optimize position independent code in executables

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.
This commit is contained in:
Daniel Micay 2014-08-09 12:43:45 -04:00
parent 86509d8d7a
commit 4deb4bcba5
3 changed files with 9 additions and 2 deletions

View file

@ -34,7 +34,6 @@ use std::sync::{Arc, Mutex};
use std::task::TaskBuilder; use std::task::TaskBuilder;
use libc::{c_uint, c_int, c_void}; use libc::{c_uint, c_int, c_void};
#[deriving(Clone, PartialEq, PartialOrd, Ord, Eq)] #[deriving(Clone, PartialEq, PartialOrd, Ord, Eq)]
pub enum OutputType { pub enum OutputType {
OutputTypeBitcode, OutputTypeBitcode,
@ -44,7 +43,6 @@ pub enum OutputType {
OutputTypeExe, OutputTypeExe,
} }
pub fn llvm_err(handler: &diagnostic::Handler, msg: String) -> ! { pub fn llvm_err(handler: &diagnostic::Handler, msg: String) -> ! {
unsafe { unsafe {
let cstr = llvm::LLVMRustGetLastError(); let cstr = llvm::LLVMRustGetLastError();
@ -202,6 +200,10 @@ fn create_target_machine(sess: &Session) -> TargetMachineRef {
(sess.targ_cfg.os == abi::OsMacos && (sess.targ_cfg.os == abi::OsMacos &&
sess.targ_cfg.arch == abi::X86_64); 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 // OSX has -dead_strip, which doesn't rely on ffunction_sections
// FIXME(#13846) this should be enabled for windows // FIXME(#13846) this should be enabled for windows
let ffunction_sections = sess.targ_cfg.os != abi::OsMacos && let ffunction_sections = sess.targ_cfg.os != abi::OsMacos &&
@ -240,6 +242,7 @@ fn create_target_machine(sess: &Session) -> TargetMachineRef {
true /* EnableSegstk */, true /* EnableSegstk */,
use_softfp, use_softfp,
no_fp_elim, no_fp_elim,
!any_library && reloc_model == llvm::RelocPIC,
ffunction_sections, ffunction_sections,
fdata_sections, fdata_sections,
) )

View file

@ -353,6 +353,7 @@ pub enum CodeGenOptLevel {
CodeGenLevelAggressive = 3, CodeGenLevelAggressive = 3,
} }
#[deriving(PartialEq)]
#[repr(C)] #[repr(C)]
pub enum RelocMode { pub enum RelocMode {
RelocDefault = 0, RelocDefault = 0,
@ -1907,6 +1908,7 @@ extern {
EnableSegstk: bool, EnableSegstk: bool,
UseSoftFP: bool, UseSoftFP: bool,
NoFramePointerElim: bool, NoFramePointerElim: bool,
PositionIndependentExecutable: bool,
FunctionSections: bool, FunctionSections: bool,
DataSections: bool) -> TargetMachineRef; DataSections: bool) -> TargetMachineRef;
pub fn LLVMRustDisposeTargetMachine(T: TargetMachineRef); pub fn LLVMRustDisposeTargetMachine(T: TargetMachineRef);

View file

@ -71,6 +71,7 @@ LLVMRustCreateTargetMachine(const char *triple,
bool EnableSegmentedStacks, bool EnableSegmentedStacks,
bool UseSoftFloat, bool UseSoftFloat,
bool NoFramePointerElim, bool NoFramePointerElim,
bool PositionIndependentExecutable,
bool FunctionSections, bool FunctionSections,
bool DataSections) { bool DataSections) {
std::string Error; std::string Error;
@ -83,6 +84,7 @@ LLVMRustCreateTargetMachine(const char *triple,
} }
TargetOptions Options; TargetOptions Options;
Options.PositionIndependentExecutable = PositionIndependentExecutable;
Options.NoFramePointerElim = NoFramePointerElim; Options.NoFramePointerElim = NoFramePointerElim;
#if LLVM_VERSION_MINOR < 5 #if LLVM_VERSION_MINOR < 5
Options.EnableSegmentedStacks = EnableSegmentedStacks; Options.EnableSegmentedStacks = EnableSegmentedStacks;