Skip to content

Commit

Permalink
Let -Crelocation-model better control -pie linking
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
cuviper committed Mar 3, 2017
1 parent f0b5145 commit 111fbe7
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/librustc_trans/back/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ use rustc::hir::svh::Svh;
use rustc_back::tempdir::TempDir;
use rustc_back::PanicStrategy;
use rustc_incremental::IncrementalHashesMap;
use context::get_reloc_model;
use llvm;

use std::ascii;
use std::char;
Expand Down Expand Up @@ -859,13 +861,11 @@ fn link_args(cmd: &mut Linker,
if crate_type == config::CrateTypeExecutable &&
t.options.position_independent_executables {
let empty_vec = Vec::new();
let empty_str = String::new();
let args = sess.opts.cg.link_args.as_ref().unwrap_or(&empty_vec);
let more_args = &sess.opts.cg.link_arg;
let mut args = args.iter().chain(more_args.iter()).chain(used_link_args.iter());
let relocation_model = sess.opts.cg.relocation_model.as_ref()
.unwrap_or(&empty_str);
if (t.options.relocation_model == "pic" || *relocation_model == "pic")

if get_reloc_model(sess) == llvm::RelocMode::PIC
&& !args.any(|x| *x == "-static") {
cmd.position_independent_executable();
}
Expand Down

0 comments on commit 111fbe7

Please sign in to comment.