summaryrefslogtreecommitdiff
path: root/rts/Linker.c
diff options
context:
space:
mode:
authorErik de Castro Lopo <erikd@mega-nerd.com>2016-04-17 14:44:38 +0200
committerBen Gamari <ben@smart-cactus.org>2016-04-17 14:44:59 +0200
commit177aec697b3d7eedcc4905d9ef783feafb4ba2a1 (patch)
tree6568023d03f3facb18116f5cf315b9b9f6838586 /rts/Linker.c
parent36a0b6dc27ae0ee2022afbef5d3cd49dfde9e82b (diff)
downloadhaskell-177aec697b3d7eedcc4905d9ef783feafb4ba2a1.tar.gz
Linker: Clean up #if USE_MMAP usage
Test Plan: - Run tests on x86_64/linux, x86_64/darwin and powerpc/linux - Cross compile rts/Linker.c with the i686-w64-mingw32-gcc and x86_64-w64-mingw32-gcc Linux to Windows cross-compilers. Reviewers: hvr, austin, thomie, bgamari, simonmar, Phyx Reviewed By: Phyx Subscribers: thomie Differential Revision: https://phabricator.haskell.org/D1437
Diffstat (limited to 'rts/Linker.c')
-rw-r--r--rts/Linker.c110
1 files changed, 52 insertions, 58 deletions
diff --git a/rts/Linker.c b/rts/Linker.c
index d670f1d175..ef7baf92b0 100644
--- a/rts/Linker.c
+++ b/rts/Linker.c
@@ -1880,15 +1880,7 @@ static void freeOcStablePtrs (ObjectCode *oc)
static void
freePreloadObjectFile (ObjectCode *oc)
{
-#if USE_MMAP
-
- if (oc->imageMapped) {
- munmap(oc->image, oc->fileSize);
- } else {
- stgFree(oc->image);
- }
-
-#elif defined(mingw32_HOST_OS)
+#if defined(mingw32_HOST_OS)
VirtualFree(oc->image - PEi386_IMAGE_OFFSET, 0, MEM_RELEASE);
@@ -1903,7 +1895,12 @@ freePreloadObjectFile (ObjectCode *oc)
#else
- stgFree(oc->image);
+ if (USE_MMAP && oc->imageMapped) {
+ munmap(oc->image, oc->fileSize);
+ }
+ else {
+ stgFree(oc->image);
+ }
#endif
@@ -1956,14 +1953,15 @@ void freeObjectCode (ObjectCode *oc)
/* Free symbol_extras. On x86_64 Windows, symbol_extras are allocated
* alongside the image, so we don't need to free. */
#if NEED_SYMBOL_EXTRAS && (!defined(x86_64_HOST_ARCH) || !defined(mingw32_HOST_OS))
-#if USE_MMAP
- if (!USE_CONTIGUOUS_MMAP && oc->symbol_extras != NULL)
- {
- m32_free(oc->symbol_extras, sizeof(SymbolExtra) * oc->n_symbol_extras);
+ if (USE_MMAP) {
+ if (!USE_CONTIGUOUS_MMAP && oc->symbol_extras != NULL) {
+ m32_free(oc->symbol_extras,
+ sizeof(SymbolExtra) * oc->n_symbol_extras);
+ }
+ }
+ else {
+ stgFree(oc->symbol_extras);
}
-#else // !USE_MMAP
- stgFree(oc->symbol_extras);
-#endif
#endif
stgFree(oc->fileName);
@@ -2391,14 +2389,15 @@ static HsInt loadArchive_ (pathchar *path)
#endif
memberSize);
#elif defined(darwin_HOST_OS)
-#if USE_MMAP
- image = mmapForLinker(memberSize, MAP_ANONYMOUS, -1, 0);
-#else
- /* See loadObj() */
- misalignment = machoGetMisalignment(f);
- image = stgMallocBytes(memberSize + misalignment, "loadArchive(image)");
- image += misalignment;
-#endif // USE_MMAP
+ if (USE_MMAP)
+ image = mmapForLinker(memberSize, MAP_ANONYMOUS, -1, 0);
+ else {
+ /* See loadObj() */
+ misalignment = machoGetMisalignment(f);
+ image = stgMallocBytes(memberSize + misalignment,
+ "loadArchive(image)");
+ image += misalignment;
+ }
#else // not windows or darwin
image = stgMallocBytes(memberSize, "loadArchive(image)");
@@ -3060,16 +3059,13 @@ static int ocAllocateSymbolExtras( ObjectCode* oc, int count, int first )
{
StgWord n;
-#if USE_MMAP
- if (USE_CONTIGUOUS_MMAP)
- {
+ if (USE_MMAP && USE_CONTIGUOUS_MMAP) {
n = roundUpToPage(oc->fileSize);
/* Keep image and symbol_extras contiguous */
void *new = mmapForLinker(n + (sizeof(SymbolExtra) * count),
MAP_ANONYMOUS, -1, 0);
- if (new)
- {
+ if (new) {
memcpy(new, oc->image, oc->fileSize);
if (oc->imageMapped) {
munmap(oc->image, n);
@@ -3084,32 +3080,28 @@ static int ocAllocateSymbolExtras( ObjectCode* oc, int count, int first )
return 0;
}
}
- else
-#endif
+ else if( count > 0 ) {
+ if (USE_MMAP) {
+ n = roundUpToPage(oc->fileSize);
- if( count > 0 )
- {
-#if USE_MMAP
- n = roundUpToPage(oc->fileSize);
-
- oc->symbol_extras = m32_alloc(&allocator,
+ oc->symbol_extras = m32_alloc(&allocator,
sizeof(SymbolExtra) * count, 8);
- if (oc->symbol_extras == NULL) return 0;
-#else
- // round up to the nearest 4
- int aligned = (oc->fileSize + 3) & ~3;
-
- int misalignment = oc->misalignment;
+ if (oc->symbol_extras == NULL) return 0;
+ }
+ else {
+ // round up to the nearest 4
+ int aligned = (oc->fileSize + 3) & ~3;
+ int misalignment = oc->misalignment;
- oc->image -= misalignment;
- oc->image = stgReallocBytes( oc->image,
+ oc->image -= misalignment;
+ oc->image = stgReallocBytes( oc->image,
misalignment +
aligned + sizeof (SymbolExtra) * count,
"ocAllocateSymbolExtras" );
- oc->image += misalignment;
+ oc->image += misalignment;
- oc->symbol_extras = (SymbolExtra *) (oc->image + aligned);
-#endif /* USE_MMAP */
+ oc->symbol_extras = (SymbolExtra *) (oc->image + aligned);
+ }
}
if (oc->symbol_extras != NULL) {
@@ -7010,16 +7002,18 @@ ocGetNames_MachO(ObjectCode* oc)
continue;
}
- if((sections[i].flags & SECTION_TYPE) == S_ZEROFILL)
- {
-#if USE_MMAP
- char * zeroFillArea = mmapForLinker(sections[i].size, MAP_ANONYMOUS, -1, 0);
- if (zeroFillArea == NULL) return 0;
- memset(zeroFillArea, 0, sections[i].size);
-#else
- char * zeroFillArea = stgCallocBytes(1,sections[i].size,
+ if((sections[i].flags & SECTION_TYPE) == S_ZEROFILL) {
+ char * zeroFillArea;
+ if (USE_MMAP) {
+ zeroFillArea = mmapForLinker(sections[i].size, MAP_ANONYMOUS,
+ -1, 0);
+ if (zeroFillArea == NULL) return 0;
+ memset(zeroFillArea, 0, sections[i].size);
+ }
+ else {
+ zeroFillArea = stgCallocBytes(1,sections[i].size,
"ocGetNames_MachO(common symbols)");
-#endif
+ }
sections[i].offset = zeroFillArea - image;
}