mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
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 <drchase@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
parent
76d088eb74
commit
6dceff8bad
2 changed files with 16 additions and 2 deletions
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue