From 8e250c3c6462991ef618ba07d8ce3208ec585a8f Mon Sep 17 00:00:00 2001 From: Frank Denis Date: Tue, 21 Feb 2023 14:52:20 +0100 Subject: [PATCH] Linker: use -z instead of -z The GNU linker accepts -z, but this is undocumented, and not supported by other linkers. In particular, `zig cc`, when used as the C compiler/linker (e.g. when using `cargo-zigbuild`), will not accept this undocumented syntax. In `linker.rs`, both syntaxes are also used inconsistently. The Go compiler used to have the same issue, but fixed it: https://github.com/golang/go/commit/38607c553878da21b5042e63997ecb3b7201e684 --- compiler/rustc_codegen_ssa/src/back/linker.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/compiler/rustc_codegen_ssa/src/back/linker.rs b/compiler/rustc_codegen_ssa/src/back/linker.rs index eaf1e9817c2..52c01b423a7 100644 --- a/compiler/rustc_codegen_ssa/src/back/linker.rs +++ b/compiler/rustc_codegen_ssa/src/back/linker.rs @@ -473,13 +473,13 @@ impl<'a> Linker for GccLinker<'a> { self.cmd.arg(path); } fn full_relro(&mut self) { - self.linker_args(&["-zrelro", "-znow"]); + self.linker_args(&["-z", "relro", "-z", "now"]); } fn partial_relro(&mut self) { - self.linker_arg("-zrelro"); + self.linker_args(&["-z", "relro"]); } fn no_relro(&mut self) { - self.linker_arg("-znorelro"); + self.linker_args(&["-z", "norelro"]); } fn link_rust_dylib(&mut self, lib: &str, _path: &Path) { @@ -758,7 +758,7 @@ impl<'a> Linker for GccLinker<'a> { if self.sess.target.is_like_windows { self.linker_arg("--nxcompat"); } else if self.is_gnu { - self.linker_arg("-znoexecstack"); + self.linker_args(&["-z", "noexecstack"]); } } @@ -1364,16 +1364,16 @@ impl<'a> Linker for L4Bender<'a> { } fn full_relro(&mut self) { - self.cmd.arg("-zrelro"); - self.cmd.arg("-znow"); + self.cmd.arg("-z").arg("relro"); + self.cmd.arg("-z").arg("now"); } fn partial_relro(&mut self) { - self.cmd.arg("-zrelro"); + self.cmd.arg("-z").arg("relro"); } fn no_relro(&mut self) { - self.cmd.arg("-znorelro"); + self.cmd.arg("-z").arg("norelro"); } fn cmd(&mut self) -> &mut Command {