Commit 34846aef authored by Russ Cox's avatar Russ Cox

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/11695Reviewed-by: default avatarDavid Crawshaw <crawshaw@golang.org>
parent 27edd720
...@@ -613,22 +613,23 @@ func (t *tester) cgoTest() error { ...@@ -613,22 +613,23 @@ func (t *tester) cgoTest() error {
pair := t.gohostos + "-" + t.goarch pair := t.gohostos + "-" + t.goarch
switch pair { 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. // 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 := t.dirCmd("misc/cgo/test", "go", "test", "-ldflags", "-linkmode=external")
cmd.Env = env cmd.Env = env
if err := cmd.Run(); err != nil { if err := cmd.Run(); err != nil {
return err return err
} }
case "darwin-386", "darwin-amd64", cmd = t.dirCmd("misc/cgo/test", "go", "test", "-ldflags", "-linkmode=external -s")
"windows-386", "windows-amd64":
if t.extLink() {
cmd := t.dirCmd("misc/cgo/test", "go", "test", "-ldflags", "-linkmode=external")
cmd.Env = env cmd.Env = env
if err := cmd.Run(); err != nil { if err := cmd.Run(); err != nil {
return err return err
} }
}
case "android-arm", case "android-arm",
"dragonfly-386", "dragonfly-amd64", "dragonfly-386", "dragonfly-amd64",
"freebsd-386", "freebsd-amd64", "freebsd-arm", "freebsd-386", "freebsd-amd64", "freebsd-arm",
......
...@@ -1693,8 +1693,6 @@ func doelf() { ...@@ -1693,8 +1693,6 @@ func doelf() {
Addstring(shstrtab, ".gopclntab") Addstring(shstrtab, ".gopclntab")
if Linkmode == LinkExternal { if Linkmode == LinkExternal {
debug_s = Debug['s']
Debug['s'] = 0
Debug['d'] = 1 Debug['d'] = 1
switch Thearch.Thechar { switch Thearch.Thechar {
......
...@@ -818,6 +818,12 @@ func hostlinksetup() { ...@@ -818,6 +818,12 @@ func hostlinksetup() {
return 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 // create temporary directory and arrange cleanup
if tmpdir == "" { if tmpdir == "" {
dir, err := ioutil.TempDir("", "go-link-") dir, err := ioutil.TempDir("", "go-link-")
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment