]> gitweb @ CieloNegro.org - pkgsrc-ghc.git/blob - patches/patch-ac
7.0.1 for powerpc-apple-darwin (but crashes on --interactive)
[pkgsrc-ghc.git] / patches / patch-ac
1 $NetBSD$
2
3 --- rts/Linker.c.orig   2010-11-12 18:10:05.000000000 +0000
4 +++ rts/Linker.c
5 @@ -69,7 +69,15 @@
6  #include <sys/wait.h>
7  #endif
8  
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.
18 + */
19  #define USE_MMAP
20  #include <fcntl.h>
21  #include <sys/mman.h>
22 @@ -1684,6 +1692,9 @@ loadArchive( char *path )
23     size_t fileSize;
24     int isObject;
25     char tmp[12];
26 +#if !defined(USE_MMAP) && defined(darwin_HOST_OS)
27 +   int misalignment;
28 +#endif
29  
30     IF_DEBUG(linker, debugBelch("loadArchive `%s'\n", path));
31  
32 @@ -1763,6 +1774,7 @@ loadArchive( char *path )
33         if (isObject) {
34             char *archiveMemberName;
35  
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
42                do better here. */
43             image = mmapForLinker(imageSize, MAP_ANONYMOUS, -1);
44 +#elif defined(darwin_HOST_OS)
45 +           // See loadObj()
46 +           misalignment = machoGetMisalignment(f);
47 +           image = stgMallocBytes(imageSize + misalignment, "loadArchive(file)");
48 +           image += misalignment;
49 +#else
50 +           image = stgMallocBytes(imageSize, "loadArchive(file)");
51 +#endif
52             n = fread ( image, 1, imageSize, f );
53             if (n != imageSize)
54 -               barf("loadObj: error whilst reading `%s'", path);
55 +               barf("loadArchive: error whilst reading `%s'", path);
56  
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
61  #ifndef USE_MMAP
62  #ifdef darwin_HOST_OS
63 -                    , 0
64 +                    , misalignment
65  #endif
66  #endif
67                      );
68 @@ -1841,7 +1861,11 @@ loadObj( char *path )
69     int fd;
70  #else
71     FILE *f;
72 +#  if defined(darwin_HOST_OS)
73 +   int misalignment;
74 +#  endif
75  #endif
76 +
77     IF_DEBUG(linker, debugBelch("loadObj %s\n", path));
78  
79     initLinker();
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;
87 -#  else
88 -   image = stgMallocBytes(fileSize, "loadObj(image)");
89 -#  endif
90 +    misalignment = machoGetMisalignment(f);
91 +    image = stgMallocBytes(fileSize + misalignment, "loadObj(image)");
92 +    image += misalignment;
93 +#   else
94 +    image = stgMallocBytes(fileSize, "loadObj(image)");
95 +#   endif
96  
97     {
98         int n;
99 @@ -2203,6 +2227,12 @@ static int ocAllocateSymbolExtras( Objec
100       */
101      if( m > n ) // we need to allocate more pages
102      {
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));
108 +#endif
109          oc->symbol_extras = mmapForLinker(sizeof(SymbolExtra) * count, 
110                                            MAP_ANONYMOUS, -1);
111      }
112 @@ -5211,20 +5241,23 @@ static int machoGetMisalignment( FILE * 
113      struct mach_header header;
114      int misalignment;
115      
116 -    fread(&header, sizeof(header), 1, f);
117 -    rewind(f);
118 +    {
119 +        int n = fread(&header, sizeof(header), 1, f);
120 +        if (n != 1) {
121 +            barf("machoGetMisalignment: can't read the Mach-O header");
122 +        }
123 +    }
124 +    fseek(f, -sizeof(header), SEEK_CUR);
125  
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);
130 -        return 0;
131 +        barf("Bad magic. Expected: %08x, got: %08x.",
132 +             MH_MAGIC_64, header.magic);
133      }
134  #else
135      if(header.magic != MH_MAGIC) {
136 -        errorBelch("Bad magic. Expected: %08x, got: %08x.\n",
137 -                   MH_MAGIC, header->magic);
138 -        return 0;
139 +        barf("Bad magic. Expected: %08x, got: %08x.",
140 +             MH_MAGIC, header.magic);
141      }
142  #endif
143