From 38ae220cd6f198e51e4a9904ae13e269dc80009a Mon Sep 17 00:00:00 2001 From: James Benton Date: Wed, 30 May 2018 22:52:20 +0100 Subject: [PATCH] elf2rpl: Simplify fixLoaderVirtualAddresses to only move STRTAB + SYMTAB. Until we can get ld to give these alloc flags we will always need this. --- tools/elf2rpl/main.cpp | 29 +++++++---------------------- 1 file changed, 7 insertions(+), 22 deletions(-) diff --git a/tools/elf2rpl/main.cpp b/tools/elf2rpl/main.cpp index 741fc599..d5514942 100644 --- a/tools/elf2rpl/main.cpp +++ b/tools/elf2rpl/main.cpp @@ -469,41 +469,26 @@ relocateSection(ElfFile &file, * * Linker script won't put symtab & strtab sections in our loader address, so * we must fix that. - * - * Expected order: - * .fexports > .dexports > .symtab > .strtab > .shstrtab > {.fimport, .dimport} */ static bool fixLoaderVirtualAddresses(ElfFile &file) { - auto addr = LoadBaseAddress; - - for (auto i = 0u; i < file.sections.size(); ++i) { - auto §ion = file.sections[i]; - if (section->header.type == elf::SHT_RPL_EXPORTS) { - relocateSection(file, *section, i, - align_up(addr, section->header.addralign)); - addr += section->data.size(); + auto loadMax = LoadBaseAddress; + for (auto §ion : file.sections) { + if (section->header.addr >= loadMax) { + loadMax = section->header.addr + section->data.size(); } } + // Relocate .symtab and .strtab to be in loader memory for (auto i = 0u; i < file.sections.size(); ++i) { auto §ion = file.sections[i]; if (section->header.type == elf::SHT_SYMTAB || section->header.type == elf::SHT_STRTAB) { relocateSection(file, *section, i, - align_up(addr, section->header.addralign)); + align_up(loadMax, section->header.addralign)); section->header.flags |= elf::SHF_ALLOC; - addr += section->data.size(); - } - } - - for (auto i = 0u; i < file.sections.size(); ++i) { - auto §ion = file.sections[i]; - if (section->header.type == elf::SHT_RPL_IMPORTS) { - relocateSection(file, *section, i, - align_up(addr, section->header.addralign)); - addr += section->data.size(); + loadMax += section->data.size(); } }