Commit e628c7be authored by Ben Gamari's avatar Ben Gamari 🐢
Browse files

rts/linker: Make elf_got.c a bit more legible

(cherry picked from commit bbc752c5)
parent 5e6f261a
......@@ -52,11 +52,13 @@ makeGot(ObjectCode * oc) {
errorBelch("MAP_FAILED. errno=%d", errno);
return EXIT_FAILURE;
}
oc->info->got_start = (void*)mem;
/* update got_addr */
size_t slot = 0;
for(ElfSymbolTable *symTab = oc->info->symbolTables;
symTab != NULL; symTab = symTab->next)
symTab != NULL; symTab = symTab->next) {
for(size_t i=0; i < symTab->n_symbols; i++)
if(needGotSlot(symTab->symbols[i].elf_sym))
symTab->symbols[i].got_addr
......@@ -74,9 +76,12 @@ fillGot(ObjectCode * oc) {
/* fill the GOT table */
for(ElfSymbolTable *symTab = oc->info->symbolTables;
symTab != NULL; symTab = symTab->next) {
for(size_t i=0; i < symTab->n_symbols; i++) {
ElfSymbol * symbol = &symTab->symbols[i];
if(needGotSlot(symbol->elf_sym)) {
/* no type are undefined symbols */
if( STT_NOTYPE == ELF_ST_TYPE(symbol->elf_sym->st_info)
|| STB_WEAK == ELF_ST_BIND(symbol->elf_sym->st_info)) {
......@@ -93,22 +98,26 @@ fillGot(ObjectCode * oc) {
} /* else it was defined somewhere in the same object, and
* we should have the address already.
*/
if(0x0 == symbol->addr) {
errorBelch(
"Something went wrong! Symbol %s has null address.\n",
symbol->name);
return EXIT_FAILURE;
}
if(0x0 == symbol->got_addr) {
errorBelch("Not good either!");
return EXIT_FAILURE;
}
*(void**)symbol->got_addr = symbol->addr;
}
}
}
return EXIT_SUCCESS;
}
bool
verifyGot(ObjectCode * oc) {
for(ElfSymbolTable *symTab = oc->info->symbolTables;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment