Skip to content

Commit 6dceff8

Browse files
committed
cmd/link: handle -w flag in external linking mode
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 <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]>
1 parent 76d088e commit 6dceff8

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

src/cmd/link/dwarf_test.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -370,14 +370,26 @@ func TestFlagW(t *testing.T) {
370370
t.Fatal(err)
371371
}
372372

373-
tests := []struct {
373+
type testCase struct {
374374
flag string
375375
wantDWARF bool
376-
}{
376+
}
377+
tests := []testCase{
377378
{"-w", false}, // -w flag disables DWARF
378379
{"-s", false}, // -s implies -w
379380
{"-s -w=0", true}, // -w=0 negates the implied -w
380381
}
382+
if testenv.HasCGO() {
383+
tests = append(tests,
384+
testCase{"-w -linkmode=external", false},
385+
testCase{"-s -linkmode=external", false},
386+
// Some external linkers don't have a way to preserve DWARF
387+
// without emitting the symbol table. Skip this case for now.
388+
// I suppose we can post- process, e.g. with objcopy.
389+
//testCase{"-s -w=0 -linkmode=external", true},
390+
)
391+
}
392+
381393
for _, test := range tests {
382394
name := strings.ReplaceAll(test.flag, " ", "_")
383395
t.Run(name, func(t *testing.T) {

src/cmd/link/internal/ld/lib.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1451,6 +1451,8 @@ func (ctxt *Link) hostlink() {
14511451
} else {
14521452
argv = append(argv, "-s")
14531453
}
1454+
} else if *FlagW {
1455+
argv = append(argv, "-Wl,-S") // suppress debugging symbols
14541456
}
14551457

14561458
// On darwin, whether to combine DWARF into executable.

0 commit comments

Comments
 (0)