Skip to content

Commit f0c459e

Browse files
committed
Make relro-level=off explicitly disable RELRO
Previously relro-level=off would just not tell the linker to use RELRO, but when you want to disable RELRO you most likely want to entirely prevent. Signed-off-by: Johannes Löthberg <[email protected]>
1 parent 2789b06 commit f0c459e

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

src/librustc_trans/back/link.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1014,7 +1014,9 @@ fn link_args(cmd: &mut Linker,
10141014
RelroLevel::Partial => {
10151015
cmd.partial_relro();
10161016
},
1017-
RelroLevel::Off => {},
1017+
RelroLevel::Off => {
1018+
cmd.no_relro();
1019+
},
10181020
}
10191021

10201022
// Pass optimization flags down to the linker.

src/librustc_trans/back/linker.rs

+18-5
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,9 @@ pub trait Linker {
113113
fn gc_sections(&mut self, keep_metadata: bool);
114114
fn position_independent_executable(&mut self);
115115
fn no_position_independent_executable(&mut self);
116-
fn partial_relro(&mut self);
117116
fn full_relro(&mut self);
117+
fn partial_relro(&mut self);
118+
fn no_relro(&mut self);
118119
fn optimize(&mut self);
119120
fn debuginfo(&mut self);
120121
fn no_default_libraries(&mut self);
@@ -188,8 +189,9 @@ impl<'a> Linker for GccLinker<'a> {
188189
fn add_object(&mut self, path: &Path) { self.cmd.arg(path); }
189190
fn position_independent_executable(&mut self) { self.cmd.arg("-pie"); }
190191
fn no_position_independent_executable(&mut self) { self.cmd.arg("-no-pie"); }
191-
fn partial_relro(&mut self) { self.linker_arg("-z,relro"); }
192192
fn full_relro(&mut self) { self.linker_arg("-z,relro,-z,now"); }
193+
fn partial_relro(&mut self) { self.linker_arg("-z,relro"); }
194+
fn no_relro(&mut self) { self.linker_arg("-z,norelro"); }
193195
fn build_static_executable(&mut self) { self.cmd.arg("-static"); }
194196
fn args(&mut self, args: &[String]) { self.cmd.args(args); }
195197

@@ -452,11 +454,15 @@ impl<'a> Linker for MsvcLinker<'a> {
452454
// noop
453455
}
454456

457+
fn full_relro(&mut self) {
458+
// noop
459+
}
460+
455461
fn partial_relro(&mut self) {
456462
// noop
457463
}
458464

459-
fn full_relro(&mut self) {
465+
fn no_relro(&mut self) {
460466
// noop
461467
}
462468

@@ -664,11 +670,15 @@ impl<'a> Linker for EmLinker<'a> {
664670
// noop
665671
}
666672

673+
fn full_relro(&mut self) {
674+
// noop
675+
}
676+
667677
fn partial_relro(&mut self) {
668678
// noop
669679
}
670680

671-
fn full_relro(&mut self) {
681+
fn no_relro(&mut self) {
672682
// noop
673683
}
674684

@@ -829,10 +839,13 @@ impl Linker for WasmLd {
829839
fn position_independent_executable(&mut self) {
830840
}
831841

842+
fn full_relro(&mut self) {
843+
}
844+
832845
fn partial_relro(&mut self) {
833846
}
834847

835-
fn full_relro(&mut self) {
848+
fn no_relro(&mut self) {
836849
}
837850

838851
fn build_static_executable(&mut self) {

0 commit comments

Comments
 (0)