Rollup merge of #88820 - hlopko:add_pie_relocation_model, r=petrochenkov
Add `pie` as another `relocation-model` value MCP: https://github.com/rust-lang/compiler-team/issues/461
This commit is contained in:
commit
6f1e930581
11 changed files with 147 additions and 8 deletions
|
@ -129,7 +129,8 @@ fn to_pass_builder_opt_level(cfg: config::OptLevel) -> llvm::PassBuilderOptLevel
|
|||
fn to_llvm_relocation_model(relocation_model: RelocModel) -> llvm::RelocModel {
|
||||
match relocation_model {
|
||||
RelocModel::Static => llvm::RelocModel::Static,
|
||||
RelocModel::Pic => llvm::RelocModel::PIC,
|
||||
// LLVM doesn't have a PIE relocation model, it represents PIE as PIC with an extra attribute.
|
||||
RelocModel::Pic | RelocModel::Pie => llvm::RelocModel::PIC,
|
||||
RelocModel::DynamicNoPic => llvm::RelocModel::DynamicNoPic,
|
||||
RelocModel::Ropi => llvm::RelocModel::ROPI,
|
||||
RelocModel::Rwpi => llvm::RelocModel::RWPI,
|
||||
|
|
|
@ -195,11 +195,14 @@ pub unsafe fn create_module(
|
|||
let llvm_target = SmallCStr::new(&sess.target.llvm_target);
|
||||
llvm::LLVMRustSetNormalizedTarget(llmod, llvm_target.as_ptr());
|
||||
|
||||
if sess.relocation_model() == RelocModel::Pic {
|
||||
let reloc_model = sess.relocation_model();
|
||||
if matches!(reloc_model, RelocModel::Pic | RelocModel::Pie) {
|
||||
llvm::LLVMRustSetModulePICLevel(llmod);
|
||||
// PIE is potentially more effective than PIC, but can only be used in executables.
|
||||
// If all our outputs are executables, then we can relax PIC to PIE.
|
||||
if sess.crate_types().iter().all(|ty| *ty == CrateType::Executable) {
|
||||
if reloc_model == RelocModel::Pie
|
||||
|| sess.crate_types().iter().all(|ty| *ty == CrateType::Executable)
|
||||
{
|
||||
llvm::LLVMRustSetModulePIELevel(llmod);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -211,9 +211,16 @@ impl CodegenBackend for LlvmCodegenBackend {
|
|||
match req {
|
||||
PrintRequest::RelocationModels => {
|
||||
println!("Available relocation models:");
|
||||
for name in
|
||||
&["static", "pic", "dynamic-no-pic", "ropi", "rwpi", "ropi-rwpi", "default"]
|
||||
{
|
||||
for name in &[
|
||||
"static",
|
||||
"pic",
|
||||
"pie",
|
||||
"dynamic-no-pic",
|
||||
"ropi",
|
||||
"rwpi",
|
||||
"ropi-rwpi",
|
||||
"default",
|
||||
] {
|
||||
println!(" {}", name);
|
||||
}
|
||||
println!();
|
||||
|
|
|
@ -143,6 +143,12 @@ impl CodegenCx<'ll, 'tcx> {
|
|||
return true;
|
||||
}
|
||||
|
||||
// With pie relocation model calls of functions defined in the translation
|
||||
// unit can use copy relocations.
|
||||
if self.tcx.sess.relocation_model() == RelocModel::Pie && !is_declaration {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue