Fix typo, trampolin -> trampoline

This commit is contained in:
Maschell 2022-05-13 16:14:46 +02:00
parent 21da3ebc27
commit 70eebb31b0
6 changed files with 33 additions and 33 deletions

View File

@ -8,7 +8,7 @@
#include "ElfUtils.h" #include "ElfUtils.h"
#include "elfio/elfio.hpp" #include "elfio/elfio.hpp"
bool ElfUtils::doRelocation(std::vector<std::shared_ptr<RelocationData>> &relocData, relocation_trampolin_entry_t *tramp_data, uint32_t tramp_length) { bool ElfUtils::doRelocation(std::vector<std::shared_ptr<RelocationData>> &relocData, relocation_trampoline_entry_t *tramp_data, uint32_t tramp_length) {
for (auto const &curReloc : relocData) { for (auto const &curReloc : relocData) {
std::string functionName = curReloc->getName(); std::string functionName = curReloc->getName();
std::string rplName = curReloc->getImportRPLInformation()->getName(); std::string rplName = curReloc->getImportRPLInformation()->getName();
@ -35,13 +35,13 @@ bool ElfUtils::doRelocation(std::vector<std::shared_ptr<RelocationData>> &relocD
} }
} }
DCFlushRange(tramp_data, tramp_length * sizeof(relocation_trampolin_entry_t)); DCFlushRange(tramp_data, tramp_length * sizeof(relocation_trampoline_entry_t));
ICInvalidateRange(tramp_data, tramp_length * sizeof(relocation_trampolin_entry_t)); ICInvalidateRange(tramp_data, tramp_length * sizeof(relocation_trampoline_entry_t));
return true; return true;
} }
// See https://github.com/decaf-emu/decaf-emu/blob/43366a34e7b55ab9d19b2444aeb0ccd46ac77dea/src/libdecaf/src/cafe/loader/cafe_loader_reloc.cpp#L144 // See https://github.com/decaf-emu/decaf-emu/blob/43366a34e7b55ab9d19b2444aeb0ccd46ac77dea/src/libdecaf/src/cafe/loader/cafe_loader_reloc.cpp#L144
bool ElfUtils::elfLinkOne(char type, size_t offset, int32_t addend, uint32_t destination, uint32_t symbol_addr, relocation_trampolin_entry_t *trampolin_data, uint32_t trampolin_data_length, bool ElfUtils::elfLinkOne(char type, size_t offset, int32_t addend, uint32_t destination, uint32_t symbol_addr, relocation_trampoline_entry_t *trampolin_data, uint32_t trampolin_data_length,
RelocationType reloc_type) { RelocationType reloc_type) {
if (type == R_PPC_NONE) { if (type == R_PPC_NONE) {
return true; return true;
@ -112,11 +112,11 @@ bool ElfUtils::elfLinkOne(char type, size_t offset, int32_t addend, uint32_t des
auto distance = static_cast<int32_t>(value) - static_cast<int32_t>(target); auto distance = static_cast<int32_t>(value) - static_cast<int32_t>(target);
if (distance > 0x1FFFFFC || distance < -0x1FFFFFC) { if (distance > 0x1FFFFFC || distance < -0x1FFFFFC) {
if (trampolin_data == nullptr) { if (trampolin_data == nullptr) {
DEBUG_FUNCTION_LINE_ERR("***24-bit relative branch cannot hit target. Trampolin isn't provided\n"); DEBUG_FUNCTION_LINE_ERR("***24-bit relative branch cannot hit target. Trampoline isn't provided\n");
DEBUG_FUNCTION_LINE_ERR("***value %08X - target %08X = distance %08X\n", value, target, distance); DEBUG_FUNCTION_LINE_ERR("***value %08X - target %08X = distance %08X\n", value, target, distance);
return false; return false;
} else { } else {
relocation_trampolin_entry_t *freeSlot = nullptr; relocation_trampoline_entry_t *freeSlot = nullptr;
for (uint32_t i = 0; i < trampolin_data_length; i++) { for (uint32_t i = 0; i < trampolin_data_length; i++) {
// We want to override "old" relocations of imports // We want to override "old" relocations of imports
// Pending relocations have the status RELOC_TRAMP_IMPORT_IN_PROGRESS. // Pending relocations have the status RELOC_TRAMP_IMPORT_IN_PROGRESS.
@ -131,22 +131,22 @@ bool ElfUtils::elfLinkOne(char type, size_t offset, int32_t addend, uint32_t des
} }
} }
if (freeSlot == nullptr) { if (freeSlot == nullptr) {
DEBUG_FUNCTION_LINE_ERR("***24-bit relative branch cannot hit target. Trampolin data list is full\n"); DEBUG_FUNCTION_LINE_ERR("***24-bit relative branch cannot hit target. Trampoline data list is full\n");
DEBUG_FUNCTION_LINE_ERR("***value %08X - target %08X = distance %08X\n", value, target, (target - (uint32_t) & (freeSlot->trampolin[0]))); DEBUG_FUNCTION_LINE_ERR("***value %08X - target %08X = distance %08X\n", value, target, (target - (uint32_t) & (freeSlot->trampoline[0])));
return false; return false;
} }
if (target - (uint32_t) & (freeSlot->trampoline[0]) > 0x1FFFFFC) { if (target - (uint32_t) & (freeSlot->trampoline[0]) > 0x1FFFFFC) {
DEBUG_FUNCTION_LINE_ERR("**Cannot link 24-bit jump (too far to tramp buffer)."); DEBUG_FUNCTION_LINE_ERR("**Cannot link 24-bit jump (too far to tramp buffer).");
DEBUG_FUNCTION_LINE_ERR("***value %08X - target %08X = distance %08X\n", value, target, (target - (uint32_t) & (freeSlot->trampolin[0]))); DEBUG_FUNCTION_LINE_ERR("***value %08X - target %08X = distance %08X\n", value, target, (target - (uint32_t) & (freeSlot->trampoline[0])));
return false; return false;
} }
freeSlot->trampolin[0] = 0x3D600000 | ((((uint32_t) value) >> 16) & 0x0000FFFF); // lis r11, real_addr@h freeSlot->trampoline[0] = 0x3D600000 | ((((uint32_t) value) >> 16) & 0x0000FFFF); // lis r11, real_addr@h
freeSlot->trampolin[1] = 0x616B0000 | (((uint32_t) value) & 0x0000ffff); // ori r11, r11, real_addr@l freeSlot->trampoline[1] = 0x616B0000 | (((uint32_t) value) & 0x0000ffff); // ori r11, r11, real_addr@l
freeSlot->trampolin[2] = 0x7D6903A6; // mtctr r11 freeSlot->trampoline[2] = 0x7D6903A6; // mtctr r11
freeSlot->trampolin[3] = 0x4E800420; // bctr freeSlot->trampoline[3] = 0x4E800420; // bctr
DCFlushRange((void *) freeSlot->trampolin, sizeof(freeSlot->trampolin)); DCFlushRange((void *) freeSlot->trampoline, sizeof(freeSlot->trampoline));
ICInvalidateRange((unsigned char *) freeSlot->trampolin, sizeof(freeSlot->trampolin)); ICInvalidateRange((unsigned char *) freeSlot->trampoline, sizeof(freeSlot->trampoline));
if (reloc_type == RELOC_TYPE_FIXED) { if (reloc_type == RELOC_TYPE_FIXED) {
freeSlot->status = RELOC_TRAMP_FIXED; freeSlot->status = RELOC_TRAMP_FIXED;
@ -154,7 +154,7 @@ bool ElfUtils::elfLinkOne(char type, size_t offset, int32_t addend, uint32_t des
// Relocations for the imports may be overridden // Relocations for the imports may be overridden
freeSlot->status = RELOC_TRAMP_IMPORT_DONE; freeSlot->status = RELOC_TRAMP_IMPORT_DONE;
} }
auto symbolValue = (uint32_t) & (freeSlot->trampolin[0]); auto symbolValue = (uint32_t) & (freeSlot->trampoline[0]);
value = symbolValue + addend; value = symbolValue + addend;
distance = static_cast<int32_t>(value) - static_cast<int32_t>(target); distance = static_cast<int32_t>(value) - static_cast<int32_t>(target);
} }

View File

@ -46,9 +46,9 @@ extern "C" {
class ElfUtils { class ElfUtils {
public: public:
static bool elfLinkOne(char type, size_t offset, int32_t addend, uint32_t destination, uint32_t symbol_addr, relocation_trampolin_entry_t *trampolin_data, uint32_t trampolin_data_length, static bool elfLinkOne(char type, size_t offset, int32_t addend, uint32_t destination, uint32_t symbol_addr, relocation_trampoline_entry_t *trampolin_data, uint32_t trampolin_data_length,
RelocationType reloc_type); RelocationType reloc_type);
static bool doRelocation(std::vector<std::shared_ptr<RelocationData>> &relocData, relocation_trampolin_entry_t *tramp_data, uint32_t tramp_length); static bool doRelocation(std::vector<std::shared_ptr<RelocationData>> &relocData, relocation_trampoline_entry_t *tramp_data, uint32_t tramp_length);
}; };

View File

@ -27,7 +27,7 @@ extern "C" {
#endif #endif
struct module_information_t { struct module_information_t {
relocation_trampolin_entry_t trampolines[DYN_LINK_TRAMPOLIN_LIST_LENGTH]; relocation_trampoline_entry_t trampolines[DYN_LINK_TRAMPOLIN_LIST_LENGTH];
}; };
#ifdef __cplusplus #ifdef __cplusplus

View File

@ -19,19 +19,19 @@
#include <cstdint> #include <cstdint>
typedef enum RelocationTrampolinStatus { typedef enum RelocationTrampolineStatus {
RELOC_TRAMP_FREE = 0, RELOC_TRAMP_FREE = 0,
RELOC_TRAMP_FIXED = 1, RELOC_TRAMP_FIXED = 1,
RELOC_TRAMP_IMPORT_IN_PROGRESS = 2, RELOC_TRAMP_IMPORT_IN_PROGRESS = 2,
RELOC_TRAMP_IMPORT_DONE = 3, RELOC_TRAMP_IMPORT_DONE = 3,
} RelocationTrampolinStatus; } RelocationTrampolineStatus;
typedef enum RelocationType { typedef enum RelocationType {
RELOC_TYPE_FIXED = 0, RELOC_TYPE_FIXED = 0,
RELOC_TYPE_IMPORT = 1 RELOC_TYPE_IMPORT = 1
} RelocationType; } RelocationType;
typedef struct relocation_trampolin_entry_t { typedef struct relocation_trampoline_entry_t {
uint32_t trampolin[4]; uint32_t trampoline[4];
RelocationTrampolinStatus status; RelocationTrampolineStatus status;
} relocation_trampolin_entry_t; } relocation_trampoline_entry_t;

View File

@ -26,7 +26,7 @@
using namespace ELFIO; using namespace ELFIO;
std::optional<std::shared_ptr<ModuleData>> std::optional<std::shared_ptr<ModuleData>>
ModuleDataFactory::load(const std::string &path, uint32_t destination_address_end, uint32_t maximum_size, relocation_trampolin_entry_t *trampolin_data, uint32_t trampolin_data_length) { ModuleDataFactory::load(const std::string &path, uint32_t destination_address_end, uint32_t maximum_size, relocation_trampoline_entry_t *trampoline_data, uint32_t trampoline_data_length) {
elfio reader; elfio reader;
std::shared_ptr<ModuleData> moduleData = std::make_shared<ModuleData>(); std::shared_ptr<ModuleData> moduleData = std::make_shared<ModuleData>();
@ -149,7 +149,7 @@ ModuleDataFactory::load(const std::string &path, uint32_t destination_address_en
section *psec = reader.sections[i]; section *psec = reader.sections[i];
if ((psec->get_type() == SHT_PROGBITS || psec->get_type() == SHT_NOBITS) && (psec->get_flags() & SHF_ALLOC)) { if ((psec->get_type() == SHT_PROGBITS || psec->get_type() == SHT_NOBITS) && (psec->get_flags() & SHF_ALLOC)) {
DEBUG_FUNCTION_LINE("Linking (%d)... %s", i, psec->get_name().c_str()); DEBUG_FUNCTION_LINE("Linking (%d)... %s", i, psec->get_name().c_str());
if (!linkSection(reader, psec->get_index(), (uint32_t) destinations[psec->get_index()], offset_text, offset_data, trampolin_data, trampolin_data_length)) { if (!linkSection(reader, psec->get_index(), (uint32_t) destinations[psec->get_index()], offset_text, offset_data, trampoline_data, trampoline_data_length)) {
DEBUG_FUNCTION_LINE_ERR("elfLink failed"); DEBUG_FUNCTION_LINE_ERR("elfLink failed");
free(destinations); free(destinations);
free(buffer); free(buffer);
@ -230,8 +230,8 @@ std::vector<std::shared_ptr<RelocationData>> ModuleDataFactory::getImportRelocat
return result; return result;
} }
bool ModuleDataFactory::linkSection(elfio &reader, uint32_t section_index, uint32_t destination, uint32_t base_text, uint32_t base_data, relocation_trampolin_entry_t *trampolin_data, bool ModuleDataFactory::linkSection(elfio &reader, uint32_t section_index, uint32_t destination, uint32_t base_text, uint32_t base_data, relocation_trampoline_entry_t *trampoline_data,
uint32_t trampolin_data_length) { uint32_t trampoline_data_length) {
uint32_t sec_num = reader.sections.size(); uint32_t sec_num = reader.sections.size();
for (uint32_t i = 0; i < sec_num; ++i) { for (uint32_t i = 0; i < sec_num; ++i) {
@ -276,7 +276,7 @@ bool ModuleDataFactory::linkSection(elfio &reader, uint32_t section_index, uint3
return false; return false;
} }
if (!ElfUtils::elfLinkOne(type, offset, addend, destination, adjusted_sym_value, trampolin_data, trampolin_data_length, RELOC_TYPE_FIXED)) { if (!ElfUtils::elfLinkOne(type, offset, addend, destination, adjusted_sym_value, trampoline_data, trampoline_data_length, RELOC_TYPE_FIXED)) {
DEBUG_FUNCTION_LINE_ERR("Link failed"); DEBUG_FUNCTION_LINE_ERR("Link failed");
return false; return false;
} }

View File

@ -27,10 +27,10 @@
class ModuleDataFactory { class ModuleDataFactory {
public: public:
static std::optional<std::shared_ptr<ModuleData>> static std::optional<std::shared_ptr<ModuleData>>
load(const std::string &path, uint32_t destination_address_end, uint32_t maximum_size, relocation_trampolin_entry_t *trampolin_data, uint32_t trampolin_data_length); load(const std::string &path, uint32_t destination_address_end, uint32_t maximum_size, relocation_trampoline_entry_t *trampoline_data, uint32_t trampoline_data_length);
static bool linkSection(ELFIO::elfio &reader, uint32_t section_index, uint32_t destination, uint32_t base_text, uint32_t base_data, relocation_trampolin_entry_t *trampolin_data, static bool linkSection(ELFIO::elfio &reader, uint32_t section_index, uint32_t destination, uint32_t base_text, uint32_t base_data, relocation_trampoline_entry_t *trampoline_data,
uint32_t trampolin_data_length); uint32_t trampoline_data_length);
static std::vector<std::shared_ptr<RelocationData>> getImportRelocationData(ELFIO::elfio &reader, uint8_t **destinations); static std::vector<std::shared_ptr<RelocationData>> getImportRelocationData(ELFIO::elfio &reader, uint8_t **destinations);
}; };