diff --git a/src/librustc/back/link.rs b/src/librustc/back/link.rs index 7c9844dbe33fb..47275f386e5e4 100644 --- a/src/librustc/back/link.rs +++ b/src/librustc/back/link.rs @@ -197,6 +197,10 @@ pub mod write { (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 && @@ -249,6 +253,7 @@ pub mod write { 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 1ac0aee85d4d9..13a7ec743a884 100644 --- a/src/librustc_llvm/lib.rs +++ b/src/librustc_llvm/lib.rs @@ -340,6 +340,7 @@ pub enum CodeGenOptLevel { CodeGenLevelAggressive = 3, } +#[deriving(PartialEq)] #[repr(C)] pub enum RelocMode { RelocDefault = 0, @@ -1869,6 +1870,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 195b044ccdcef..6409491272731 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;