Skip to content

Commit 1943079

Browse files
committed
Configure LLVM module PIC level
As of LLVM 9, this is required for 32-bit PowerPC to properly generate PLT references. Previously, only BigPIC was supported; now LLVM supports both BigPIC and SmallPIC, and there is no default value provided.
1 parent 91fd628 commit 1943079

File tree

3 files changed

+9
-0
lines changed

3 files changed

+9
-0
lines changed

src/librustc_codegen_llvm/context.rs

+4
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,10 @@ pub unsafe fn create_module(
203203
let llvm_target = SmallCStr::new(&sess.target.target.llvm_target);
204204
llvm::LLVMRustSetNormalizedTarget(llmod, llvm_target.as_ptr());
205205

206+
if get_reloc_model(sess) == llvm::RelocMode::PIC {
207+
llvm::LLVMRustSetModulePICLevel(llmod);
208+
}
209+
206210
if is_pie_binary(sess) {
207211
llvm::LLVMRustSetModulePIELevel(llmod);
208212
}

src/librustc_codegen_llvm/llvm/ffi.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1805,6 +1805,7 @@ extern "C" {
18051805

18061806
pub fn LLVMRustSetComdat(M: &'a Module, V: &'a Value, Name: *const c_char);
18071807
pub fn LLVMRustUnsetComdat(V: &Value);
1808+
pub fn LLVMRustSetModulePICLevel(M: &Module);
18081809
pub fn LLVMRustSetModulePIELevel(M: &Module);
18091810
pub fn LLVMRustModuleBufferCreate(M: &Module) -> &'static mut ModuleBuffer;
18101811
pub fn LLVMRustModuleBufferPtr(p: &ModuleBuffer) -> *const u8;

src/rustllvm/PassWrapper.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -754,6 +754,10 @@ LLVMRustSetDataLayoutFromTargetMachine(LLVMModuleRef Module,
754754
unwrap(Module)->setDataLayout(Target->createDataLayout());
755755
}
756756

757+
extern "C" void LLVMRustSetModulePICLevel(LLVMModuleRef M) {
758+
unwrap(M)->setPICLevel(PICLevel::Level::BigPIC);
759+
}
760+
757761
extern "C" void LLVMRustSetModulePIELevel(LLVMModuleRef M) {
758762
unwrap(M)->setPIELevel(PIELevel::Level::Large);
759763
}

0 commit comments

Comments
 (0)