aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/internal/obj/objfile_test.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_test.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_test.go')
-rw-r--r--src/cmd/internal/obj/objfile_test.go22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/cmd/internal/obj/objfile_test.go b/src/cmd/internal/obj/objfile_test.go
index f5a4016eec..91e96e435d 100644
--- a/src/cmd/internal/obj/objfile_test.go
+++ b/src/cmd/internal/obj/objfile_test.go
@@ -121,3 +121,25 @@ func TestSymbolTooLarge(t *testing.T) { // Issue 42054
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)
+ }
+}