1
0
mirror of https://github.com/golang/go synced 2024-11-11 22:50:22 -07:00

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 <crawshaw@golang.org>
This commit is contained in:
Russ Cox 2015-06-29 13:12:10 -04:00
parent 27edd7209e
commit 34846aef78
3 changed files with 16 additions and 11 deletions

19
src/cmd/dist/test.go vendored
View 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",

View 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 {

View 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-")