aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/internal/obj/objfile.go
diff options
context:
space:
mode:
authorCherry Mui <cherryyz@google.com>2022-05-05 17:22:17 -0400
committerCherry Mui <cherryyz@google.com>2022-05-11 21:01:09 +0000
commitb89a1948893d2c6c04497030eb78addd6fd7daf3 (patch)
treef13fed1520bbc65a47aeb8265c43e3f6c76540b5 /src/cmd/internal/obj/objfile.go
parentc1105cfd435c84f3454822fdccfe0c8ab7d8f621 (diff)
downloadgo-b89a1948893d2c6c04497030eb78addd6fd7daf3.tar.xz
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>
Diffstat (limited to 'src/cmd/internal/obj/objfile.go')
-rw-r--r--src/cmd/internal/obj/objfile.go17
1 files changed, 12 insertions, 5 deletions
diff --git a/src/cmd/internal/obj/objfile.go b/src/cmd/internal/obj/objfile.go
index 2caff62702..d31afda703 100644
--- a/src/cmd/internal/obj/objfile.go
+++ b/src/cmd/internal/obj/objfile.go
@@ -269,17 +269,21 @@ func (w *writer) StringTable() {
w.AddString(pkg)
}
w.ctxt.traverseSyms(traverseAll, func(s *LSym) {
+ // 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)
}
- // Don't put names of builtins into the string table (to save
- // space).
- if s.PkgIdx == goobj.PkgIdxBuiltin {
- return
- }
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 {