]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/link: fix -s with external linking
authorRuss Cox <rsc@golang.org>
Mon, 29 Jun 2015 17:12:10 +0000 (13:12 -0400)
committerRuss Cox <rsc@golang.org>
Mon, 29 Jun 2015 19:49:38 +0000 (19:49 +0000)
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 <crawshaw@golang.org>
src/cmd/dist/test.go
src/cmd/link/internal/ld/elf.go
src/cmd/link/internal/ld/lib.go

index 802631dbf98372d8a6b3c266993400c1d0cfcdb7..ff35c6cd4066fad9b2263d4760c71f12076b29ce 100644 (file)
@@ -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",
index 785b1cbd2ddfb1052c917e24c9a5978322517e2d..7864d1a68f8fd3db63b9c082b6f151cf7422aae3 100644 (file)
@@ -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 {
index ac28439d96891cda7a1302aa378e8511e392ef17..866eb67961eabd16143528cc967c4c66f6726ea4 100644 (file)
@@ -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-")