diff --git a/src/librustc_llvm/ffi.rs b/src/librustc_llvm/ffi.rs index 402166cc13f..5cb5a62c93b 100644 --- a/src/librustc_llvm/ffi.rs +++ b/src/librustc_llvm/ffi.rs @@ -284,10 +284,13 @@ pub enum CodeGenOptLevel { #[derive(Copy, Clone, PartialEq)] #[repr(C)] pub enum RelocMode { - Default = 0, - Static = 1, - PIC = 2, - DynamicNoPic = 3, + Default, + Static, + PIC, + DynamicNoPic, + ROPI, + RWPI, + ROPI_RWPI, } /// LLVMRustCodeModel diff --git a/src/librustc_trans/back/write.rs b/src/librustc_trans/back/write.rs index ccb3f7ac882..3492403a1bf 100644 --- a/src/librustc_trans/back/write.rs +++ b/src/librustc_trans/back/write.rs @@ -37,11 +37,14 @@ use std::sync::mpsc::channel; use std::thread; use libc::{c_uint, c_void}; -pub const RELOC_MODEL_ARGS : [(&'static str, llvm::RelocMode); 4] = [ +pub const RELOC_MODEL_ARGS : [(&'static str, llvm::RelocMode); 7] = [ ("pic", llvm::RelocMode::PIC), ("static", llvm::RelocMode::Static), ("default", llvm::RelocMode::Default), ("dynamic-no-pic", llvm::RelocMode::DynamicNoPic), + ("ropi", llvm::RelocMode::ROPI), + ("rwpi", llvm::RelocMode::RWPI), + ("ropi-rwpi", llvm::RelocMode::ROPI_RWPI), ]; pub const CODE_GEN_MODEL_ARGS : [(&'static str, llvm::CodeModel); 5] = [ diff --git a/src/rustllvm/PassWrapper.cpp b/src/rustllvm/PassWrapper.cpp index b938f94cda2..fdbe4e5f7ad 100644 --- a/src/rustllvm/PassWrapper.cpp +++ b/src/rustllvm/PassWrapper.cpp @@ -246,6 +246,47 @@ static CodeGenOpt::Level fromRust(LLVMRustCodeGenOptLevel Level) { } } +enum class LLVMRustRelocMode { + Default, + Static, + PIC, + DynamicNoPic, + ROPI, + RWPI, + ROPIRWPI, +}; + +#if LLVM_VERSION_LE(3, 8) +static Reloc::Model fromRust(LLVMRustRelocMode RustReloc) { +#else +static Optional fromRust(LLVMRustRelocMode RustReloc) { +#endif + switch (RustReloc) { + case LLVMRustRelocMode::Default: +#if LLVM_VERSION_LE(3, 8) + return Reloc::Default; +#else + return None; +#endif + case LLVMRustRelocMode::Static: + return Reloc::Static; + case LLVMRustRelocMode::PIC: + return Reloc::PIC_; + case LLVMRustRelocMode::DynamicNoPic: + return Reloc::DynamicNoPIC; +#if LLVM_VERSION_GE(4, 0) + case LLVMRustRelocMode::ROPI: + return Reloc::ROPI; + case LLVMRustRelocMode::RWPI: + return Reloc::RWPI; + case LLVMRustRelocMode::ROPIRWPI: + return Reloc::ROPI_RWPI; +#endif + default: + llvm_unreachable("Bad RelocModel."); + } +} + #if LLVM_RUSTLLVM /// getLongestEntryLength - Return the length of the longest entry in the table. /// @@ -297,35 +338,14 @@ extern "C" void LLVMRustPrintTargetFeatures(LLVMTargetMachineRef) { extern "C" LLVMTargetMachineRef LLVMRustCreateTargetMachine( const char *TripleStr, const char *CPU, const char *Feature, - LLVMRustCodeModel RustCM, LLVMRelocMode Reloc, + LLVMRustCodeModel RustCM, LLVMRustRelocMode RustReloc, LLVMRustCodeGenOptLevel RustOptLevel, bool UseSoftFloat, bool PositionIndependentExecutable, bool FunctionSections, bool DataSections) { -#if LLVM_VERSION_LE(3, 8) - Reloc::Model RM; -#else - Optional RM; -#endif auto CM = fromRust(RustCM); auto OptLevel = fromRust(RustOptLevel); - - switch (Reloc) { - case LLVMRelocStatic: - RM = Reloc::Static; - break; - case LLVMRelocPIC: - RM = Reloc::PIC_; - break; - case LLVMRelocDynamicNoPic: - RM = Reloc::DynamicNoPIC; - break; - default: -#if LLVM_VERSION_LE(3, 8) - RM = Reloc::Default; -#endif - break; - } + auto RM = fromRust(RustReloc); std::string Error; Triple Trip(Triple::normalize(TripleStr));