void-packages/srcpkgs/rust/patches/0099-set-piclevel.patch
q66 d94f88a684 rust: update to 1.39.0
This also switches to LLVM9.
2019-11-10 14:58:00 +01:00

56 lines
2.3 KiB
Diff

From 194307936110470487c41637684d4b09b3516af5 Mon Sep 17 00:00:00 2001
From: Samuel Holland <samuel@sholland.org>
Date: Sun, 3 Nov 2019 10:52:00 -0600
Subject: [PATCH] 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.
---
src/librustc_codegen_llvm/context.rs | 4 ++++
src/librustc_codegen_llvm/llvm/ffi.rs | 1 +
src/rustllvm/PassWrapper.cpp | 4 ++++
3 files changed, 9 insertions(+)
diff --git a/src/librustc_codegen_llvm/context.rs b/src/librustc_codegen_llvm/context.rs
index 2da938771721..4a40349cb73e 100644
--- a/src/librustc_codegen_llvm/context.rs
+++ b/src/librustc_codegen_llvm/context.rs
@@ -203,6 +203,10 @@ pub unsafe fn create_module(
let llvm_target = SmallCStr::new(&sess.target.target.llvm_target);
llvm::LLVMRustSetNormalizedTarget(llmod, llvm_target.as_ptr());
+ if get_reloc_model(sess) == llvm::RelocMode::PIC {
+ llvm::LLVMRustSetModulePICLevel(llmod);
+ }
+
if is_pie_binary(sess) {
llvm::LLVMRustSetModulePIELevel(llmod);
}
diff --git a/src/librustc_codegen_llvm/llvm/ffi.rs b/src/librustc_codegen_llvm/llvm/ffi.rs
index c69942ef3f2d..7f7b5b22d9af 100644
--- a/src/librustc_codegen_llvm/llvm/ffi.rs
+++ b/src/librustc_codegen_llvm/llvm/ffi.rs
@@ -1805,6 +1805,7 @@ extern "C" {
pub fn LLVMRustSetComdat(M: &'a Module, V: &'a Value, Name: *const c_char);
pub fn LLVMRustUnsetComdat(V: &Value);
+ pub fn LLVMRustSetModulePICLevel(M: &Module);
pub fn LLVMRustSetModulePIELevel(M: &Module);
pub fn LLVMRustModuleBufferCreate(M: &Module) -> &'static mut ModuleBuffer;
pub fn LLVMRustModuleBufferPtr(p: &ModuleBuffer) -> *const u8;
diff --git a/src/rustllvm/PassWrapper.cpp b/src/rustllvm/PassWrapper.cpp
index 0cda3465dc09..4c5bc20b86db 100644
--- a/src/rustllvm/PassWrapper.cpp
+++ b/src/rustllvm/PassWrapper.cpp
@@ -754,6 +754,10 @@ LLVMRustSetDataLayoutFromTargetMachine(LLVMModuleRef Module,
unwrap(Module)->setDataLayout(Target->createDataLayout());
}
+extern "C" void LLVMRustSetModulePICLevel(LLVMModuleRef M) {
+ unwrap(M)->setPICLevel(PICLevel::Level::BigPIC);
+}
+
extern "C" void LLVMRustSetModulePIELevel(LLVMModuleRef M) {
unwrap(M)->setPIELevel(PIELevel::Level::Large);
}