summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Gamari <ben@smart-cactus.org>2019-06-08 13:28:19 -0400
committerBen Gamari <ben@smart-cactus.org>2019-06-12 08:45:15 -0400
commit2e8be92b454883dcba5d68e8e56c56c69d17bf0e (patch)
treea6731e54371d7190265e5025339f1fa6f72c34fc
parente628c7be84ba59c947d51053599831c7df9a5492 (diff)
downloadhaskell-2e8be92b454883dcba5d68e8e56c56c69d17bf0e.tar.gz
rts/linker: Only mprotect GOT after it is filledwip/backport-MR1137
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. (cherry picked from commit 217e6db4af6752b13c586d4e8925a4a9a2f47245)
-rw-r--r--rts/linker/elf_got.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/rts/linker/elf_got.c b/rts/linker/elf_got.c
index ee73a4a4da..9be2490a17 100644
--- a/rts/linker/elf_got.c
+++ b/rts/linker/elf_got.c
@@ -64,8 +64,6 @@ makeGot(ObjectCode * oc) {
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;
@@ -115,6 +113,11 @@ fillGot(ObjectCode * oc) {
}
}
}
+
+ // 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;
}