aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul E. Murphy <murp@ibm.com>2024-03-12 15:00:08 -0500
committerThan McIntosh <thanm@google.com>2024-03-26 19:16:20 +0000
commit0bd1a2289d0e37ec5015ce3c05a5873c3a6da3e5 (patch)
tree991119f62399c3e4ab5ae628bfe94312ac493bba
parent140b37d659ab7c12f9be655d31690dfa5ff7b3c0 (diff)
downloadgo-0bd1a2289d0e37ec5015ce3c05a5873c3a6da3e5.tar.gz
go-0bd1a2289d0e37ec5015ce3c05a5873c3a6da3e5.zip
[release-branch.go1.21] cmd/internal/obj/ppc64: don't modify runtime.elf_* symbols
The runtime.elf_* symbols are assembly functions which are used to support the gcc/llvm -Os option when used with cgo. When compiling Go for shared code, we attempt to strip out the TOC regenation code added by the go assembler for these symbols. This causes the symbol to no longer appear as an assembly function which causes problems later on when handling other implicit symbols. Avoid adding a TOC regeneration prologue to these functions to avoid this issue. Fixes #66411 Change-Id: Icbf8e4438d177082a57bb228e39b232e7a0d7ada Reviewed-on: https://go-review.googlesource.com/c/go/+/571835 Reviewed-by: Than McIntosh <thanm@google.com> Run-TryBot: Paul Murphy <murp@ibm.com> Reviewed-by: Cherry Mui <cherryyz@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Lynn Boger <laboger@linux.vnet.ibm.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-on: https://go-review.googlesource.com/c/go/+/572876
-rw-r--r--src/cmd/go/testdata/script/test_ppc64_linker_funcs.txt4
-rw-r--r--src/cmd/internal/obj/ppc64/obj9.go19
-rw-r--r--src/cmd/link/internal/ppc64/asm.go17
3 files changed, 23 insertions, 17 deletions
diff --git a/src/cmd/go/testdata/script/test_ppc64_linker_funcs.txt b/src/cmd/go/testdata/script/test_ppc64_linker_funcs.txt
index 735b5dcc7f6..d789f89f4e6 100644
--- a/src/cmd/go/testdata/script/test_ppc64_linker_funcs.txt
+++ b/src/cmd/go/testdata/script/test_ppc64_linker_funcs.txt
@@ -14,6 +14,10 @@ go build -ldflags='-linkmode=internal'
exec ./abitest
stdout success
+go build -buildmode=pie -o abitest.pie -ldflags='-linkmode=internal'
+exec ./abitest.pie
+stdout success
+
-- go.mod --
module abitest
diff --git a/src/cmd/internal/obj/ppc64/obj9.go b/src/cmd/internal/obj/ppc64/obj9.go
index 02831b890a3..57660ce2ce1 100644
--- a/src/cmd/internal/obj/ppc64/obj9.go
+++ b/src/cmd/internal/obj/ppc64/obj9.go
@@ -36,8 +36,25 @@ import (
"cmd/internal/sys"
"internal/abi"
"log"
+ "strings"
)
+// Is this a symbol which should never have a TOC prologue generated?
+// These are special functions which should not have a TOC regeneration
+// prologue.
+func isNOTOCfunc(name string) bool {
+ switch {
+ case name == "runtime.duffzero":
+ return true
+ case name == "runtime.duffcopy":
+ return true
+ case strings.HasPrefix(name, "runtime.elf_"):
+ return true
+ default:
+ return false
+ }
+}
+
func progedit(ctxt *obj.Link, p *obj.Prog, newprog obj.ProgAlloc) {
p.From.Class = 0
p.To.Class = 0
@@ -643,7 +660,7 @@ func preprocess(ctxt *obj.Link, cursym *obj.LSym, newprog obj.ProgAlloc) {
q = p
- if NeedTOCpointer(c.ctxt) && c.cursym.Name != "runtime.duffzero" && c.cursym.Name != "runtime.duffcopy" {
+ if NeedTOCpointer(c.ctxt) && !isNOTOCfunc(c.cursym.Name) {
// When compiling Go into PIC, without PCrel support, all functions must start
// with instructions to load the TOC pointer into r2:
//
diff --git a/src/cmd/link/internal/ppc64/asm.go b/src/cmd/link/internal/ppc64/asm.go
index d537bc533c3..3def3e6919d 100644
--- a/src/cmd/link/internal/ppc64/asm.go
+++ b/src/cmd/link/internal/ppc64/asm.go
@@ -475,24 +475,9 @@ func rewriteABIFuncReloc(ctxt *ld.Link, ldr *loader.Loader, tname string, r load
r.SetAdd(int64((n - minReg) * offMul))
firstUse = !ldr.AttrReachable(ts)
if firstUse {
- ldr.SetAttrReachable(ts, true)
// This function only becomes reachable now. It has been dropped from
// the text section (it was unreachable until now), it needs included.
- //
- // Similarly, TOC regeneration should not happen for these functions,
- // remove it from this save/restore function.
- if ldr.AttrShared(ts) {
- sb := ldr.MakeSymbolUpdater(ts)
- sb.SetData(sb.Data()[8:])
- sb.SetSize(sb.Size() - 8)
- relocs := sb.Relocs()
- // Only one PCREL reloc to .TOC. should be present.
- if relocs.Count() != 1 {
- log.Fatalf("Unexpected number of relocs in %s\n", ldr.SymName(ts))
- }
- sb.ResetRelocs()
-
- }
+ ldr.SetAttrReachable(ts, true)
}
return ts, firstUse
}