Skip to content

Commit 98cbe17

Browse files
authored
Rollup merge of rust-lang#66062 - smaeul:patch/pic-level, r=estebank
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.
2 parents 81550a0 + 1943079 commit 98cbe17

File tree

3 files changed

+9
-0
lines changed

3 files changed

+9
-0
lines changed

src/librustc_codegen_llvm/context.rs

Lines changed: 4 additions & 0 deletions
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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1807,6 +1807,7 @@ extern "C" {
18071807

18081808
pub fn LLVMRustSetComdat(M: &'a Module, V: &'a Value, Name: *const c_char);
18091809
pub fn LLVMRustUnsetComdat(V: &Value);
1810+
pub fn LLVMRustSetModulePICLevel(M: &Module);
18101811
pub fn LLVMRustSetModulePIELevel(M: &Module);
18111812
pub fn LLVMRustModuleBufferCreate(M: &Module) -> &'static mut ModuleBuffer;
18121813
pub fn LLVMRustModuleBufferPtr(p: &ModuleBuffer) -> *const u8;

src/rustllvm/PassWrapper.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -755,6 +755,10 @@ LLVMRustSetDataLayoutFromTargetMachine(LLVMModuleRef Module,
755755
unwrap(Module)->setDataLayout(Target->createDataLayout());
756756
}
757757

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

0 commit comments

Comments
 (0)