mirror of
https://github.com/golang/go
synced 2024-11-17 01:24:50 -07:00
cmd/link: don't pass -Wl,--dynamic-linker if -static
As with -rdynamic, clang will pass -Wl,--dynamic-linker to the linker even when linking statically. When using lld this will produce a statically linked executable with a dynamic interpreter, which will crash at runtime. This CL changes the linker to drop -Wl,--dynamic-linker when using -static, as it already does with -rdynamic. This has become more important since CL 310349, which changes the linker to always pass a -Wl,--dynamic-linker option if the Go linker is invoked with a -I option. Change-Id: I68ed431064f02c70018bc0547585e5b0ebd20a41 Reviewed-on: https://go-review.googlesource.com/c/go/+/314412 Trust: Ian Lance Taylor <iant@golang.org> Reviewed-by: Cherry Zhang <cherryyz@google.com>
This commit is contained in:
parent
12af403624
commit
24ea547a21
@ -1520,12 +1520,13 @@ func (ctxt *Link) hostlink() {
|
|||||||
// even when linking with -static, causing a linker
|
// even when linking with -static, causing a linker
|
||||||
// error when using GNU ld. So take out -rdynamic if
|
// error when using GNU ld. So take out -rdynamic if
|
||||||
// we added it. We do it in this order, rather than
|
// we added it. We do it in this order, rather than
|
||||||
// only adding -rdynamic later, so that -*extldflags
|
// only adding -rdynamic later, so that -extldflags
|
||||||
// can override -rdynamic without using -static.
|
// can override -rdynamic without using -static.
|
||||||
|
// Similarly for -Wl,--dynamic-linker.
|
||||||
checkStatic := func(arg string) {
|
checkStatic := func(arg string) {
|
||||||
if ctxt.IsELF && arg == "-static" {
|
if ctxt.IsELF && arg == "-static" {
|
||||||
for i := range argv {
|
for i := range argv {
|
||||||
if argv[i] == "-rdynamic" {
|
if argv[i] == "-rdynamic" || strings.HasPrefix(argv[i], "-Wl,--dynamic-linker,") {
|
||||||
argv[i] = "-static"
|
argv[i] = "-static"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user