about summary refs log tree commit diff
path: root/compiler
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2023-02-21 18:53:34 +0000
committerbors <bors@rust-lang.org>2023-02-21 18:53:34 +0000
commit246eae2fab54a5139365c4e1a08c5724fb385fbf (patch)
tree172384106b5abfdfc2b9336cbe242d74f68e5c38 /compiler
parentf4c7596ac3f2d27578787da3279705fd45aefbd6 (diff)
parent8e250c3c6462991ef618ba07d8ce3208ec585a8f (diff)
downloadrust-246eae2fab54a5139365c4e1a08c5724fb385fbf.tar.gz
rust-246eae2fab54a5139365c4e1a08c5724fb385fbf.zip
Auto merge of #108307 - jedisct1:z-link-flags, r=wesleywiser
Linker: use -z <params> instead of -z<params>

The GNU linker accepts -z<params>, 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
Diffstat (limited to 'compiler')
-rw-r--r--compiler/rustc_codegen_ssa/src/back/linker.rs16
1 files 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 {