summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Gamari <ben@smart-cactus.org>2019-05-28 09:43:36 -0400
committerBen Gamari <ben@smart-cactus.org>2019-05-28 09:45:39 -0400
commitb6184be96c647a8326ca299f67b52a575e35db8e (patch)
treec2e96f671599b0b0ce64d7e8a4f4380bd3ca815a
parent2d0cf6252957b8980d89481ecd0b79891da4b14b (diff)
downloadhaskell-wip/T16701.tar.gz
rts: Handle zero-sized mappings in MachO linkerwip/T16701
As noted in #16701, it is possible that we will find that an object has no segments needing to be mapped. Previously this would result in mmap being called for a zero-length mapping, which would fail. We now simply skip the mmap call in this case; the rest of the logic just works.
-rw-r--r--rts/linker/MachO.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/rts/linker/MachO.c b/rts/linker/MachO.c
index 21e46a30d2..9516eac1f2 100644
--- a/rts/linker/MachO.c
+++ b/rts/linker/MachO.c
@@ -1122,8 +1122,12 @@ ocBuildSegments_MachO(ObjectCode *oc)
n_activeSegments++;
}
- mem = mmapForLinker(size_compound, MAP_ANON, -1, 0);
- if (NULL == mem) return 0;
+ // N.B. it's possible that there is nothing mappable in an object. In this
+ // case we avoid the mmap call since it would fail. See #16701.
+ if (size_compound > 0) {
+ mem = mmapForLinker(size_compound, MAP_ANON, -1, 0);
+ if (NULL == mem) return 0;
+ }
IF_DEBUG(linker, debugBelch("ocBuildSegments: allocating %d segments\n", n_activeSegments));
segments = (Segment*)stgCallocBytes(n_activeSegments, sizeof(Segment),