Skip to content

Commit 32b9266

Browse files
committed
Add RWPI/ROPI relocation model support
Adds support for using LLVM 4's ROPI and RWPI relocation models for ARM
1 parent b0a4074 commit 32b9266

File tree

3 files changed

+22
-5
lines changed

3 files changed

+22
-5
lines changed

src/librustc_llvm/ffi.rs

+3
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,9 @@ pub enum RelocMode {
288288
Static = 1,
289289
PIC = 2,
290290
DynamicNoPic = 3,
291+
ROPI = 4,
292+
RWPI = 5,
293+
ROPI_RWPI = 6,
291294
}
292295

293296
/// LLVMRustCodeModel

src/librustc_trans/back/write.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,14 @@ use std::sync::mpsc::channel;
3737
use std::thread;
3838
use libc::{c_uint, c_void};
3939

40-
pub const RELOC_MODEL_ARGS : [(&'static str, llvm::RelocMode); 4] = [
40+
pub const RELOC_MODEL_ARGS : [(&'static str, llvm::RelocMode); 7] = [
4141
("pic", llvm::RelocMode::PIC),
4242
("static", llvm::RelocMode::Static),
4343
("default", llvm::RelocMode::Default),
4444
("dynamic-no-pic", llvm::RelocMode::DynamicNoPic),
45+
("ropi", llvm::RelocMode::ROPI),
46+
("rwpi", llvm::RelocMode::RWPI),
47+
("ropi-rwpi", llvm::RelocMode::ROPI_RWPI),
4548
];
4649

4750
pub const CODE_GEN_MODEL_ARGS : [(&'static str, llvm::CodeModel); 5] = [

src/rustllvm/PassWrapper.cpp

+15-4
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ extern "C" void LLVMRustPrintTargetFeatures(LLVMTargetMachineRef) {
290290

291291
extern "C" LLVMTargetMachineRef LLVMRustCreateTargetMachine(
292292
const char *TripleStr, const char *CPU, const char *Feature,
293-
LLVMRustCodeModel RustCM, LLVMRelocMode Reloc,
293+
LLVMRustCodeModel RustCM, int Reloc,
294294
LLVMRustCodeGenOptLevel RustOptLevel, bool UseSoftFloat,
295295
bool PositionIndependentExecutable, bool FunctionSections,
296296
bool DataSections) {
@@ -304,15 +304,26 @@ extern "C" LLVMTargetMachineRef LLVMRustCreateTargetMachine(
304304
auto OptLevel = fromRust(RustOptLevel);
305305

306306
switch (Reloc) {
307-
case LLVMRelocStatic:
307+
case 1:
308308
RM = Reloc::Static;
309309
break;
310-
case LLVMRelocPIC:
310+
case 2:
311311
RM = Reloc::PIC_;
312312
break;
313-
case LLVMRelocDynamicNoPic:
313+
case 3:
314314
RM = Reloc::DynamicNoPIC;
315315
break;
316+
#if LLVM_VERSION_GE(4, 0)
317+
case 4:
318+
RM = Reloc::ROPI;
319+
break;
320+
case 5:
321+
RM = Reloc::RWPI;
322+
break;
323+
case 6:
324+
RM = Reloc::ROPI_RWPI;
325+
break;
326+
#endif
316327
default:
317328
#if LLVM_VERSION_LE(3, 8)
318329
RM = Reloc::Default;

0 commit comments

Comments
 (0)