mirror of
https://github.com/llvm/llvm-project.git
synced 2025-04-18 17:56:50 +00:00
[BOLT][AArch64] Fix PLT optimization (#124192)
Preserve C++ exception metadata while running PLT optimization on AArch64.
This commit is contained in:
parent
77c23fd0aa
commit
34c6c5e72f
@ -1426,11 +1426,12 @@ public:
|
||||
}
|
||||
|
||||
/// Creates an indirect call to the function within the \p DirectCall PLT
|
||||
/// stub. The function's memory location is pointed by the \p TargetLocation
|
||||
/// stub. The function's address location is pointed by the \p TargetLocation
|
||||
/// symbol.
|
||||
/// Move instruction annotations from \p DirectCall to the indirect call.
|
||||
virtual InstructionListType
|
||||
createIndirectPltCall(const MCInst &DirectCall,
|
||||
const MCSymbol *TargetLocation, MCContext *Ctx) {
|
||||
createIndirectPLTCall(MCInst &&DirectCall, const MCSymbol *TargetLocation,
|
||||
MCContext *Ctx) {
|
||||
llvm_unreachable("not implemented");
|
||||
return {};
|
||||
}
|
||||
|
@ -70,8 +70,8 @@ Error PLTCall::runOnFunctions(BinaryContext &BC) {
|
||||
const BinaryFunction *CalleeBF = BC.getFunctionForSymbol(CallSymbol);
|
||||
if (!CalleeBF || !CalleeBF->isPLTFunction())
|
||||
continue;
|
||||
const InstructionListType NewCode = BC.MIB->createIndirectPltCall(
|
||||
*II, CalleeBF->getPLTSymbol(), BC.Ctx.get());
|
||||
const InstructionListType NewCode = BC.MIB->createIndirectPLTCall(
|
||||
std::move(*II), CalleeBF->getPLTSymbol(), BC.Ctx.get());
|
||||
II = BB.replaceInstruction(II, NewCode);
|
||||
assert(!NewCode.empty() && "PLT Call replacement must be non-empty");
|
||||
std::advance(II, NewCode.size() - 1);
|
||||
|
@ -1263,7 +1263,7 @@ public:
|
||||
return true;
|
||||
}
|
||||
|
||||
InstructionListType createIndirectPltCall(const MCInst &DirectCall,
|
||||
InstructionListType createIndirectPLTCall(MCInst &&DirectCall,
|
||||
const MCSymbol *TargetLocation,
|
||||
MCContext *Ctx) override {
|
||||
const bool IsTailCall = isTailCall(DirectCall);
|
||||
@ -1297,8 +1297,7 @@ public:
|
||||
MCInst InstCall;
|
||||
InstCall.setOpcode(IsTailCall ? AArch64::BR : AArch64::BLR);
|
||||
InstCall.addOperand(MCOperand::createReg(AArch64::X17));
|
||||
if (IsTailCall)
|
||||
setTailCall(InstCall);
|
||||
moveAnnotations(std::move(DirectCall), InstCall);
|
||||
Code.emplace_back(InstCall);
|
||||
|
||||
return Code;
|
||||
|
@ -1605,7 +1605,7 @@ public:
|
||||
return true;
|
||||
}
|
||||
|
||||
InstructionListType createIndirectPltCall(const MCInst &DirectCall,
|
||||
InstructionListType createIndirectPLTCall(MCInst &&DirectCall,
|
||||
const MCSymbol *TargetLocation,
|
||||
MCContext *Ctx) override {
|
||||
assert((DirectCall.getOpcode() == X86::CALL64pcrel32 ||
|
||||
|
21
bolt/test/AArch64/exceptions-plt.cpp
Normal file
21
bolt/test/AArch64/exceptions-plt.cpp
Normal file
@ -0,0 +1,21 @@
|
||||
// Verify that PLT optimization in BOLT preserves exception-handling info.
|
||||
|
||||
// REQUIRES: system-linux
|
||||
|
||||
// RUN: %clangxx %cxxflags -O1 -Wl,-q,-znow %s -o %t.exe
|
||||
// RUN: llvm-bolt %t.exe -o %t.bolt.exe --plt=all --print-only=.*main.* \
|
||||
// RUN: --print-finalized 2>&1 | FileCheck %s
|
||||
|
||||
// CHECK-LABEL: Binary Function
|
||||
// CHECK: adrp {{.*}}__cxa_throw
|
||||
// CHECK-NEXT: ldr {{.*}}__cxa_throw
|
||||
// CHECK-NEXT: blr x17 {{.*}} handler: {{.*}} PLTCall:
|
||||
|
||||
int main() {
|
||||
try {
|
||||
throw new int;
|
||||
} catch (...) {
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
16
bolt/test/runtime/exceptions-plt.cpp
Normal file
16
bolt/test/runtime/exceptions-plt.cpp
Normal file
@ -0,0 +1,16 @@
|
||||
// Verify that PLT optimization in BOLT preserves exception-handling info.
|
||||
|
||||
// REQUIRES: system-linux
|
||||
|
||||
// RUN: %clangxx %cxxflags -O1 -Wl,-q,-znow %s -o %t.exe
|
||||
// RUN: llvm-bolt %t.exe -o %t.bolt.exe --plt=all
|
||||
// RUN: %t.bolt.exe
|
||||
|
||||
int main() {
|
||||
try {
|
||||
throw new int;
|
||||
} catch (...) {
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user