summaryrefslogtreecommitdiff
path: root/rts/linker/Elf.c
diff options
context:
space:
mode:
authorBen Gamari <ben@smart-cactus.org>2020-11-23 14:35:56 -0500
committerMarge Bot <ben+marge-bot@smart-cactus.org>2020-12-01 19:58:17 -0500
commitadd0aeaefd4d823d31315564e924ce8c018fb69e (patch)
tree4fc39929885b53bd774d7a8eedde70917cd37bfe /rts/linker/Elf.c
parentd66660ba4c491f9937a1a959b009d90f08a4fbee (diff)
downloadhaskell-add0aeaefd4d823d31315564e924ce8c018fb69e.tar.gz
rts: Introduce mmapAnonForLinker
Previously most of the uses of mmapForLinker were mapping anonymous memory, resulting in a great deal of unnecessary repetition. Factor this out into a new helper. Also fixes a few places where error checking was missing or suboptimal.
Diffstat (limited to 'rts/linker/Elf.c')
-rw-r--r--rts/linker/Elf.c19
1 files changed, 11 insertions, 8 deletions
diff --git a/rts/linker/Elf.c b/rts/linker/Elf.c
index b70eab0916..050de23dac 100644
--- a/rts/linker/Elf.c
+++ b/rts/linker/Elf.c
@@ -714,7 +714,11 @@ ocGetNames_ELF ( ObjectCode* oc )
* address might be out of range for sections that are mmaped.
*/
alloc = SECTION_MMAP;
- start = mmapForLinker(size, PROT_READ | PROT_WRITE, MAP_ANONYMOUS, -1, 0);
+ start = mmapAnonForLinker(size);
+ if (start == NULL) {
+ barf("failed to mmap memory for bss. "
+ "errno = %d", errno);
+ }
mapped_start = start;
mapped_offset = 0;
mapped_size = roundUpToPage(size);
@@ -756,9 +760,9 @@ ocGetNames_ELF ( ObjectCode* oc )
unsigned nstubs = numberOfStubsForSection(oc, i);
unsigned stub_space = STUB_SIZE * nstubs;
- void * mem = mmapForLinker(size+stub_space, PROT_READ | PROT_WRITE, MAP_ANON, -1, 0);
+ void * mem = mmapAnonForLinker(size+stub_space);
- if( mem == MAP_FAILED ) {
+ if( mem == NULL ) {
barf("failed to mmap allocated memory to load section %d. "
"errno = %d", i, errno);
}
@@ -865,11 +869,10 @@ ocGetNames_ELF ( ObjectCode* oc )
}
void * common_mem = NULL;
if(common_size > 0) {
- common_mem = mmapForLinker(common_size,
- PROT_READ | PROT_WRITE,
- MAP_ANON | MAP_PRIVATE,
- -1, 0);
- CHECK(common_mem != NULL);
+ common_mem = mmapAnonForLinker(common_size);
+ if (common_mem == NULL) {
+ barf("ocGetNames_ELF: Failed to allocate memory for SHN_COMMONs");
+ }
}
//TODO: we ignore local symbols anyway right? So we can use the