LocationLists int `help:"print information about DWARF location list creation"`
Nil int `help:"print information about nil checks"`
NoOpenDefer int `help:"disable open-coded defers"`
+ NoRefName int `help:"do not include referenced symbol names in object file"`
PCTab string `help:"print named pc-value table\nOne of: pctospadj, pctofile, pctoline, pctoinline, pctopcdata"`
Panic int `help:"show all compiler panics"`
Slice int `help:"print information about slice compilation"`
Ctxt.Flag_optimize = Flag.N == 0
Ctxt.Debugasm = int(Flag.S)
Ctxt.Flag_maymorestack = Debug.MayMoreStack
+ Ctxt.Flag_noRefName = Debug.NoRefName != 0
if flag.NArg() < 1 {
usage()
PkgIdxHashed // Hashed (content-addressable) symbols
PkgIdxBuiltin // Predefined runtime symbols (ex: runtime.newobject)
PkgIdxSelf // Symbols defined in the current package
+ PkgIdxSpecial = PkgIdxSelf // Indices above it has special meanings
PkgIdxInvalid = 0
// The index of other referenced packages starts from 1.
)
Flag_linkshared bool
Flag_optimize bool
Flag_locationlists bool
+ Flag_noRefName bool // do not include referenced symbol names in object file
Retpoline bool // emit use of retpoline stubs for indirect jmp/call
Flag_maymorestack string // If not "", call this function before stack checks
Bso *bufio.Writer
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)
})
// 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 {
t.Errorf("unexpected error message: want: %q, got: %s", want, out)
}
}
+
+func TestNoRefName(t *testing.T) {
+ // Test that the norefname flag works.
+ testenv.MustHaveGoBuild(t)
+
+ tmpdir := t.TempDir()
+
+ src := filepath.Join(tmpdir, "x.go")
+ err := ioutil.WriteFile(src, []byte("package main; import \"fmt\"; func main() { fmt.Println(123) }\n"), 0666)
+ if err != nil {
+ t.Fatalf("failed to write source file: %v\n", err)
+ }
+ exe := filepath.Join(tmpdir, "x.exe")
+
+ // Build the fmt package with norefname. Not rebuilding all packages to save time.
+ // Also testing that norefname and non-norefname packages can link together.
+ cmd := exec.Command(testenv.GoToolPath(t), "build", "-gcflags=fmt=-d=norefname", "-o", exe, src)
+ out, err := cmd.CombinedOutput()
+ if err != nil {
+ t.Fatalf("build failed: %v, output:\n%s", err, out)
+ }
+}