1
0
mirror of https://github.com/golang/go synced 2024-11-23 19:40:08 -07:00

cmd/link: remove -rdynamic if -static appears in cgo LDFLAGS

We already remove -rdynamic if -static appears in -extldflags.
Extend that to apply to CGO_LDFLAGS and #cgo LDFLAGS as well.

Updates #26197

Change-Id: Ibb62d1b20726916a12fd889acb05c1c559a5ace2
Reviewed-on: https://go-review.googlesource.com/122135
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
Ian Lance Taylor 2018-07-03 10:16:03 -07:00
parent abaf53fb8e
commit ad4e6370fe

View File

@ -1262,7 +1262,26 @@ func (ctxt *Link) hostlink() {
} }
} }
argv = append(argv, ldflag...) // clang, unlike GCC, passes -rdynamic to the linker
// even when linking with -static, causing a linker
// error when using GNU ld. So take out -rdynamic if
// we added it. We do it in this order, rather than
// only adding -rdynamic later, so that -*extldflags
// can override -rdynamic without using -static.
checkStatic := func(arg string) {
if ctxt.IsELF && arg == "-static" {
for i := range argv {
if argv[i] == "-rdynamic" {
argv[i] = "-static"
}
}
}
}
for _, p := range ldflag {
argv = append(argv, p)
checkStatic(p)
}
// When building a program with the default -buildmode=exe the // When building a program with the default -buildmode=exe the
// gc compiler generates code requires DT_TEXTREL in a // gc compiler generates code requires DT_TEXTREL in a
@ -1283,20 +1302,7 @@ func (ctxt *Link) hostlink() {
for _, p := range strings.Fields(*flagExtldflags) { for _, p := range strings.Fields(*flagExtldflags) {
argv = append(argv, p) argv = append(argv, p)
checkStatic(p)
// clang, unlike GCC, passes -rdynamic to the linker
// even when linking with -static, causing a linker
// error when using GNU ld. So take out -rdynamic if
// we added it. We do it in this order, rather than
// only adding -rdynamic later, so that -*extldflags
// can override -rdynamic without using -static.
if ctxt.IsELF && p == "-static" {
for i := range argv {
if argv[i] == "-rdynamic" {
argv[i] = "-static"
}
}
}
} }
if ctxt.HeadType == objabi.Hwindows { if ctxt.HeadType == objabi.Hwindows {
// use gcc linker script to work around gcc bug // use gcc linker script to work around gcc bug