]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/link: handle -w flag in external linking mode
authorCherry Mui <cherryyz@google.com>
Tue, 16 Sep 2025 17:34:19 +0000 (13:34 -0400)
committerCherry Mui <cherryyz@google.com>
Thu, 25 Sep 2025 16:24:46 +0000 (09:24 -0700)
Currently, when the -w flag is set, it doesn't actually disable
the debug info generation with in external linking mode. (It does
make the Go object have no debug info, but C objects may still
have.) Pass "-Wl,-S" to let the external linker disable debug info
generation.

Change-Id: I0fce56b9f23a45546b69b9e6dd027c5527b1bc87
Reviewed-on: https://go-review.googlesource.com/c/go/+/705857
Reviewed-by: David Chase <drchase@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
src/cmd/link/dwarf_test.go
src/cmd/link/internal/ld/lib.go

index 5a464fccf3089cafbb6b6db44719a3a2473df5a3..4ca578498d79234c87ed3a99719a752ad03e16a4 100644 (file)
@@ -370,14 +370,26 @@ func TestFlagW(t *testing.T) {
                t.Fatal(err)
        }
 
-       tests := []struct {
+       type testCase struct {
                flag      string
                wantDWARF bool
-       }{
+       }
+       tests := []testCase{
                {"-w", false},     // -w flag disables DWARF
                {"-s", false},     // -s implies -w
                {"-s -w=0", true}, // -w=0 negates the implied -w
        }
+       if testenv.HasCGO() {
+               tests = append(tests,
+                       testCase{"-w -linkmode=external", false},
+                       testCase{"-s -linkmode=external", false},
+                       // Some external linkers don't have a way to preserve DWARF
+                       // without emitting the symbol table. Skip this case for now.
+                       // I suppose we can post- process, e.g. with objcopy.
+                       //testCase{"-s -w=0 -linkmode=external", true},
+               )
+       }
+
        for _, test := range tests {
                name := strings.ReplaceAll(test.flag, " ", "_")
                t.Run(name, func(t *testing.T) {
index 1a1bc186755f4fe4123eec21258d2fb296940bf8..623acc1ad4899799d41218e8a7fa556704d6441d 100644 (file)
@@ -1451,6 +1451,8 @@ func (ctxt *Link) hostlink() {
                } else {
                        argv = append(argv, "-s")
                }
+       } else if *FlagW {
+               argv = append(argv, "-Wl,-S") // suppress debugging symbols
        }
 
        // On darwin, whether to combine DWARF into executable.