Skip to content

Commit 6febaf2

Browse files
committed
Implement -Z relax-elf-relocations=yes|no
This lets rustc users tweak whether the linker should relax ELF relocations, namely whether it should emit R_X86_64_GOTPCRELX relocations instead of R_X86_64_GOTPCREL, as the former is allowed by the ABI to be further optimised. The default value is whatever the target defines.
1 parent 3478d7c commit 6febaf2

File tree

3 files changed

+8
-1
lines changed

3 files changed

+8
-1
lines changed

compiler/rustc_codegen_llvm/src/back/write.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,11 @@ pub fn target_machine_factory(
156156
let emit_stack_size_section = sess.opts.debugging_opts.emit_stack_sizes;
157157

158158
let asm_comments = sess.asm_comments();
159-
let relax_elf_relocations = sess.target.options.relax_elf_relocations;
159+
let relax_elf_relocations = sess
160+
.opts
161+
.debugging_opts
162+
.relax_elf_relocations
163+
.unwrap_or(sess.target.options.relax_elf_relocations);
160164

161165
let use_init_array = !sess
162166
.opts

compiler/rustc_interface/src/tests.rs

+1
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,7 @@ fn test_debugging_options_tracking_hash() {
573573
tracked!(print_fuel, Some("abc".to_string()));
574574
tracked!(profile, true);
575575
tracked!(profile_emit, Some(PathBuf::from("abc")));
576+
tracked!(relax_elf_relocations, Some(true));
576577
tracked!(relro_level, Some(RelroLevel::Full));
577578
tracked!(report_delayed_bugs, true);
578579
tracked!(run_dsymutil, false);

compiler/rustc_session/src/options.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1030,6 +1030,8 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
10301030
"enable queries of the dependency graph for regression testing (default: no)"),
10311031
query_stats: bool = (false, parse_bool, [UNTRACKED],
10321032
"print some statistics about the query system (default: no)"),
1033+
relax_elf_relocations: Option<bool> = (None, parse_opt_bool, [TRACKED],
1034+
"whether ELF relocations can be relaxed"),
10331035
relro_level: Option<RelroLevel> = (None, parse_relro_level, [TRACKED],
10341036
"choose which RELRO level to use"),
10351037
report_delayed_bugs: bool = (false, parse_bool, [TRACKED],

0 commit comments

Comments
 (0)