src/cmd/cgo/internal/testplugin/plugin_test.go | 8 ++++++++ src/cmd/cgo/internal/testplugin/testdata/issue67976/plugin.go | 16 ++++++++++++++++ src/cmd/link/internal/amd64/asm.go | 7 +++++++ diff --git a/src/cmd/cgo/internal/testplugin/plugin_test.go b/src/cmd/cgo/internal/testplugin/plugin_test.go index 4900ada18201567de89e86615f08ce2c2c816618..85dfd31123b5dedd27aa83544caf692bc3805395 100644 --- a/src/cmd/cgo/internal/testplugin/plugin_test.go +++ b/src/cmd/cgo/internal/testplugin/plugin_test.go @@ -414,3 +414,11 @@ if !strings.Contains(syms, "runtime.text.1") { t.Errorf("runtime.text.1 not found, text section not split?") } } + +func TestIssue67976(t *testing.T) { + // Issue 67976: build failure with loading a dynimport variable (the runtime/pprof + // package does this on darwin) in a plugin on darwin/amd64. + // The test program uses runtime/pprof in a plugin. + globalSkip(t) + goCmd(t, "build", "-buildmode=plugin", "-o", "issue67976.so", "./issue67976/plugin.go") +} diff --git a/src/cmd/cgo/internal/testplugin/testdata/issue67976/plugin.go b/src/cmd/cgo/internal/testplugin/testdata/issue67976/plugin.go new file mode 100644 index 0000000000000000000000000000000000000000..502ecc5c4750f4920759768a408eb197f3afc022 --- /dev/null +++ b/src/cmd/cgo/internal/testplugin/testdata/issue67976/plugin.go @@ -0,0 +1,16 @@ +// Copyright 2024 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +import ( + "io" + "runtime/pprof" +) + +func main() {} + +func Start() { + pprof.StartCPUProfile(io.Discard) +} diff --git a/src/cmd/link/internal/amd64/asm.go b/src/cmd/link/internal/amd64/asm.go index f86d22493227acbf529bfb6eefb6709a0be3ae7f..9da0541f5263c26d12740cb279074fa859740f83 100644 --- a/src/cmd/link/internal/amd64/asm.go +++ b/src/cmd/link/internal/amd64/asm.go @@ -398,6 +398,13 @@ // to the relocation target. So it can be examined statically // (e.g. go version). return true } + case objabi.R_GOTPCREL: + if target.IsExternal() { + // External linker will do this relocation. + return true + } + // We only need to handle external linking mode, as R_GOTPCREL can + // only occur in plugin or shared build modes. } return false