Skip to content

Commit c2d4f85

Browse files
cherrymuijoedian
authored andcommitted
[release-branch.go1.22] cmd/link: handle dynamic import variables on Darwin in plugin mode
CL 501855 added support for cgo_dynamic_import variables on Darwin. But it didn't support the plugin build mode on amd64, where the assembler turns a direct load (R_PCREL) to a load via GOT (R_GOTPCREL). This CL adds the support. We just need to handle external linking mode, as this can only occur in plugin or shared build mode, which requires external linking. Fixes #68122. Updates #67976. Updates #50891. Change-Id: I0f56265d50bfcb36047fa5538ad7a5ec77e7ef96 Reviewed-on: https://go-review.googlesource.com/c/go/+/592499 Reviewed-by: David Chase <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> (cherry picked from commit 44f1870) Reviewed-on: https://go-review.googlesource.com/c/go/+/595175 Reviewed-by: Joedian Reid <[email protected]> Reviewed-by: Than McIntosh <[email protected]>
1 parent 3222951 commit c2d4f85

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

src/cmd/cgo/internal/testplugin/plugin_test.go

+8
Original file line numberDiff line numberDiff line change
@@ -414,3 +414,11 @@ func TestTextSectionSplit(t *testing.T) {
414414
t.Errorf("runtime.text.1 not found, text section not split?")
415415
}
416416
}
417+
418+
func TestIssue67976(t *testing.T) {
419+
// Issue 67976: build failure with loading a dynimport variable (the runtime/pprof
420+
// package does this on darwin) in a plugin on darwin/amd64.
421+
// The test program uses runtime/pprof in a plugin.
422+
globalSkip(t)
423+
goCmd(t, "build", "-buildmode=plugin", "-o", "issue67976.so", "./issue67976/plugin.go")
424+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright 2024 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
package main
6+
7+
import (
8+
"io"
9+
"runtime/pprof"
10+
)
11+
12+
func main() {}
13+
14+
func Start() {
15+
pprof.StartCPUProfile(io.Discard)
16+
}

src/cmd/link/internal/amd64/asm.go

+7
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,13 @@ func adddynrel(target *ld.Target, ldr *loader.Loader, syms *ld.ArchSyms, s loade
398398
// (e.g. go version).
399399
return true
400400
}
401+
case objabi.R_GOTPCREL:
402+
if target.IsExternal() {
403+
// External linker will do this relocation.
404+
return true
405+
}
406+
// We only need to handle external linking mode, as R_GOTPCREL can
407+
// only occur in plugin or shared build modes.
401408
}
402409

403410
return false

0 commit comments

Comments
 (0)