Have elf2rpl write in same allignments as reflected in rpl.ld, fix issue with .tbss where GCC is dumb and doesn't increment the address

This commit is contained in:
shinyquagsire23 2016-07-30 16:54:13 -07:00
parent 9398b20936
commit 23dff0fe81
2 changed files with 22 additions and 29 deletions

View File

@ -90,15 +90,6 @@ SECTIONS {
__tdata_lma_end = .;
} : hdr_data
.tbss ALIGN(256) :
{
*(.tbss)
*(.tbss.*)
*(.gnu.linkonce.tb.*)
*(.tcommon)
. = ALIGN(4);
} : hdr_data
.preinit_array ALIGN(256) :
{
PROVIDE (__preinit_array_start = .);
@ -139,31 +130,39 @@ SECTIONS {
} : hdr_data
__bss_start__ = .;
.bss ALIGN(4) :
.bss ALIGN(256) :
{
*(.dynbss)
*(.bss)
*(.bss.*)
*(.gnu.linkonce.b*)
*(COMMON)
. = ALIGN(4);
. = ALIGN(32);
__sbss_start = .;
*(.sbss)
*(.sbss.*)
__sbss_end = .;
. = ALIGN(4);
. = ALIGN(32);
__sbss2_start = .;
*(.sbss2)
*(.sbss2.*)
*(.gnu.linkonce.sb2.*)
__sbss2_end = .;
. = ALIGN(4);
. = ALIGN(32);
/* Reserve space for the TLS segment of the main thread */
__tls_start = .;
. += + SIZEOF(.tdata) + SIZEOF(.tbss);
__tbss_start = .;
*(.tbss)
*(.tbss.*)
*(.gnu.linkonce.tb.*)
*(.tcommon)
__tbss_end = .;
. += + SIZEOF(.tdata);
__tls_end = .;
. = ALIGN(32);
} : hdr_data

View File

@ -423,19 +423,11 @@ read(ElfFile &file, const std::string &filename)
auto &sym = symTab[index];
auto symType = sym.info & 0xf;
if (symType == elf::STT_NOTYPE && sym.value == 0) {
if (rela.offset < DataAddress) {
std::cout << "Unexpected symbol referenced in relocation section " << name << std::endl;
return false;
}
} else if (symType == elf::STT_SECTION && sym.value == CodeAddress) {
if (symType == elf::STT_SECTION && sym.value == CodeAddress) {
if (rela.offset < CodeAddress || rela.offset >= DataAddress) {
std::cout << "Unexpected symbol referenced in relocation section " << name << std::endl;
return false;
}
} else {
std::cout << "Unexpected symbol referenced in relocation section " << name << std::endl;
return false;
}
auto addend = static_cast<uint32_t>(rela.addend);
@ -450,8 +442,12 @@ read(ElfFile &file, const std::string &filename)
relocation->symbol = findSymbol(file, DataAddress);
relocation->addend = addend - DataAddress;
} else {
std::cout << "Unexpected addend " << std::hex << addend << " referenced in relocation section " << name << std::endl;
return false;
// If we can't find a proper symbol, write the addend in and hope for the best
auto ptr = getLoaderDataPtr<uint32_t>(inSections, rela.offset);
*ptr = addend;
std::cout << "Unexpected addend " << std::hex << addend << " referenced in relocation section " << name << ", continuing." << std::endl;
continue;
}
relocation->target = rela.offset;
@ -612,13 +608,11 @@ write(ElfFile &file, const std::string &filename)
out->header.link = 0;
out->header.info = 0;
if (section->type == elf::SHT_NOBITS) {
out->header.addralign = 256;
} else if (section->address == DataAddress) {
if (section->address == DataAddress) {
out->header.addralign = 4096;
out->header.flags |= elf::SHF_WRITE; // .rodata needs to be writable?
} else {
out->header.addralign = 32;
out->header.addralign = 256;
}
out->header.entsize = 0;