aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/link
diff options
context:
space:
mode:
authorJosh Bleecher Snyder <josharian@gmail.com>2021-09-27 14:27:20 -0700
committerJosh Bleecher Snyder <josharian@gmail.com>2021-10-05 19:16:08 +0000
commit3100dc1a7fe3f3302cf2419298b0585bc8e83890 (patch)
tree5f8955e9fcab05ec6a6e00a20e483950088e1a83 /src/cmd/link
parentae83301ab21fd3a0664d1277ee7b313cbf6590d9 (diff)
downloadgo-3100dc1a7fe3f3302cf2419298b0585bc8e83890.tar.gz
go-3100dc1a7fe3f3302cf2419298b0585bc8e83890.zip
cmd/link,runtime: remove relocations from stkobjs
Use an offset from go.func.* instead. This removes the last relocation from funcdata symbols, which lets us simplify that code. size before after Δ % addr2line 3683218 3680706 -2512 -0.068% api 4951074 4944850 -6224 -0.126% asm 4744258 4757586 +13328 +0.281% buildid 2419986 2418546 -1440 -0.060% cgo 4218306 4197346 -20960 -0.497% compile 22132066 22076882 -55184 -0.249% cover 4432834 4411362 -21472 -0.484% dist 3111202 3091346 -19856 -0.638% doc 3583602 3563234 -20368 -0.568% fix 3023922 3020658 -3264 -0.108% link 6188034 6164642 -23392 -0.378% nm 3665826 3646818 -19008 -0.519% objdump 4015234 4012450 -2784 -0.069% pack 2155010 2153554 -1456 -0.068% pprof 13044178 13011522 -32656 -0.250% test2json 2402146 2383906 -18240 -0.759% trace 9765410 9736514 -28896 -0.296% vet 6681250 6655058 -26192 -0.392% total 104217556 103926980 -290576 -0.279% relocs before after Δ % addr2line 25563 25066 -497 -1.944% api 18409 17176 -1233 -6.698% asm 18903 18271 -632 -3.343% buildid 9513 9233 -280 -2.943% cgo 17103 16222 -881 -5.151% compile 64825 60421 -4404 -6.794% cover 19464 18479 -985 -5.061% dist 10798 10135 -663 -6.140% doc 13503 12735 -768 -5.688% fix 11465 10820 -645 -5.626% link 23214 21849 -1365 -5.880% nm 25480 24987 -493 -1.935% objdump 26610 26057 -553 -2.078% pack 7951 7665 -286 -3.597% pprof 63964 60761 -3203 -5.008% test2json 8735 8389 -346 -3.961% trace 39639 37180 -2459 -6.203% vet 25970 24044 -1926 -7.416% total 431108 409489 -21619 -5.015% Change-Id: I43c26196a008da6d1cb3a782eea2f428778bd569 Reviewed-on: https://go-review.googlesource.com/c/go/+/353138 Trust: Josh Bleecher Snyder <josharian@gmail.com> Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Cherry Mui <cherryyz@google.com>
Diffstat (limited to 'src/cmd/link')
-rw-r--r--src/cmd/link/internal/ld/data.go5
-rw-r--r--src/cmd/link/internal/ld/pcln.go22
-rw-r--r--src/cmd/link/internal/ld/symtab.go15
3 files changed, 12 insertions, 30 deletions
diff --git a/src/cmd/link/internal/ld/data.go b/src/cmd/link/internal/ld/data.go
index 8de0e0df1a..4f0ce23ce7 100644
--- a/src/cmd/link/internal/ld/data.go
+++ b/src/cmd/link/internal/ld/data.go
@@ -1367,6 +1367,11 @@ func (state *dodataState) makeRelroForSharedLib(target *Link) {
// the relro data.
isRelro = true
}
+ case sym.SGOFUNC:
+ // The only SGOFUNC symbols that contain relocations are .stkobj,
+ // and their relocations are of type objabi.R_ADDROFF,
+ // which always get resolved during linking.
+ isRelro = false
}
if isRelro {
state.setSymType(s, symnrelro)
diff --git a/src/cmd/link/internal/ld/pcln.go b/src/cmd/link/internal/ld/pcln.go
index b041174cfe..b5a66b8517 100644
--- a/src/cmd/link/internal/ld/pcln.go
+++ b/src/cmd/link/internal/ld/pcln.go
@@ -711,7 +711,7 @@ func writeFuncs(ctxt *Link, sb *loader.SymbolBuilder, funcs []loader.Sym, inlSym
ldr := ctxt.loader
deferReturnSym := ldr.Lookup("runtime.deferreturn", abiInternalVer)
gofunc := ldr.Lookup("go.func.*", 0)
- gofuncrel := ldr.Lookup("go.funcrel.*", 0)
+ gofuncBase := ldr.SymValue(gofunc)
textStart := ldr.SymValue(ldr.Lookup("runtime.text", 0))
funcdata := []loader.Sym{}
var pcsp, pcfile, pcline, pcinline loader.Sym
@@ -813,24 +813,10 @@ func writeFuncs(ctxt *Link, sb *loader.SymbolBuilder, funcs []loader.Sym, inlSym
continue
}
- outer := ldr.OuterSym(fdsym)
- if outer == 0 {
- panic(fmt.Sprintf("no carrier sym for symbol %s (funcdata %s#%d)", ldr.SymName(fdsym), ldr.SymName(s), j))
+ if outer := ldr.OuterSym(fdsym); outer != gofunc {
+ panic(fmt.Sprintf("bad carrier sym for symbol %s (funcdata %s#%d), want go.func.* got %s", ldr.SymName(fdsym), ldr.SymName(s), j, ldr.SymName(outer)))
}
- rel := uint32(ldr.SymValue(fdsym) - ldr.SymValue(outer))
- // Record gofunc vs gofuncrel in bottom bit. See runtime/symtab.go:funcdata.
- // TODO: The only symbols that in gofuncrel are .stkobj symbols.
- // Remove those relocations, and simplify this.
- rel <<= 1
- switch outer {
- case gofunc:
- case gofuncrel:
- rel |= 1
- default:
- panic(fmt.Sprintf("expected symbol %s (funcdata %s#%d) to be placed in go.func.* or go.funcrel.*, got %s (%d)",
- ldr.SymName(fdsym), ldr.SymName(s), j, ldr.SymName(outer), outer))
- }
- sb.SetUint32(ctxt.Arch, int64(dataoff), rel)
+ sb.SetUint32(ctxt.Arch, int64(dataoff), uint32(ldr.SymValue(fdsym)-gofuncBase))
}
}
}
diff --git a/src/cmd/link/internal/ld/symtab.go b/src/cmd/link/internal/ld/symtab.go
index c582e4908d..878d30b5f1 100644
--- a/src/cmd/link/internal/ld/symtab.go
+++ b/src/cmd/link/internal/ld/symtab.go
@@ -569,13 +569,8 @@ func (ctxt *Link) symtab(pcln *pclntab) []sym.SymKind {
strings.HasSuffix(name, ".args_stackmap"),
strings.HasSuffix(name, ".stkobj"):
ldr.SetAttrNotInSymbolTable(s, true)
- if ctxt.UseRelro() && strings.HasSuffix(name, ".stkobj") {
- symGroupType[s] = sym.SGOFUNCRELRO
- ldr.SetCarrierSym(s, symgofuncrel)
- } else {
- symGroupType[s] = sym.SGOFUNC
- ldr.SetCarrierSym(s, symgofunc)
- }
+ symGroupType[s] = sym.SGOFUNC
+ ldr.SetCarrierSym(s, symgofunc)
if ctxt.Debugvlog != 0 {
align := ldr.SymAlign(s)
liveness += (ldr.SymSize(s) + int64(align) - 1) &^ (int64(align) - 1)
@@ -676,12 +671,8 @@ func (ctxt *Link) symtab(pcln *pclntab) []sym.SymKind {
moduledata.AddAddr(ctxt.Arch, ldr.Lookup("runtime.gcbss", 0))
moduledata.AddAddr(ctxt.Arch, ldr.Lookup("runtime.types", 0))
moduledata.AddAddr(ctxt.Arch, ldr.Lookup("runtime.etypes", 0))
+ moduledata.AddAddr(ctxt.Arch, ldr.Lookup("runtime.rodata", 0))
moduledata.AddAddr(ctxt.Arch, ldr.Lookup("go.func.*", 0))
- if gofuncrel := ldr.Lookup("go.funcrel.*", 0); gofuncrel != 0 {
- moduledata.AddAddr(ctxt.Arch, gofuncrel)
- } else {
- moduledata.AddUint(ctxt.Arch, 0)
- }
if ctxt.IsAIX() && ctxt.IsExternal() {
// Add R_XCOFFREF relocation to prevent ld's garbage collection of