diff --git a/bolt/include/bolt/Core/BinaryFunction.h b/bolt/include/bolt/Core/BinaryFunction.h --- a/bolt/include/bolt/Core/BinaryFunction.h +++ b/bolt/include/bolt/Core/BinaryFunction.h @@ -2053,6 +2053,10 @@ void handleIndirectBranch(MCInst &Instruction, uint64_t Size, uint64_t Offset); + // Check for linker veneers, which lack relocations and need manual + // adjustments. + void handleAArch64IndirectCall(MCInst &Instruction, const uint64_t Offset); + /// Scan function for references to other functions. In relocation mode, /// add relocations for external references. /// diff --git a/bolt/lib/Core/BinaryFunction.cpp b/bolt/lib/Core/BinaryFunction.cpp --- a/bolt/lib/Core/BinaryFunction.cpp +++ b/bolt/lib/Core/BinaryFunction.cpp @@ -1133,6 +1133,28 @@ } } +void BinaryFunction::handleAArch64IndirectCall(MCInst &Instruction, + const uint64_t Offset) { + auto &MIB = BC.MIB; + const uint64_t AbsoluteInstrAddr = getAddress() + Offset; + MCInst *TargetHiBits, *TargetLowBits; + uint64_t TargetAddress, Count; + Count = MIB->matchLinkerVeneer(Instructions.begin(), Instructions.end(), + AbsoluteInstrAddr, Instruction, TargetHiBits, + TargetLowBits, TargetAddress); + if (Count) { + MIB->addAnnotation(Instruction, "AArch64Veneer", true); + --Count; + for (auto It = std::prev(Instructions.end()); Count != 0; + It = std::prev(It), --Count) { + MIB->addAnnotation(It->second, "AArch64Veneer", true); + } + + BC.addAdrpAddRelocAArch64(*this, *TargetLowBits, *TargetHiBits, + TargetAddress); + } +} + bool BinaryFunction::disassemble() { NamedRegionTimer T("disassemble", "Disassemble function", "buildfuncs", "Build Binary Functions", opts::TimeBuild); @@ -1151,28 +1173,6 @@ // basic block. Labels[0] = Ctx->createNamedTempSymbol("BB0"); - // Check for linker veneers, which lack relocations and need manual - // adjustments. - auto handleAArch64IndirectCall = [&](MCInst &Instruction, uint64_t Offset) { - const uint64_t AbsoluteInstrAddr = getAddress() + Offset; - MCInst *TargetHiBits, *TargetLowBits; - uint64_t TargetAddress, Count; - Count = MIB->matchLinkerVeneer(Instructions.begin(), Instructions.end(), - AbsoluteInstrAddr, Instruction, TargetHiBits, - TargetLowBits, TargetAddress); - if (Count) { - MIB->addAnnotation(Instruction, "AArch64Veneer", true); - --Count; - for (auto It = std::prev(Instructions.end()); Count != 0; - It = std::prev(It), --Count) { - MIB->addAnnotation(It->second, "AArch64Veneer", true); - } - - BC.addAdrpAddRelocAArch64(*this, *TargetLowBits, *TargetHiBits, - TargetAddress); - } - }; - uint64_t Size = 0; // instruction size for (uint64_t Offset = 0; Offset < getSize(); Offset += Size) { MCInst Instruction;