From 30d7e3b7bde41ebb5556adc180150fd397d16e6f Mon Sep 17 00:00:00 2001 From: Maschell Date: Sat, 18 Sep 2021 12:01:04 +0200 Subject: [PATCH] Fix R_PPC_REL24 relocations --- relocator/src/ElfUtils.cpp | 10 +++++----- source/ElfUtils.cpp | 9 ++++----- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/relocator/src/ElfUtils.cpp b/relocator/src/ElfUtils.cpp index b77565c..03b3753 100644 --- a/relocator/src/ElfUtils.cpp +++ b/relocator/src/ElfUtils.cpp @@ -91,14 +91,15 @@ bool ElfUtils::elfLinkOne(char type, size_t offset, int32_t addend, uint32_t des break; } } - if (freeSlot != NULL) { + if (freeSlot == nullptr) { DEBUG_FUNCTION_LINE("***24-bit relative branch cannot hit target. Trampolin data list is full\n"); - DEBUG_FUNCTION_LINE("***value %08X - target %08X = distance %08X\n", value, target, distance); + DEBUG_FUNCTION_LINE("***value %08X - target %08X = distance %08X\n", value, target, (target - (uint32_t) &(freeSlot->trampolin[0]))); + return false; } if (target - (uint32_t) &(freeSlot->trampolin[0]) > 0x1FFFFFC) { DEBUG_FUNCTION_LINE("**Cannot link 24-bit jump (too far to tramp buffer)."); - DEBUG_FUNCTION_LINE("***value %08X - target %08X = distance %08X\n", value, target, distance); + DEBUG_FUNCTION_LINE("***value %08X - target %08X = distance %08X\n", value, target, (target - (uint32_t) &(freeSlot->trampolin[0]))); return false; } @@ -113,12 +114,11 @@ bool ElfUtils::elfLinkOne(char type, size_t offset, int32_t addend, uint32_t des freeSlot->status = RELOC_TRAMP_FIXED; } else { // Relocations for the imports may be overridden - freeSlot->status = RELOC_TRAMP_IMPORT_IN_PROGRESS; + freeSlot->status = RELOC_TRAMP_IMPORT_DONE; } auto symbolValue = (uint32_t) &(freeSlot->trampolin[0]); value = symbolValue + addend; distance = static_cast(value) - static_cast(target); - DEBUG_FUNCTION_LINE("Created tramp\n"); } } diff --git a/source/ElfUtils.cpp b/source/ElfUtils.cpp index 015f262..867a3fc 100644 --- a/source/ElfUtils.cpp +++ b/source/ElfUtils.cpp @@ -196,14 +196,14 @@ bool ElfUtils::elfLinkOne(char type, size_t offset, int32_t addend, uint32_t des break; } } - if (freeSlot != NULL) { + if (freeSlot == nullptr) { DEBUG_FUNCTION_LINE("***24-bit relative branch cannot hit target. Trampolin data list is full\n"); - DEBUG_FUNCTION_LINE("***value %08X - target %08X = distance %08X\n", value, target, distance); + DEBUG_FUNCTION_LINE("***value %08X - target %08X = distance %08X\n", value, target, (target - (uint32_t) &(freeSlot->trampolin[0]))); return false; } if (target - (uint32_t) &(freeSlot->trampolin[0]) > 0x1FFFFFC) { DEBUG_FUNCTION_LINE("**Cannot link 24-bit jump (too far to tramp buffer)."); - DEBUG_FUNCTION_LINE("***value %08X - target %08X = distance %08X\n", value, target, distance); + DEBUG_FUNCTION_LINE("***value %08X - target %08X = distance %08X\n", value, target, (target - (uint32_t) &(freeSlot->trampolin[0]))); return false; } @@ -218,12 +218,11 @@ bool ElfUtils::elfLinkOne(char type, size_t offset, int32_t addend, uint32_t des freeSlot->status = RELOC_TRAMP_FIXED; } else { // Relocations for the imports may be overridden - freeSlot->status = RELOC_TRAMP_IMPORT_IN_PROGRESS; + freeSlot->status = RELOC_TRAMP_IMPORT_DONE; } auto symbolValue = (uint32_t) &(freeSlot->trampolin[0]); value = symbolValue + addend; distance = static_cast(value) - static_cast(target); - DEBUG_FUNCTION_LINE("Created tramp\n"); } }