Skip to content

Commit 8e250c3

Browse files
committed
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: golang/go@38607c5
1 parent bda32a4 commit 8e250c3

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

compiler/rustc_codegen_ssa/src/back/linker.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -473,13 +473,13 @@ impl<'a> Linker for GccLinker<'a> {
473473
self.cmd.arg(path);
474474
}
475475
fn full_relro(&mut self) {
476-
self.linker_args(&["-zrelro", "-znow"]);
476+
self.linker_args(&["-z", "relro", "-z", "now"]);
477477
}
478478
fn partial_relro(&mut self) {
479-
self.linker_arg("-zrelro");
479+
self.linker_args(&["-z", "relro"]);
480480
}
481481
fn no_relro(&mut self) {
482-
self.linker_arg("-znorelro");
482+
self.linker_args(&["-z", "norelro"]);
483483
}
484484

485485
fn link_rust_dylib(&mut self, lib: &str, _path: &Path) {
@@ -758,7 +758,7 @@ impl<'a> Linker for GccLinker<'a> {
758758
if self.sess.target.is_like_windows {
759759
self.linker_arg("--nxcompat");
760760
} else if self.is_gnu {
761-
self.linker_arg("-znoexecstack");
761+
self.linker_args(&["-z", "noexecstack"]);
762762
}
763763
}
764764

@@ -1364,16 +1364,16 @@ impl<'a> Linker for L4Bender<'a> {
13641364
}
13651365

13661366
fn full_relro(&mut self) {
1367-
self.cmd.arg("-zrelro");
1368-
self.cmd.arg("-znow");
1367+
self.cmd.arg("-z").arg("relro");
1368+
self.cmd.arg("-z").arg("now");
13691369
}
13701370

13711371
fn partial_relro(&mut self) {
1372-
self.cmd.arg("-zrelro");
1372+
self.cmd.arg("-z").arg("relro");
13731373
}
13741374

13751375
fn no_relro(&mut self) {
1376-
self.cmd.arg("-znorelro");
1376+
self.cmd.arg("-z").arg("norelro");
13771377
}
13781378

13791379
fn cmd(&mut self) -> &mut Command {

0 commit comments

Comments
 (0)