diff options
| author | bors <bors@rust-lang.org> | 2014-10-13 10:32:43 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2014-10-13 10:32:43 +0000 |
| commit | 7dbd4349c406b997b486426d2e3aa9f2cc1fbd0c (patch) | |
| tree | 170f3590a7b841e48d9ebb9823719a33398ae6ab | |
| parent | a0ea210b394aa1b61d341593a3f9098fe5bf7806 (diff) | |
| parent | 4deb4bcba590e707e23670d8b40bc5520c5ab7fe (diff) | |
| download | rust-7dbd4349c406b997b486426d2e3aa9f2cc1fbd0c.tar.gz rust-7dbd4349c406b997b486426d2e3aa9f2cc1fbd0c.zip | |
auto merge of #17975 : thestinger/rust/fPIE, r=eddyb
Position independent code has fewer requirements in executables, so pass the appropriate flag to LLVM in order to allow more optimization. At the moment this means faster thread-local storage.
| -rw-r--r-- | src/librustc/back/write.rs | 7 | ||||
| -rw-r--r-- | src/librustc_llvm/lib.rs | 2 | ||||
| -rw-r--r-- | src/rustllvm/PassWrapper.cpp | 2 |
3 files changed, 9 insertions, 2 deletions
diff --git a/src/librustc/back/write.rs b/src/librustc/back/write.rs index 603f5ed227c..f1cd8b52e5e 100644 --- a/src/librustc/back/write.rs +++ b/src/librustc/back/write.rs @@ -34,7 +34,6 @@ use std::sync::{Arc, Mutex}; use std::task::TaskBuilder; use libc::{c_uint, c_int, c_void}; - #[deriving(Clone, PartialEq, PartialOrd, Ord, Eq)] pub enum OutputType { OutputTypeBitcode, @@ -44,7 +43,6 @@ pub enum OutputType { OutputTypeExe, } - pub fn llvm_err(handler: &diagnostic::Handler, msg: String) -> ! { unsafe { let cstr = llvm::LLVMRustGetLastError(); @@ -202,6 +200,10 @@ fn create_target_machine(sess: &Session) -> TargetMachineRef { (sess.targ_cfg.os == abi::OsMacos && sess.targ_cfg.arch == abi::X86_64); + let any_library = sess.crate_types.borrow().iter().any(|ty| { + *ty != config::CrateTypeExecutable + }); + // OSX has -dead_strip, which doesn't rely on ffunction_sections // FIXME(#13846) this should be enabled for windows let ffunction_sections = sess.targ_cfg.os != abi::OsMacos && @@ -240,6 +242,7 @@ fn create_target_machine(sess: &Session) -> TargetMachineRef { true /* EnableSegstk */, use_softfp, no_fp_elim, + !any_library && reloc_model == llvm::RelocPIC, ffunction_sections, fdata_sections, ) diff --git a/src/librustc_llvm/lib.rs b/src/librustc_llvm/lib.rs index e1576e37cc6..a1a6412af11 100644 --- a/src/librustc_llvm/lib.rs +++ b/src/librustc_llvm/lib.rs @@ -353,6 +353,7 @@ pub enum CodeGenOptLevel { CodeGenLevelAggressive = 3, } +#[deriving(PartialEq)] #[repr(C)] pub enum RelocMode { RelocDefault = 0, @@ -1907,6 +1908,7 @@ extern { EnableSegstk: bool, UseSoftFP: bool, NoFramePointerElim: bool, + PositionIndependentExecutable: bool, FunctionSections: bool, DataSections: bool) -> TargetMachineRef; pub fn LLVMRustDisposeTargetMachine(T: TargetMachineRef); diff --git a/src/rustllvm/PassWrapper.cpp b/src/rustllvm/PassWrapper.cpp index eb074001d58..ce3090390db 100644 --- a/src/rustllvm/PassWrapper.cpp +++ b/src/rustllvm/PassWrapper.cpp @@ -71,6 +71,7 @@ LLVMRustCreateTargetMachine(const char *triple, bool EnableSegmentedStacks, bool UseSoftFloat, bool NoFramePointerElim, + bool PositionIndependentExecutable, bool FunctionSections, bool DataSections) { std::string Error; @@ -83,6 +84,7 @@ LLVMRustCreateTargetMachine(const char *triple, } TargetOptions Options; + Options.PositionIndependentExecutable = PositionIndependentExecutable; Options.NoFramePointerElim = NoFramePointerElim; #if LLVM_VERSION_MINOR < 5 Options.EnableSegmentedStacks = EnableSegmentedStacks; |
