[Git][ghc/ghc][master] 2 commits: rts/linker: Make elf_got.c a bit more legible

Marge Bot gitlab at gitlab.haskell.org
Wed Jun 12 11:36:40 UTC 2019



 Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC


Commits:
bbc752c5 by Ben Gamari at 2019-06-12T11:36:36Z
rts/linker: Make elf_got.c a bit more legible

- - - - -
217e6db4 by Ben Gamari at 2019-06-12T11:36:36Z
rts/linker: Only mprotect GOT after it is filled

This fixes a regression, introduced by 67c422ca, where we mprotect'd the
global offset table (GOT) region to PROT_READ before we had finished
filling it, resulting in a linker crash.

Fixes #16779.

- - - - -


1 changed file:

- rts/linker/elf_got.c


Changes:

=====================================
rts/linker/elf_got.c
=====================================
@@ -52,18 +52,18 @@ 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
                             = (uint8_t *)oc->info->got_start
                               + (slot++ * sizeof(void*));
-        if(mprotect(mem, oc->info->got_size, PROT_READ) != 0) {
-            sysErrorBelch("unable to protect memory");
         }
     }
     return EXIT_SUCCESS;
@@ -74,9 +74,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 +96,31 @@ 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;
             }
         }
     }
+
+    // We are done initializing the GOT; freeze it.
+    if(mprotect(oc->info->got_start, oc->info->got_size, PROT_READ) != 0) {
+        sysErrorBelch("unable to protect memory");
+    }
     return EXIT_SUCCESS;
 }
+
 bool
 verifyGot(ObjectCode * oc) {
     for(ElfSymbolTable *symTab = oc->info->symbolTables;



View it on GitLab: https://gitlab.haskell.org/ghc/ghc/compare/c05ca251620ff2589f21192208a1e500285eb5c3...217e6db4af6752b13c586d4e8925a4a9a2f47245

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/compare/c05ca251620ff2589f21192208a1e500285eb5c3...217e6db4af6752b13c586d4e8925a4a9a2f47245
You're receiving this email because of your account on gitlab.haskell.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20190612/003a3239/attachment-0001.html>


More information about the ghc-commits mailing list