mirror of https://github.com/rust-lang/rust.git
Added LLVMRustRelocMode
Replaces the llvm-c exposed LLVMRelocMode, which does not include all relocation model variants, with a LLVMRustRelocMode modeled after LLVMRustCodeMode.
This commit is contained in:
parent
32b92669e4
commit
0f00f27e0d
|
@ -284,13 +284,13 @@ pub enum CodeGenOptLevel {
|
||||||
#[derive(Copy, Clone, PartialEq)]
|
#[derive(Copy, Clone, PartialEq)]
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
pub enum RelocMode {
|
pub enum RelocMode {
|
||||||
Default = 0,
|
Default,
|
||||||
Static = 1,
|
Static,
|
||||||
PIC = 2,
|
PIC,
|
||||||
DynamicNoPic = 3,
|
DynamicNoPic,
|
||||||
ROPI = 4,
|
ROPI,
|
||||||
RWPI = 5,
|
RWPI,
|
||||||
ROPI_RWPI = 6,
|
ROPI_RWPI,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// LLVMRustCodeModel
|
/// LLVMRustCodeModel
|
||||||
|
|
|
@ -239,6 +239,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<Reloc::Model> 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
|
#if LLVM_RUSTLLVM
|
||||||
/// getLongestEntryLength - Return the length of the longest entry in the table.
|
/// getLongestEntryLength - Return the length of the longest entry in the table.
|
||||||
///
|
///
|
||||||
|
@ -290,46 +331,14 @@ extern "C" void LLVMRustPrintTargetFeatures(LLVMTargetMachineRef) {
|
||||||
|
|
||||||
extern "C" LLVMTargetMachineRef LLVMRustCreateTargetMachine(
|
extern "C" LLVMTargetMachineRef LLVMRustCreateTargetMachine(
|
||||||
const char *TripleStr, const char *CPU, const char *Feature,
|
const char *TripleStr, const char *CPU, const char *Feature,
|
||||||
LLVMRustCodeModel RustCM, int Reloc,
|
LLVMRustCodeModel RustCM, LLVMRustRelocMode RustReloc,
|
||||||
LLVMRustCodeGenOptLevel RustOptLevel, bool UseSoftFloat,
|
LLVMRustCodeGenOptLevel RustOptLevel, bool UseSoftFloat,
|
||||||
bool PositionIndependentExecutable, bool FunctionSections,
|
bool PositionIndependentExecutable, bool FunctionSections,
|
||||||
bool DataSections) {
|
bool DataSections) {
|
||||||
|
|
||||||
#if LLVM_VERSION_LE(3, 8)
|
|
||||||
Reloc::Model RM;
|
|
||||||
#else
|
|
||||||
Optional<Reloc::Model> RM;
|
|
||||||
#endif
|
|
||||||
auto CM = fromRust(RustCM);
|
auto CM = fromRust(RustCM);
|
||||||
auto OptLevel = fromRust(RustOptLevel);
|
auto OptLevel = fromRust(RustOptLevel);
|
||||||
|
auto RM = fromRust(RustReloc);
|
||||||
switch (Reloc) {
|
|
||||||
case 1:
|
|
||||||
RM = Reloc::Static;
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
RM = Reloc::PIC_;
|
|
||||||
break;
|
|
||||||
case 3:
|
|
||||||
RM = Reloc::DynamicNoPIC;
|
|
||||||
break;
|
|
||||||
#if LLVM_VERSION_GE(4, 0)
|
|
||||||
case 4:
|
|
||||||
RM = Reloc::ROPI;
|
|
||||||
break;
|
|
||||||
case 5:
|
|
||||||
RM = Reloc::RWPI;
|
|
||||||
break;
|
|
||||||
case 6:
|
|
||||||
RM = Reloc::ROPI_RWPI;
|
|
||||||
break;
|
|
||||||
#endif
|
|
||||||
default:
|
|
||||||
#if LLVM_VERSION_LE(3, 8)
|
|
||||||
RM = Reloc::Default;
|
|
||||||
#endif
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string Error;
|
std::string Error;
|
||||||
Triple Trip(Triple::normalize(TripleStr));
|
Triple Trip(Triple::normalize(TripleStr));
|
||||||
|
|
Loading…
Reference in New Issue