3 --- rts/Linker.c.orig 2010-11-12 18:10:05.000000000 +0000
9 -#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)
10 +#if defined(linux_HOST_OS ) || defined(freebsd_HOST_OS) || \
11 + defined(dragonfly_HOST_OS) || defined(netbsd_HOST_OS ) || \
12 + defined(openbsd_HOST_OS ) || \
13 + ( defined(darwin_HOST_OS ) && !defined(powerpc_HOST_ARCH) )
14 +/* Don't use mmap on powerpc-apple-darwin as mmap doesn't support
15 + * reallocating but we need to allocate jump islands just after each
16 + * object images. Otherwise relative branches to jump islands can fail
17 + * due to 24-bits displacement overflow.
22 @@ -1684,6 +1692,9 @@ loadArchive( char *path )
26 +#if !defined(USE_MMAP) && defined(darwin_HOST_OS)
30 IF_DEBUG(linker, debugBelch("loadArchive `%s'\n", path));
32 @@ -1763,6 +1774,7 @@ loadArchive( char *path )
34 char *archiveMemberName;
36 +#if defined(USE_MMAP)
37 /* We can't mmap from the archive directly, as object
38 files need to be 8-byte aligned but files in .ar
39 archives are 2-byte aligned, and if we malloc the
40 @@ -1770,9 +1782,17 @@ loadArchive( char *path )
41 mmap some anonymous memory and use that. We could
43 image = mmapForLinker(imageSize, MAP_ANONYMOUS, -1);
44 +#elif defined(darwin_HOST_OS)
46 + misalignment = machoGetMisalignment(f);
47 + image = stgMallocBytes(imageSize + misalignment, "loadArchive(file)");
48 + image += misalignment;
50 + image = stgMallocBytes(imageSize, "loadArchive(file)");
52 n = fread ( image, 1, imageSize, f );
54 - barf("loadObj: error whilst reading `%s'", path);
55 + barf("loadArchive: error whilst reading `%s'", path);
57 archiveMemberName = stgMallocBytes(strlen(path) + fileNameSize + 3, "loadArchive(file)");
58 sprintf(archiveMemberName, "%s(%.*s)", path, (int)fileNameSize, file);
59 @@ -1780,7 +1800,7 @@ loadArchive( char *path )
60 oc = mkOc(path, image, imageSize, archiveMemberName
68 @@ -1841,7 +1861,11 @@ loadObj( char *path )
72 +# if defined(darwin_HOST_OS)
77 IF_DEBUG(linker, debugBelch("loadObj %s\n", path));
80 @@ -1914,12 +1938,12 @@ loadObj( char *path )
81 // We calculate the correct alignment from the header before
82 // reading the file, and then we misalign image on purpose so
83 // that the actual sections end up aligned again.
84 - misalignment = machoGetMisalignment(f);
85 - image = stgMallocBytes(fileSize + misalignment, "loadObj(image)");
86 - image += misalignment;
88 - image = stgMallocBytes(fileSize, "loadObj(image)");
90 + misalignment = machoGetMisalignment(f);
91 + image = stgMallocBytes(fileSize + misalignment, "loadObj(image)");
92 + image += misalignment;
94 + image = stgMallocBytes(fileSize, "loadObj(image)");
99 @@ -2203,6 +2227,12 @@ static int ocAllocateSymbolExtras( Objec
101 if( m > n ) // we need to allocate more pages
103 +#if !defined(x86_64_HOST_ARCH)
104 + errorBelch("%s: WARNING: Allocating jump islands separately from "
105 + "the object image itself. This may interfere with "
106 + "relative branches to them.",
107 + OC_INFORMATIVE_FILENAME(oc));
109 oc->symbol_extras = mmapForLinker(sizeof(SymbolExtra) * count,
112 @@ -5211,20 +5241,23 @@ static int machoGetMisalignment( FILE *
113 struct mach_header header;
116 - fread(&header, sizeof(header), 1, f);
119 + int n = fread(&header, sizeof(header), 1, f);
121 + barf("machoGetMisalignment: can't read the Mach-O header");
124 + fseek(f, -sizeof(header), SEEK_CUR);
126 #if x86_64_HOST_ARCH || powerpc64_HOST_ARCH
127 if(header.magic != MH_MAGIC_64) {
128 - errorBelch("Bad magic. Expected: %08x, got: %08x.\n",
129 - MH_MAGIC_64, header->magic);
131 + barf("Bad magic. Expected: %08x, got: %08x.",
132 + MH_MAGIC_64, header.magic);
135 if(header.magic != MH_MAGIC) {
136 - errorBelch("Bad magic. Expected: %08x, got: %08x.\n",
137 - MH_MAGIC, header->magic);
139 + barf("Bad magic. Expected: %08x, got: %08x.",
140 + MH_MAGIC, header.magic);