]> git.lizzy.rs Git - rust.git/commitdiff
optimize position independent code in executables
authorDaniel Micay <danielmicay@gmail.com>
Sat, 9 Aug 2014 16:43:45 +0000 (12:43 -0400)
committerDaniel Micay <danielmicay@gmail.com>
Sun, 12 Oct 2014 13:18:14 +0000 (09:18 -0400)
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.

src/librustc/back/write.rs
src/librustc_llvm/lib.rs
src/rustllvm/PassWrapper.cpp

index 603f5ed227cdf8e0621701cb6d4d100d0f06abdc..f1cd8b52e5ed3103fa8e2b0a09c87dcecfdae0d0 100644 (file)
@@ -34,7 +34,6 @@
 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,
                     )
index e1576e37cc64cea92843a451d7fe83eacfc02437..a1a6412af1135605891132e4df57ad1f20788541 100644 (file)
@@ -353,6 +353,7 @@ pub enum CodeGenOptLevel {
     CodeGenLevelAggressive = 3,
 }
 
+#[deriving(PartialEq)]
 #[repr(C)]
 pub enum RelocMode {
     RelocDefault = 0,
@@ -1907,6 +1908,7 @@ pub fn LLVMRustCreateTargetMachine(Triple: *const c_char,
                                        EnableSegstk: bool,
                                        UseSoftFP: bool,
                                        NoFramePointerElim: bool,
+                                       PositionIndependentExecutable: bool,
                                        FunctionSections: bool,
                                        DataSections: bool) -> TargetMachineRef;
     pub fn LLVMRustDisposeTargetMachine(T: TargetMachineRef);
index eb074001d5854bf42e5d4d627a624f56b30196c2..ce3090390db8e73ac904ee6fc6f742a2960fb8dc 100644 (file)
@@ -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;