From: Josh Bleecher Snyder Date: Fri, 24 Sep 2021 20:50:22 +0000 (-0700) Subject: cmd/link: move all FUNCDATA refs into go.func.* X-Git-Tag: go1.18beta1~1057 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=cfd74f7727f6ad5a81d574c28cbee52cc13fdc52;p=gostls13.git cmd/link: move all FUNCDATA refs into go.func.* This change moves all symbols referred to by FUNCDATA into go.func.* and go.funcrel.*. Surprisingly (because it inhibits some content-addressability), it shrinks binaries by a little bit, about 0.1%. This paves the way for a subsequent change to change FUNCDATA relocations to offsets. Change-Id: I70e487205073699f442192b0791cc92da5663057 Reviewed-on: https://go-review.googlesource.com/c/go/+/352189 Trust: Josh Bleecher Snyder Run-TryBot: Josh Bleecher Snyder TryBot-Result: Go Bot Reviewed-by: Cherry Mui --- diff --git a/src/cmd/internal/obj/objfile.go b/src/cmd/internal/obj/objfile.go index 0f3356f85e..687cddc70c 100644 --- a/src/cmd/internal/obj/objfile.go +++ b/src/cmd/internal/obj/objfile.go @@ -408,7 +408,21 @@ func contentHashSection(s *LSym) byte { name := s.Name if s.IsPcdata() { return 'P' - } else if strings.HasPrefix(name, "type.") { + } + if strings.HasPrefix(name, "runtime.gcbits.") { + return 'G' // gcbits + } + if strings.HasPrefix(name, "gcargs.") || + strings.HasPrefix(name, "gclocals.") || + strings.HasPrefix(name, "gclocals·") || + strings.HasSuffix(name, ".opendefer") || + strings.HasSuffix(name, ".arginfo0") || + strings.HasSuffix(name, ".arginfo1") || + strings.HasSuffix(name, ".args_stackmap") || + strings.HasSuffix(name, ".stkobj") { + return 'F' // go.func.* or go.funcrel.* + } + if strings.HasPrefix(name, "type.") { return 'T' } return 0 diff --git a/src/cmd/link/internal/ld/symtab.go b/src/cmd/link/internal/ld/symtab.go index 5e7eeeb94f..7fddc59bb5 100644 --- a/src/cmd/link/internal/ld/symtab.go +++ b/src/cmd/link/internal/ld/symtab.go @@ -507,13 +507,9 @@ func (ctxt *Link) symtab(pcln *pclntab) []sym.SymKind { symgcbits = groupSym("runtime.gcbits.*", sym.SGCBITS) ) - var symgofuncrel loader.Sym - if !ctxt.DynlinkingGo() { - if ctxt.UseRelro() { - symgofuncrel = groupSym("go.funcrel.*", sym.SGOFUNCRELRO) - } else { - symgofuncrel = symgofunc - } + symgofuncrel := symgofunc + if ctxt.UseRelro() { + symgofuncrel = groupSym("go.funcrel.*", sym.SGOFUNCRELRO) } symt := ldr.CreateSymForUpdate("runtime.symtab", 0) @@ -555,7 +551,7 @@ func (ctxt *Link) symtab(pcln *pclntab) []sym.SymKind { } if ctxt.UseRelro() { symGroupType[s] = sym.SGOFUNCRELRO - if symgofuncrel != 0 { + if !ctxt.DynlinkingGo() { ldr.SetCarrierSym(s, symgofuncrel) } } else { @@ -569,10 +565,17 @@ func (ctxt *Link) symtab(pcln *pclntab) []sym.SymKind { ldr.SymType(s) == sym.SGOFUNC && s != symgofunc, // inltree, see pcln.go strings.HasSuffix(name, ".opendefer"), strings.HasSuffix(name, ".arginfo0"), - strings.HasSuffix(name, ".arginfo1"): - symGroupType[s] = sym.SGOFUNC + strings.HasSuffix(name, ".arginfo1"), + strings.HasSuffix(name, ".args_stackmap"), + strings.HasSuffix(name, ".stkobj"): ldr.SetAttrNotInSymbolTable(s, true) - ldr.SetCarrierSym(s, symgofunc) + if ctxt.UseRelro() && strings.HasSuffix(name, ".stkobj") { + symGroupType[s] = sym.SGOFUNCRELRO + ldr.SetCarrierSym(s, symgofuncrel) + } else { + 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)