X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=rts%2FLinker.c;h=878c86b60aa4fd58dce8a626b0b684ba3df6343a;hb=05859437c5dfd2967418e3267f7cfc37e4f8952d;hp=c92ede50ebf8806fde0fb9273de3b1048af3207d;hpb=b2adc5010f7a072bc81d374ab3009405e1c5c1b8;p=ghc-hetmet.git diff --git a/rts/Linker.c b/rts/Linker.c index c92ede5..878c86b 100644 --- a/rts/Linker.c +++ b/rts/Linker.c @@ -69,7 +69,15 @@ #include #endif -#if defined(linux_HOST_OS) || defined(freebsd_HOST_OS) || defined(dragonfly_HOST_OS) || defined(netbsd_HOST_OS) || defined(openbsd_HOST_OS) || defined(darwin_HOST_OS) +#if defined(linux_HOST_OS ) || defined(freebsd_HOST_OS) || \ + defined(dragonfly_HOST_OS) || defined(netbsd_HOST_OS ) || \ + defined(openbsd_HOST_OS ) || \ + ( defined(darwin_HOST_OS ) && !defined(powerpc_HOST_ARCH) ) +/* Don't use mmap on powerpc-apple-darwin as mmap doesn't support + * reallocating but we need to allocate jump islands just after each + * object images. Otherwise relative branches to jump islands can fail + * due to 24-bits displacement overflow. + */ #define USE_MMAP #include #include @@ -261,6 +269,7 @@ typedef struct _RtsSymbolVal { SymI_HasProto(unlockFile) \ SymI_HasProto(signal_handlers) \ SymI_HasProto(stg_sig_install) \ + SymI_HasProto(rtsTimerSignal) \ SymI_NeedsProto(nocldstop) #endif @@ -880,7 +889,7 @@ typedef struct _RtsSymbolVal { SymI_HasProto(rts_unlock) \ SymI_HasProto(rts_unsafeGetMyCapability) \ SymI_HasProto(rtsSupportsBoundThreads) \ - SymI_HasProto(rts_isProfiled) \ + SymI_HasProto(rts_isProfiled) \ SymI_HasProto(setProgArgv) \ SymI_HasProto(startupHaskell) \ SymI_HasProto(shutdownHaskell) \ @@ -1685,6 +1694,9 @@ loadArchive( char *path ) char tmp[12]; char *gnuFileIndex; int gnuFileIndexSize; +#if !defined(USE_MMAP) && defined(darwin_HOST_OS) + int misalignment; +#endif IF_DEBUG(linker, debugBelch("loadArchive: Loading archive `%s'\n", path)); @@ -1854,8 +1866,13 @@ loadArchive( char *path ) we use malloc then we can be given memory above 2^32. In the mmap case we're probably wasting lots of space; we could do better. */ -#ifdef USE_MMAP +#if defined(USE_MMAP) image = mmapForLinker(memberSize, MAP_ANONYMOUS, -1); +#elif defined(darwin_HOST_OS) + /* See loadObj() */ + misalignment = machoGetMisalignment(f); + image = stgMallocBytes(memberSize + misalignment, "loadArchive(image)"); + image += misalignment; #else image = stgMallocBytes(memberSize, "loadArchive(image)"); #endif @@ -1872,7 +1889,7 @@ loadArchive( char *path ) oc = mkOc(path, image, memberSize, archiveMemberName #ifndef USE_MMAP #ifdef darwin_HOST_OS - , 0 + , misalignment #endif #endif ); @@ -1952,6 +1969,9 @@ loadObj( char *path ) int fd; #else FILE *f; +# if defined(darwin_HOST_OS) + int misalignment; +# endif #endif IF_DEBUG(linker, debugBelch("loadObj %s\n", path)); @@ -2393,13 +2413,12 @@ static SymbolExtra* makeSymbolExtra( ObjectCode* oc, Because the PPC has split data/instruction caches, we have to do that whenever we modify code at runtime. */ - -static void ocFlushInstructionCache( ObjectCode *oc ) +static void ocFlushInstructionCacheFrom(void* begin, size_t length) { - int n = (oc->fileSize + sizeof( SymbolExtra ) * oc->n_symbol_extras + 3) / 4; - unsigned long *p = (unsigned long *) oc->image; + size_t n = (length + 3) / 4; + unsigned long* p = begin; - while( n-- ) + while (n--) { __asm__ volatile ( "dcbf 0,%0\n\t" "sync\n\t" @@ -2413,6 +2432,14 @@ static void ocFlushInstructionCache( ObjectCode *oc ) "isync" ); } +static void ocFlushInstructionCache( ObjectCode *oc ) +{ + /* The main object code */ + ocFlushInstructionCacheFrom(oc->image + oc->misalignment, oc->fileSize); + + /* Jump Islands */ + ocFlushInstructionCacheFrom(oc->symbol_extras, sizeof(SymbolExtra) * oc->n_symbol_extras); +} #endif /* -------------------------------------------------------------------------- @@ -5321,21 +5348,24 @@ static int machoGetMisalignment( FILE * f ) { struct mach_header header; int misalignment; - - fread(&header, sizeof(header), 1, f); - rewind(f); + + { + int n = fread(&header, sizeof(header), 1, f); + if (n != 1) { + barf("machoGetMisalignment: can't read the Mach-O header"); + } + } + fseek(f, -sizeof(header), SEEK_CUR); #if x86_64_HOST_ARCH || powerpc64_HOST_ARCH if(header.magic != MH_MAGIC_64) { - errorBelch("Bad magic. Expected: %08x, got: %08x.\n", - MH_MAGIC_64, header->magic); - return 0; + barf("Bad magic. Expected: %08x, got: %08x.", + MH_MAGIC_64, header.magic); } #else if(header.magic != MH_MAGIC) { - errorBelch("Bad magic. Expected: %08x, got: %08x.\n", - MH_MAGIC, header->magic); - return 0; + barf("Bad magic. Expected: %08x, got: %08x.", + MH_MAGIC, header.magic); } #endif