rts/linker: Make elf_got.c a bit more legible
authorBen Gamari <ben@smart-cactus.org>
Sat, 8 Jun 2019 17:28:08 +0000 (13:28 -0400)
committerMarge Bot <ben+marge-bot@smart-cactus.org>
Wed, 12 Jun 2019 11:36:36 +0000 (07:36 -0400)
rts/linker/elf_got.c

index 10ea25b..ee73a4a 100644 (file)
@@ -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;