Skip to content

Commit

Permalink
cmd/link: move all FUNCDATA refs into go.func.*
Browse files Browse the repository at this point in the history
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 <[email protected]>
Run-TryBot: Josh Bleecher Snyder <[email protected]>
TryBot-Result: Go Bot <[email protected]>
Reviewed-by: Cherry Mui <[email protected]>
  • Loading branch information
josharian committed Oct 5, 2021
1 parent 7983830 commit cfd74f7
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 12 deletions.
16 changes: 15 additions & 1 deletion src/cmd/internal/obj/objfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 14 additions & 11 deletions src/cmd/link/internal/ld/symtab.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand All @@ -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)
Expand Down

0 comments on commit cfd74f7

Please sign in to comment.