aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCherry Mui <cherryyz@google.com>2025-12-15 13:45:28 -0500
committerDavid Chase <drchase@google.com>2025-12-15 13:08:19 -0800
commit9ba0948172cbb05308fb2a9db823a720f8ffb9ad (patch)
tree04e5b2319c6c57870ae9050ad32a74cf2c8f160b
parentb7944a5f80b5aa7ad43730064cf4ebc8c473df47 (diff)
downloadgo-9ba0948172cbb05308fb2a9db823a720f8ffb9ad.tar.xz
cmd/link: don't create __x86.get_pc_thunk symbol if it already exists
On 386, in some build modes we need to create the __x86.get_pc_thunk symbols, to support PC-relative addressing. In some situation the thunk symbols may already exist, e.g. loaded from a C object in internal linking mode. In this case, we should use the exiting symbol instead of making a new one. The current code updates the symbol content in place but also adds a duplicated entry to Textp, which breaks the address sorting order. Fixes #76815. Change-Id: Iab11106ce592dc5219b7a0e07cfafcd270661a2f Reviewed-on: https://go-review.googlesource.com/c/go/+/730161 Reviewed-by: David Chase <drchase@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
-rw-r--r--src/cmd/link/internal/x86/asm.go3
1 files changed, 3 insertions, 0 deletions
diff --git a/src/cmd/link/internal/x86/asm.go b/src/cmd/link/internal/x86/asm.go
index 036514819a..2c38473702 100644
--- a/src/cmd/link/internal/x86/asm.go
+++ b/src/cmd/link/internal/x86/asm.go
@@ -72,6 +72,9 @@ func gentext(ctxt *ld.Link, ldr *loader.Loader) {
{"di", 7},
} {
thunkfunc := ldr.CreateSymForUpdate("__x86.get_pc_thunk."+r.name, 0)
+ if t := thunkfunc.Type(); t != 0 && t != sym.SXREF && t != sym.SDYNIMPORT && t != sym.SUNDEFEXT {
+ continue // symbol already exists, probably loaded from a C object
+ }
thunkfunc.SetType(sym.STEXT)
ldr.SetAttrLocal(thunkfunc.Sym(), true)
o := func(op ...uint8) {