From be3bcba701437fd1b8e2f07d367f37d775095051 Mon Sep 17 00:00:00 2001 From: dimok789 Date: Tue, 11 Oct 2016 19:04:55 +0200 Subject: [PATCH] - added missing gcc_except_table section - added ignore of paddings in elf2rpl --- rules/rpl.ld | 5 +++-- tools/elf2rpl/main.cpp | 37 +++++++++++++++++++++++-------------- 2 files changed, 26 insertions(+), 16 deletions(-) diff --git a/rules/rpl.ld b/rules/rpl.ld index cc4d289..157e6bc 100644 --- a/rules/rpl.ld +++ b/rules/rpl.ld @@ -151,14 +151,14 @@ SECTIONS { /* Reserve space for the TLS segment of the main thread */ __tls_start = .; - + __tbss_start = .; *(.tbss) *(.tbss.*) *(.gnu.linkonce.tb.*) *(.tcommon) __tbss_end = .; - + . += + SIZEOF(.tdata); __tls_end = .; . = ALIGN(32); @@ -193,6 +193,7 @@ SECTIONS { /* Required compiler trash */ .fixup ALIGN(32) : { *(.fixup*) } .got ALIGN(32) : { *(.got*) } + .gcc_except_table ALIGN(32) : { *(.gcc_except_table*) } .hash ALIGN(32) : { *(.hash) } .dynsym ALIGN(32) : { *(.dynsym) } diff --git a/tools/elf2rpl/main.cpp b/tools/elf2rpl/main.cpp index 81e13b0..47d8331 100644 --- a/tools/elf2rpl/main.cpp +++ b/tools/elf2rpl/main.cpp @@ -94,7 +94,7 @@ findSymbol(ElfFile &file, uint32_t address) return symbol.get(); } } - + for (auto &symbol : file.symbols) { if (symbol->address == address) { return symbol.get(); @@ -238,6 +238,9 @@ read(ElfFile &file, const std::string &filename) case elf::R_PPC_RELATIVE: *ptr = byte_swap(addr); break; + case elf::R_PPC_NONE: + // ignore padding + break; default: std::cout << "Unexpected relocation type in .rela.dyn section" << std::endl; return false; @@ -448,7 +451,7 @@ read(ElfFile &file, const std::string &filename) // If we can't find a proper symbol, write the addend in and hope for the best auto ptr = getLoaderDataPtr(inSections, rela.offset); *ptr = addend; - + std::cout << "Unexpected addend " << std::hex << addend << " referenced in relocation section " << name << ", continuing." << std::endl; continue; } @@ -458,7 +461,7 @@ read(ElfFile &file, const std::string &filename) file.relocations.emplace_back(relocation); } } - + // Read dyn relocations for (auto §ion : inSections) { if (section.header.type != elf::SHT_RELA) { @@ -484,6 +487,12 @@ read(ElfFile &file, const std::string &filename) auto symbol = getSectionSymbol(symSection, index); auto addr = symbol->value + rela.addend; + if(type == elf::R_PPC_NONE) + { + // ignore padding + continue; + } + if(index == 0) { auto addend = static_cast(rela.addend); @@ -785,7 +794,7 @@ write(ElfFile &file, const std::string &filename) if(relocation->type == elf::R_PPC_RELATIVE) { rela.info = elf::R_PPC_ADDR32 | idx << 8; - } + } rela.addend = relocation->addend; rela.offset = relocation->target; @@ -897,7 +906,7 @@ write(ElfFile &file, const std::string &filename) char *symData = reinterpret_cast(&sym); symTabSection->data.insert(symTabSection->data.end(), symData, symData + sizeof(elf::Symbol)); } - + //Finish SHT_RPL_IMPORTS signatures Bytef *zero_buffer = reinterpret_cast(calloc(0x10, 1)); for (auto §ion : outSections) { @@ -1063,7 +1072,7 @@ write(ElfFile &file, const std::string &filename) if (section->header.type != elf::SHT_RPL_CRCS && section->header.type != elf::SHT_RPL_FILEINFO) { continue; } - + if (section->header.type != elf::SHT_NOBITS) { section->header.size = section->data.size(); } @@ -1075,17 +1084,17 @@ write(ElfFile &file, const std::string &filename) section->header.offset = 0; } } - + // Add data sections next for (auto §ion : outSections) { if(section->header.offset != -1) { continue; } - + if (section->header.addr < DataAddress || section->header.addr >= WiiuLoadAddress) { continue; } - + if (section->header.type != elf::SHT_NOBITS) { section->header.size = section->data.size(); } @@ -1097,17 +1106,17 @@ write(ElfFile &file, const std::string &filename) section->header.offset = 0; } } - + // Add load sections next for (auto §ion : outSections) { if(section->header.offset != -1) { continue; } - + if (section->header.addr < WiiuLoadAddress) { continue; } - + if (section->header.type != elf::SHT_NOBITS) { section->header.size = section->data.size(); } @@ -1119,13 +1128,13 @@ write(ElfFile &file, const std::string &filename) section->header.offset = 0; } } - + // Everything else for (auto §ion : outSections) { if(section->header.offset != -1) { continue; } - + if (section->header.type != elf::SHT_NOBITS) { section->header.size = section->data.size(); }