Skip to content

Commit 111fbe7

Browse files
committed
Let -Crelocation-model better control -pie linking
Prior to this, if relocation model in the target options was "pic", as most targets have it, then the user's `-Crelocation-model` had no effect on whether `-pie` would be used. Only `-Clink-arg=-static` would have a further override here. Now we use `context::get_reloc_model`, which gives precedence to the user's option, and if it's `RelocMode::PIC` we enable `-pie`. This is the same test as `context::is_pie_binary`, except that folds across all `sess.crate_types`, not just the current one.
1 parent f0b5145 commit 111fbe7

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/librustc_trans/back/link.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ use rustc::hir::svh::Svh;
3131
use rustc_back::tempdir::TempDir;
3232
use rustc_back::PanicStrategy;
3333
use rustc_incremental::IncrementalHashesMap;
34+
use context::get_reloc_model;
35+
use llvm;
3436

3537
use std::ascii;
3638
use std::char;
@@ -859,13 +861,11 @@ fn link_args(cmd: &mut Linker,
859861
if crate_type == config::CrateTypeExecutable &&
860862
t.options.position_independent_executables {
861863
let empty_vec = Vec::new();
862-
let empty_str = String::new();
863864
let args = sess.opts.cg.link_args.as_ref().unwrap_or(&empty_vec);
864865
let more_args = &sess.opts.cg.link_arg;
865866
let mut args = args.iter().chain(more_args.iter()).chain(used_link_args.iter());
866-
let relocation_model = sess.opts.cg.relocation_model.as_ref()
867-
.unwrap_or(&empty_str);
868-
if (t.options.relocation_model == "pic" || *relocation_model == "pic")
867+
868+
if get_reloc_model(sess) == llvm::RelocMode::PIC
869869
&& !args.any(|x| *x == "-static") {
870870
cmd.position_independent_executable();
871871
}

0 commit comments

Comments
 (0)