mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
cmd/internal/obj: add a flag to not write referenced symbol names in object file
The Go object file references (some of) symbols from other packages by indices, not by names. The linker doesn't need the symbol names to do the linking. The names are included in the object file so it is self-contained and tools (objdump, nm) can read the referenced symbol names. Including the names increases object file size. Add a flag to disable it on demand (off by default). Change-Id: I143a0eb656997497c750b8eb1541341b2aee8f30 Reviewed-on: https://go-review.googlesource.com/c/go/+/404297 TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Cherry Mui <cherryyz@google.com> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
This commit is contained in:
parent
c1105cfd43
commit
b89a194889
6 changed files with 39 additions and 6 deletions
|
|
@ -269,17 +269,21 @@ func (w *writer) StringTable() {
|
|||
w.AddString(pkg)
|
||||
}
|
||||
w.ctxt.traverseSyms(traverseAll, func(s *LSym) {
|
||||
// TODO: this includes references of indexed symbols from other packages,
|
||||
// for which the linker doesn't need the name. Consider moving them to
|
||||
// a separate block (for tools only).
|
||||
if w.pkgpath != "" {
|
||||
s.Name = strings.Replace(s.Name, "\"\".", w.pkgpath+".", -1)
|
||||
}
|
||||
// Don't put names of builtins into the string table (to save
|
||||
// space).
|
||||
if s.PkgIdx == goobj.PkgIdxBuiltin {
|
||||
return
|
||||
}
|
||||
// TODO: this includes references of indexed symbols from other packages,
|
||||
// for which the linker doesn't need the name. Consider moving them to
|
||||
// a separate block (for tools only).
|
||||
if w.ctxt.Flag_noRefName && s.PkgIdx < goobj.PkgIdxSpecial {
|
||||
// Don't include them if Flag_noRefName
|
||||
return
|
||||
}
|
||||
if w.pkgpath != "" {
|
||||
s.Name = strings.Replace(s.Name, "\"\".", w.pkgpath+".", -1)
|
||||
}
|
||||
w.AddString(s.Name)
|
||||
})
|
||||
|
||||
|
|
@ -625,6 +629,9 @@ func (w *writer) refFlags() {
|
|||
// Emits names of referenced indexed symbols, used by tools (objdump, nm)
|
||||
// only.
|
||||
func (w *writer) refNames() {
|
||||
if w.ctxt.Flag_noRefName {
|
||||
return
|
||||
}
|
||||
seen := make(map[*LSym]bool)
|
||||
w.ctxt.traverseSyms(traverseRefs, func(rs *LSym) { // only traverse refs, not auxs, as tools don't need auxs
|
||||
switch rs.PkgIdx {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue