Skip to content

Commit e068e00

Browse files
committed
cmd/link: specify -Wl,-z params as documented
Both GNU and LLVM linkers de facto accept `-zPARAM`, and Go sometimes does it. Inconsistently: there are more uses of `-z PARAM` than `-zPARAM`: $ git grep -h -- '-Wl,-z' master | cut -b-76 re(`-Wl,-z,(no)?execstack`), re(`-Wl,-z,relro`), argv = append(argv, "-Wl,-z,relro") argv = append(argv, "-Wl,-z,relro") argv = append(argv, "-Wl,-z,nodelete") argv = append(argv, "-Wl,-z,relro") argv = append(argv, "-Wl,-z,relro") argv = append(argv, "-Wl,-znow") argv = append(argv, "-Wl,-znocopyreloc") However, not adding a space between `-z` and the param is not documented: llvm-13: $ man ld.lld-13 | grep -E -A1 -w -- "^ +-z" -z option Linker option extensions. gnu ld: $ man ld | grep -E -A1 -w -- "^ +-z" -z keyword The recognized keywords are: -- -z defs Report unresolved symbol references from regular object files. This is done even if the linker is creating a non-symbolic -- -z muldefs Normally when a symbol is defined multiple times, the linker will report a fatal error. These options allow multiple definitions -- -z --imagic ... and thus should be avoided. `zig cc`, when used as the C compiler (`CC="zig cc" go build ...`), will bark, because `zig cc` accepts only `-z PARAM`. Closes ziglang/zig#11669
1 parent 46ab7a5 commit e068e00

File tree

1 file changed

+2
-2
lines changed
  • src/cmd/link/internal/ld

1 file changed

+2
-2
lines changed

src/cmd/link/internal/ld/lib.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -1463,12 +1463,12 @@ func (ctxt *Link) hostlink() {
14631463
// We force all symbol resolution to be done at program startup
14641464
// because lazy PLT resolution can use large amounts of stack at
14651465
// times we cannot allow it to do so.
1466-
argv = append(argv, "-Wl,-znow")
1466+
argv = append(argv, "-Wl,-z,now")
14671467

14681468
// Do not let the host linker generate COPY relocations. These
14691469
// can move symbols out of sections that rely on stable offsets
14701470
// from the beginning of the section (like sym.STYPE).
1471-
argv = append(argv, "-Wl,-znocopyreloc")
1471+
argv = append(argv, "-Wl,-z,nocopyreloc")
14721472

14731473
if buildcfg.GOOS == "android" {
14741474
// Use lld to avoid errors from default linker (issue #38838)

0 commit comments

Comments
 (0)