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

View File

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