diff --git a/FEXCore/Source/Interface/Core/CPUBackend.h b/FEXCore/Source/Interface/Core/CPUBackend.h index 9eb9e0639..b8963ebc6 100644 --- a/FEXCore/Source/Interface/Core/CPUBackend.h +++ b/FEXCore/Source/Interface/Core/CPUBackend.h @@ -161,7 +161,7 @@ namespace CPU { virtual CompiledCode CompileCode(uint64_t Entry, uint64_t Size, bool SingleInst, const FEXCore::IR::IRListView* IR, FEXCore::Core::DebugData* DebugData, bool CheckTF) = 0; - virtual fextl::vector TakeRelocations() = 0; + virtual fextl::vector TakeRelocations(uint64_t GuestBaseAddress) = 0; virtual void ClearCache() {} diff --git a/FEXCore/Source/Interface/Core/JIT/Arm64Relocations.cpp b/FEXCore/Source/Interface/Core/JIT/Arm64Relocations.cpp index 1dffe711e..f6729a6bc 100644 --- a/FEXCore/Source/Interface/Core/JIT/Arm64Relocations.cpp +++ b/FEXCore/Source/Interface/Core/JIT/Arm64Relocations.cpp @@ -150,7 +150,19 @@ bool Arm64JITCore::ApplyRelocations(uint64_t GuestEntry, std::span Co return true; } -fextl::vector Arm64JITCore::TakeRelocations() { +fextl::vector Arm64JITCore::TakeRelocations(uint64_t GuestBaseAddress) { + // Rebase relocations to library base address + for (auto& Relocation : Relocations) { + switch (Relocation.Header.Type) { + case FEXCore::CPU::RelocationTypes::RELOC_GUEST_RIP_MOVE: + case FEXCore::CPU::RelocationTypes::RELOC_GUEST_RIP_LITERAL: { + Relocation.GuestRIP.GuestRIP -= GuestBaseAddress; + break; + } + default:; + } + } + return std::move(Relocations); } diff --git a/FEXCore/Source/Interface/Core/JIT/JITClass.h b/FEXCore/Source/Interface/Core/JIT/JITClass.h index fd5fc3a22..521176d6d 100644 --- a/FEXCore/Source/Interface/Core/JIT/JITClass.h +++ b/FEXCore/Source/Interface/Core/JIT/JITClass.h @@ -594,7 +594,13 @@ private: ///< Relocation code loading bool ApplyRelocations(uint64_t GuestEntry, std::span Code, std::span); - fextl::vector TakeRelocations() override; + /** + * Returns any relocations generated since the last call to TakeRelocations. + * + * GuestBaseAddress must match the base virtual address to which the + * input x86 binary is mapped. + */ + fextl::vector TakeRelocations(uint64_t GuestBaseAddress) override; /** @} */