[BOLT] Drop -znow requirement for PLT optimization on x86-64 (#178758)
On x86-64, PLT optimization does not require the binary to be linked with -znow because indirect calls through GOT work correctly with lazy binding. At runtime, the dynamic linker's resolver will populate the GOT entry on the first call, just like with a regular PLT call. This change removes the -znow requirement specifically for x86-64 while keeping it for other architectures. I haven't checked RISV-V, but it's still necessary on AArch64.
This commit is contained in:
parent
b93d6c2fd6
commit
34a7608fad
3 changed files with 24 additions and 3 deletions
|
|
@ -724,7 +724,7 @@
|
|||
|
||||
- `--plt=<value>`
|
||||
|
||||
Optimize PLT calls (requires linking with -znow)
|
||||
Optimize PLT calls (requires linking with -znow on non-x86 architectures)
|
||||
- `none`: do not optimize PLT calls
|
||||
- `hot`: optimize executed (hot) PLT calls
|
||||
- `all`: optimize all PLT calls
|
||||
|
|
|
|||
|
|
@ -23,7 +23,9 @@ namespace opts {
|
|||
extern cl::OptionCategory BoltOptCategory;
|
||||
|
||||
static cl::opt<bolt::PLTCall::OptType>
|
||||
PLT("plt", cl::desc("optimize PLT calls (requires linking with -znow)"),
|
||||
PLT("plt",
|
||||
cl::desc("optimize PLT calls (requires linking with -znow on "
|
||||
"non-x86 architectures)"),
|
||||
cl::init(bolt::PLTCall::OT_NONE),
|
||||
cl::values(clEnumValN(bolt::PLTCall::OT_NONE, "none",
|
||||
"do not optimize PLT calls"),
|
||||
|
|
@ -76,7 +78,12 @@ Error PLTCall::runOnFunctions(BinaryContext &BC) {
|
|||
}
|
||||
|
||||
if (NumCallsOptimized) {
|
||||
BC.RequiresZNow = true;
|
||||
// On X86-64, PLT optimization does not require -znow because the indirect
|
||||
// call through GOT works correctly with lazy binding. At runtime, the
|
||||
// resolver will populate the GOT entry on first call just like with a
|
||||
// regular PLT call.
|
||||
if (!BC.isX86())
|
||||
BC.RequiresZNow = true;
|
||||
BC.outs() << "BOLT-INFO: " << NumCallsOptimized
|
||||
<< " PLT calls in the binary were optimized.\n";
|
||||
}
|
||||
|
|
|
|||
14
bolt/test/runtime/X86/plt-call.c
Normal file
14
bolt/test/runtime/X86/plt-call.c
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
// Check that PLT optimization works on X86-64 without -znow.
|
||||
|
||||
// RUN: %clang %cflags %s -o %t.exe -Wl,-q
|
||||
// RUN: llvm-bolt %t.exe -o %t.bolt --plt=all
|
||||
// RUN: %t.bolt | FileCheck %s
|
||||
|
||||
// CHECK: Success
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
puts("Success");
|
||||
return 0;
|
||||
}
|
||||
Loading…
Reference in a new issue