From cfc30307a3cb7ba281e0c9964b733eb9f060dc09 Mon Sep 17 00:00:00 2001 From: desrt Date: Thu, 17 Feb 2005 16:58:21 +0000 Subject: [PATCH] [project @ 2005-02-17 16:58:18 by desrt] LinkerInternals.h: all platforms: changed 'image' pointer in ObjectCode from (void *) to (char *). Linker.c: linux/ppc: added mremap() support to unbreak the build when USE_MMAP is defined on linux/ppc (as it now is.) --- ghc/rts/Linker.c | 46 ++++++++++++++++++++++++++++++++++++++------- ghc/rts/LinkerInternals.h | 2 +- 2 files changed, 40 insertions(+), 8 deletions(-) diff --git a/ghc/rts/Linker.c b/ghc/rts/Linker.c index 8aed286..7b9df7f 100644 --- a/ghc/rts/Linker.c +++ b/ghc/rts/Linker.c @@ -10,7 +10,9 @@ #include "PosixSource.h" #endif -// Linux needs _GNU_SOURCE to get RTLD_DEFAULT from . +/* Linux needs _GNU_SOURCE to get RTLD_DEFAULT from and + MREMAP_MAYMOVE from . + */ #ifdef __linux__ #define _GNU_SOURCE #endif @@ -1307,21 +1309,51 @@ static void addSection ( ObjectCode* oc, SectionKind kind, static int ocAllocateJumpIslands( ObjectCode* oc, int count, int first ) { +#ifdef USE_MMAP + int pagesize, n, m; +#endif int aligned; if( count > 0 ) { -#ifdef USE_MMAP - #error ocAllocateJumpIslands doesnt want USE_MMAP to be defined -#endif // round up to the nearest 4 aligned = (oc->fileSize + 3) & ~3; +#ifdef USE_MMAP + #ifndef linux_HOST_OS /* mremap is a linux extension */ + #error ocAllocateJumpIslands doesnt want USE_MMAP to be defined + #endif + + pagesize = getpagesize(); + n = ROUND_UP( oc->fileSize, pagesize ); + m = ROUND_UP( aligned + sizeof (ppcJumpIsland) * count, pagesize ); + + /* The effect of this mremap() call is only the ensure that we have + * a sufficient number of virtually contiguous pages. As returned from + * mremap, the pages past the end of the file are not backed. We give + * them a backing by using MAP_FIXED to map in anonymous pages. + */ + if( (oc->image = mremap( oc->image, n, m, MREMAP_MAYMOVE )) == MAP_FAILED ) + { + errorBelch( "Unable to mremap for Jump Islands\n" ); + return 0; + } + + if( mmap( oc->image + n, m - n, PROT_READ | PROT_WRITE | PROT_EXEC, + MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED, 0, 0 ) == MAP_FAILED ) + { + errorBelch( "Unable to mmap( MAP_FIXED ) for Jump Islands\n" ); + return 0; + } + +#else oc->image = stgReallocBytes( oc->image, - aligned + sizeof( ppcJumpIsland ) * count, + aligned + sizeof (ppcJumpIsland) * count, "ocAllocateJumpIslands" ); - oc->jump_islands = (ppcJumpIsland *) (((char *) oc->image) + aligned); - memset( oc->jump_islands, 0, sizeof( ppcJumpIsland ) * count ); +#endif /* USE_MMAP */ + + oc->jump_islands = (ppcJumpIsland *) (oc->image + aligned); + memset( oc->jump_islands, 0, sizeof (ppcJumpIsland) * count ); } else oc->jump_islands = NULL; diff --git a/ghc/rts/LinkerInternals.h b/ghc/rts/LinkerInternals.h index f1e2677..3f7653f 100644 --- a/ghc/rts/LinkerInternals.h +++ b/ghc/rts/LinkerInternals.h @@ -65,7 +65,7 @@ typedef struct _ObjectCode { int n_symbols; /* ptr to malloc'd lump of memory holding the obj file */ - void* image; + char* image; /* The section-kind entries for this object module. Linked list. */ -- 1.7.10.4