[BOLT] Fix data reoder for aarch64

Use proper relocation for aarch64

Differential Revision: https://reviews.llvm.org/D144095
This commit is contained in:
Vladislav Khmelevsky 2023-02-15 17:18:37 +04:00 committed by Tobias Hieta
parent 867c59c2da
commit 32b8cc7031
3 changed files with 10 additions and 1 deletions

View File

@ -106,6 +106,9 @@ struct Relocation {
/// Return code for a PC-relative 8-byte relocation
static uint64_t getPC64();
/// Return code for a ABS 8-byte relocation
static uint64_t getAbs64();
/// Return true if this relocation is PC-relative. Return false otherwise.
bool isPCRelative() const { return isPCRelative(Type); }

View File

@ -252,7 +252,7 @@ void BinarySection::reorderContents(const std::vector<BinaryData *> &Order,
// of the reordered segment to force LLVM to recognize and map this
// section.
MCSymbol *ZeroSym = BC.registerNameAtAddress("Zero", 0, 0, 0);
addRelocation(OS.tell(), ZeroSym, ELF::R_X86_64_64, 0xdeadbeef);
addRelocation(OS.tell(), ZeroSym, Relocation::getAbs64(), 0xdeadbeef);
uint64_t Zero = 0;
OS.write(reinterpret_cast<const char *>(&Zero), sizeof(Zero));

View File

@ -637,6 +637,12 @@ bool Relocation::isPCRelative(uint64_t Type) {
return isPCRelativeX86(Type);
}
uint64_t Relocation::getAbs64() {
if (Arch == Triple::aarch64)
return ELF::R_AARCH64_ABS64;
return ELF::R_X86_64_64;
}
size_t Relocation::emit(MCStreamer *Streamer) const {
const size_t Size = getSizeForType(Type);
MCContext &Ctx = Streamer->getContext();