Skip to content

Commit 34846ae

Browse files
committed
cmd/link: fix -s with external linking
This code used to only be run for ELF, with the predictable result that using -s with external linking broke on Windows and OS X. Moving it here should fix Windows and does fix OS X. CL 10835 also claims to fix the crash on Windows. I don't know whether it does so correctly, but regardless, this CL should make that one a no-op. Fixes #10254. Change-Id: I2e7b45ab0c28568ddbb1b50581dcc157ae0e7ffe Reviewed-on: https://go-review.googlesource.com/11695 Reviewed-by: David Crawshaw <[email protected]>
1 parent 27edd72 commit 34846ae

File tree

3 files changed

+16
-11
lines changed

3 files changed

+16
-11
lines changed

src/cmd/dist/test.go

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -613,21 +613,22 @@ func (t *tester) cgoTest() error {
613613

614614
pair := t.gohostos + "-" + t.goarch
615615
switch pair {
616-
case "openbsd-386", "openbsd-amd64":
616+
case "darwin-386", "darwin-amd64",
617+
"openbsd-386", "openbsd-amd64",
618+
"windows-386", "windows-amd64":
617619
// test linkmode=external, but __thread not supported, so skip testtls.
620+
if !t.extLink() {
621+
break
622+
}
618623
cmd := t.dirCmd("misc/cgo/test", "go", "test", "-ldflags", "-linkmode=external")
619624
cmd.Env = env
620625
if err := cmd.Run(); err != nil {
621626
return err
622627
}
623-
case "darwin-386", "darwin-amd64",
624-
"windows-386", "windows-amd64":
625-
if t.extLink() {
626-
cmd := t.dirCmd("misc/cgo/test", "go", "test", "-ldflags", "-linkmode=external")
627-
cmd.Env = env
628-
if err := cmd.Run(); err != nil {
629-
return err
630-
}
628+
cmd = t.dirCmd("misc/cgo/test", "go", "test", "-ldflags", "-linkmode=external -s")
629+
cmd.Env = env
630+
if err := cmd.Run(); err != nil {
631+
return err
631632
}
632633
case "android-arm",
633634
"dragonfly-386", "dragonfly-amd64",

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1693,8 +1693,6 @@ func doelf() {
16931693
Addstring(shstrtab, ".gopclntab")
16941694

16951695
if Linkmode == LinkExternal {
1696-
debug_s = Debug['s']
1697-
Debug['s'] = 0
16981696
Debug['d'] = 1
16991697

17001698
switch Thearch.Thechar {

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -818,6 +818,12 @@ func hostlinksetup() {
818818
return
819819
}
820820

821+
// For external link, record that we need to tell the external linker -s,
822+
// and turn off -s internally: the external linker needs the symbol
823+
// information for its final link.
824+
debug_s = Debug['s']
825+
Debug['s'] = 0
826+
821827
// create temporary directory and arrange cleanup
822828
if tmpdir == "" {
823829
dir, err := ioutil.TempDir("", "go-link-")

0 commit comments

Comments
 (0)