Skip to content

Commit e53d2b9

Browse files
committed
Skip PLT for built-in functions
Implementation inspired by: https://reviews.llvm.org/D42217 https://reviews.llvm.org/D42216
1 parent ba972e2 commit e53d2b9

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

src/librustc_codegen_llvm/context.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,13 @@ pub unsafe fn create_module(
208208
llvm::LLVMRustSetModulePIELevel(llmod);
209209
}
210210

211+
// If skipping the PLT is enabled, we need to add some module metadata
212+
// to ensure intrinsic calls don't use it.
213+
if sess.opts.debugging_opts.no_plt.unwrap_or(true) {
214+
let avoid_plt = "RtLibUseGOT\0".as_ptr() as *const _;
215+
llvm::LLVMRustAddModuleFlag(llmod, avoid_plt, 1);
216+
}
217+
211218
llmod
212219
}
213220

src/test/codegen/no-plt.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,6 @@ extern "C" {
2222
pub unsafe fn call_through_plt() -> *mut u8 {
2323
getenv(b"\0".as_ptr())
2424
}
25+
26+
// Ensure intrinsics also skip the PLT
27+
// CHECK: !"RtLibUseGOT"

0 commit comments

Comments
 (0)