From: Russ Cox Date: Mon, 29 Jun 2015 17:12:10 +0000 (-0400) Subject: cmd/link: fix -s with external linking X-Git-Tag: go1.5beta1~50 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=34846aef78e2e27da8eaadff2d9ea78cd99d491d;p=gostls13.git 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 --- diff --git a/src/cmd/dist/test.go b/src/cmd/dist/test.go index 802631dbf9..ff35c6cd40 100644 --- a/src/cmd/dist/test.go +++ b/src/cmd/dist/test.go @@ -613,21 +613,22 @@ func (t *tester) cgoTest() error { pair := t.gohostos + "-" + t.goarch switch pair { - case "openbsd-386", "openbsd-amd64": + case "darwin-386", "darwin-amd64", + "openbsd-386", "openbsd-amd64", + "windows-386", "windows-amd64": // test linkmode=external, but __thread not supported, so skip testtls. + if !t.extLink() { + break + } cmd := t.dirCmd("misc/cgo/test", "go", "test", "-ldflags", "-linkmode=external") cmd.Env = env if err := cmd.Run(); err != nil { return err } - case "darwin-386", "darwin-amd64", - "windows-386", "windows-amd64": - if t.extLink() { - cmd := t.dirCmd("misc/cgo/test", "go", "test", "-ldflags", "-linkmode=external") - cmd.Env = env - if err := cmd.Run(); err != nil { - return err - } + cmd = t.dirCmd("misc/cgo/test", "go", "test", "-ldflags", "-linkmode=external -s") + cmd.Env = env + if err := cmd.Run(); err != nil { + return err } case "android-arm", "dragonfly-386", "dragonfly-amd64", diff --git a/src/cmd/link/internal/ld/elf.go b/src/cmd/link/internal/ld/elf.go index 785b1cbd2d..7864d1a68f 100644 --- a/src/cmd/link/internal/ld/elf.go +++ b/src/cmd/link/internal/ld/elf.go @@ -1693,8 +1693,6 @@ func doelf() { Addstring(shstrtab, ".gopclntab") if Linkmode == LinkExternal { - debug_s = Debug['s'] - Debug['s'] = 0 Debug['d'] = 1 switch Thearch.Thechar { diff --git a/src/cmd/link/internal/ld/lib.go b/src/cmd/link/internal/ld/lib.go index ac28439d96..866eb67961 100644 --- a/src/cmd/link/internal/ld/lib.go +++ b/src/cmd/link/internal/ld/lib.go @@ -818,6 +818,12 @@ func hostlinksetup() { return } + // For external link, record that we need to tell the external linker -s, + // and turn off -s internally: the external linker needs the symbol + // information for its final link. + debug_s = Debug['s'] + Debug['s'] = 0 + // create temporary directory and arrange cleanup if tmpdir == "" { dir, err := ioutil.TempDir("", "go-link-")