Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Explicitly pass -no-pie #44067

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions src/librustc_trans/back/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -894,18 +894,24 @@ fn link_args(cmd: &mut Linker,

let used_link_args = sess.cstore.used_link_args();

let mut pie = false;
if crate_type == config::CrateTypeExecutable &&
t.options.position_independent_executables {
t.options.position_independent_executables {
let empty_vec = Vec::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());

if get_reloc_model(sess) == llvm::RelocMode::PIC
&& !sess.crt_static() && !args.any(|x| *x == "-static") {
cmd.position_independent_executable();
if get_reloc_model(sess) == llvm::RelocMode::PIC &&
!sess.crt_static() && !args.any(|x| *x == "-static") {
pie = true
}
}
if pie {
cmd.position_independent_executable();
} else {
cmd.no_position_independent_executable();
}

let relro_level = match sess.opts.debugging_opts.relro_level {
Some(level) => level,
Expand Down
10 changes: 10 additions & 0 deletions src/librustc_trans/back/linker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ pub trait Linker {
fn add_object(&mut self, path: &Path);
fn gc_sections(&mut self, keep_metadata: bool);
fn position_independent_executable(&mut self);
fn no_position_independent_executable(&mut self);
fn partial_relro(&mut self);
fn full_relro(&mut self);
fn optimize(&mut self);
Expand Down Expand Up @@ -178,6 +179,7 @@ impl<'a> Linker for GccLinker<'a> {
fn output_filename(&mut self, path: &Path) { self.cmd.arg("-o").arg(path); }
fn add_object(&mut self, path: &Path) { self.cmd.arg(path); }
fn position_independent_executable(&mut self) { self.cmd.arg("-pie"); }
fn no_position_independent_executable(&mut self) { self.cmd.arg("-no-pie"); }
fn partial_relro(&mut self) { self.linker_arg("-z,relro"); }
fn full_relro(&mut self) { self.linker_arg("-z,relro,-z,now"); }
fn build_static_executable(&mut self) { self.cmd.arg("-static"); }
Expand Down Expand Up @@ -438,6 +440,10 @@ impl<'a> Linker for MsvcLinker<'a> {
// noop
}

fn no_position_independent_executable(&mut self) {
// noop
}

fn partial_relro(&mut self) {
// noop
}
Expand Down Expand Up @@ -634,6 +640,10 @@ impl<'a> Linker for EmLinker<'a> {
// noop
}

fn no_position_independent_executable(&mut self) {
// noop
}

fn partial_relro(&mut self) {
// noop
}
Expand Down