[llvm] [BOLT][AArch64] Add support for long absolute LLD thunks/veneers (PR #113408)
Paschalis Mpeis via llvm-commits
llvm-commits at lists.llvm.org
Tue Nov 5 09:18:22 PST 2024
================
@@ -29,30 +29,47 @@ static llvm::cl::opt<bool>
namespace llvm {
namespace bolt {
+static bool isPossibleVeneer(const BinaryFunction &BF) {
+ return BF.isAArch64Veneer() || BF.getOneName().starts_with("__AArch64");
+}
+
Error VeneerElimination::runOnFunctions(BinaryContext &BC) {
if (!opts::EliminateVeneers || !BC.isAArch64())
return Error::success();
- std::map<uint64_t, BinaryFunction> &BFs = BC.getBinaryFunctions();
std::unordered_map<const MCSymbol *, const MCSymbol *> VeneerDestinations;
- uint64_t VeneersCount = 0;
- for (auto &It : BFs) {
- BinaryFunction &VeneerFunction = It.second;
- if (!VeneerFunction.isAArch64Veneer())
+ uint64_t NumEliminatedVeneers = 0;
+ for (BinaryFunction &BF : llvm::make_second_range(BC.getBinaryFunctions())) {
+ if (!isPossibleVeneer(BF))
continue;
- VeneersCount++;
- VeneerFunction.setPseudo(true);
- MCInst &FirstInstruction = *(VeneerFunction.begin()->begin());
- const MCSymbol *VeneerTargetSymbol =
- BC.MIB->getTargetSymbol(FirstInstruction, 1);
- assert(VeneerTargetSymbol && "Expecting target symbol for instruction");
- for (const MCSymbol *Symbol : VeneerFunction.getSymbols())
+ if (BF.isIgnored())
+ continue;
+
+ const MCSymbol *VeneerTargetSymbol = 0;
+ uint64_t TargetAddress;
+ if (BC.MIB->matchAbsLongVeneer(BF, TargetAddress)) {
+ if (BinaryFunction *TargetBF =
+ BC.getBinaryFunctionAtAddress(TargetAddress))
+ VeneerTargetSymbol = TargetBF->getSymbol();
+ } else {
+ MCInst &FirstInstruction = *(BF.begin()->begin());
+ if (BC.MIB->hasAnnotation(FirstInstruction, "AArch64Veneer"))
+ VeneerTargetSymbol = BC.MIB->getTargetSymbol(FirstInstruction, 1);
----------------
paschalis-mpeis wrote:
Maybe we could keep the assertion just for the else case?
```cpp
assert(VeneerTargetSymbol && "Expecting target symbol for instruction");
```
https://github.com/llvm/llvm-project/pull/113408
More information about the llvm-commits
mailing list