Arm64: ghc_android.patch

File ghc_android.patch, 13.4 KB (added by hypoon, 4 years ago)

My (unsafe) patches to make GHC compile

Line 
1cd into directory, and then execute:
2"patch -p1 -i ../ghc_android.patch"
3diff -cr ghc-8.0.0-stock/compiler/llvmGen/LlvmCodeGen/Ppr.hs ghc-8.0.0.20160111/compiler/llvmGen/LlvmCodeGen/Ppr.hs
4*** ghc-8.0.0-stock/compiler/llvmGen/LlvmCodeGen/Ppr.hs 2015-12-28 09:42:43.000000000 -0500
5--- ghc-8.0.0.20160111/compiler/llvmGen/LlvmCodeGen/Ppr.hs      2016-01-22 22:25:49.806935441 -0500
6***************
7*** 65,70 ****
8--- 65,76 ----
9      Platform { platformArch = ArchX86, platformOS = OSiOS } ->
10          text "target datalayout = \"e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128-n8:16:32\""
11          $+$ text "target triple = \"i386-apple-darwin11\""
12+     Platform { platformArch = ArchARM64, platformOS = OSAndroid } ->
13+         text "target datalayout = \"e-m:e-i64:64-i128:128-n32:64-S128\""
14+         $+$ text "target triple = \"aarch64-unknown-linux-android\""
15+     Platform { platformArch = ArchARM64, platformOS = OSAndroid } ->
16+         text "target datalayout = \"e-m:e-i64:64-i128:128-n32:64-S128\""
17+         $+$ text "target triple = \"aarch64-none-linux-android\""
18      Platform { platformArch = ArchARM64, platformOS = OSiOS } ->
19          text "target datalayout = \"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-n32:64-S128\""
20          $+$ text "target triple = \"arm64-apple-ios7.0.0\""
21diff -cr ghc-8.0.0-stock/compiler/main/DriverPipeline.hs ghc-8.0.0.20160111/compiler/main/DriverPipeline.hs
22*** ghc-8.0.0-stock/compiler/main/DriverPipeline.hs     2016-01-08 06:27:17.000000000 -0500
23--- ghc-8.0.0.20160111/compiler/main/DriverPipeline.hs  2016-01-22 22:25:49.876933862 -0500
24***************
25*** 1817,1823 ****
26              let os = platformOS (targetPlatform dflags)
27              in if os == OSOsf3 then ["-lpthread", "-lexc"]
28                 else if os `elem` [OSMinGW32, OSFreeBSD, OSOpenBSD,
29!                                   OSNetBSD, OSHaiku, OSQNXNTO, OSiOS, OSDarwin]
30                 then []
31                 else ["-lpthread"]
32           | otherwise               = []
33--- 1817,1823 ----
34              let os = platformOS (targetPlatform dflags)
35              in if os == OSOsf3 then ["-lpthread", "-lexc"]
36                 else if os `elem` [OSMinGW32, OSFreeBSD, OSOpenBSD,
37!                                   OSNetBSD, OSHaiku, OSQNXNTO, OSiOS, OSDarwin, OSAndroid]
38                 then []
39                 else ["-lpthread"]
40           | otherwise               = []
41diff -cr ghc-8.0.0-stock/compiler/main/DynFlags.hs ghc-8.0.0.20160111/compiler/main/DynFlags.hs
42*** ghc-8.0.0-stock/compiler/main/DynFlags.hs   2016-01-09 14:59:20.000000000 -0500
43--- ghc-8.0.0.20160111/compiler/main/DynFlags.hs        2016-01-23 01:07:07.339028754 -0500
44***************
45*** 3323,3328 ****
46--- 3323,3329 ----
47  default_PIC platform =
48    case (platformOS platform, platformArch platform) of
49      (OSDarwin, ArchX86_64) -> [Opt_PIC]
50+     (OSAndroid, _) -> [Opt_PIC]
51      (OSOpenBSD, ArchX86_64) -> [Opt_PIC] -- Due to PIE support in
52                                           -- OpenBSD since 5.3 release
53                                           -- (1 May 2013) we need to
54***************
55*** 4412,4418 ****
56          in loop dflags' warn
57   | hscTarget dflags == HscLlvm &&
58     not ((arch == ArchX86_64) && (os == OSLinux || os == OSDarwin || os == OSFreeBSD)) &&
59!    not ((isARM arch) && (os == OSLinux)) &&
60     (gopt Opt_PIC dflags || WayDyn `elem` ways dflags)
61      = if cGhcWithNativeCodeGen == "YES"
62        then let dflags' = dflags { hscTarget = HscAsm }
63--- 4413,4419 ----
64          in loop dflags' warn
65   | hscTarget dflags == HscLlvm &&
66     not ((arch == ArchX86_64) && (os == OSLinux || os == OSDarwin || os == OSFreeBSD)) &&
67!    not (((isARM arch) && (os == OSLinux)) || ((isARM arch) && (os == OSAndroid))) &&
68     (gopt Opt_PIC dflags || WayDyn `elem` ways dflags)
69      = if cGhcWithNativeCodeGen == "YES"
70        then let dflags' = dflags { hscTarget = HscAsm }
71diff -cr ghc-8.0.0-stock/ghc.mk ghc-8.0.0.20160111/ghc.mk
72*** ghc-8.0.0-stock/ghc.mk      2016-01-08 06:27:17.000000000 -0500
73--- ghc-8.0.0.20160111/ghc.mk   2016-01-22 22:25:49.876933862 -0500
74***************
75*** 413,423 ****
76  # compiler already has installed (or up-to-date enough).
77 
78  PACKAGES_STAGE0 = binary Cabal/Cabal hpc ghc-boot hoopl transformers template-haskell
79! ifeq "$(Windows_Host)" "NO"
80! ifneq "$(HostOS_CPP)" "ios"
81! PACKAGES_STAGE0 += terminfo
82! endif
83! endif
84 
85  PACKAGES_STAGE1 += ghc-prim
86  PACKAGES_STAGE1 += $(INTEGER_LIBRARY)
87--- 413,423 ----
88  # compiler already has installed (or up-to-date enough).
89 
90  PACKAGES_STAGE0 = binary Cabal/Cabal hpc ghc-boot hoopl transformers template-haskell
91! # ifeq "$(Windows_Host)" "NO"
92! # ifneq "$(HostOS_CPP)" "ios"
93! # PACKAGES_STAGE0 += terminfo
94! # endif
95! # endif
96 
97  PACKAGES_STAGE1 += ghc-prim
98  PACKAGES_STAGE1 += $(INTEGER_LIBRARY)
99***************
100*** 451,461 ****
101  PACKAGES_STAGE1 += xhtml
102  endif
103 
104! ifeq "$(Windows_Target)" "NO"
105! ifneq "$(TargetOS_CPP)" "ios"
106! PACKAGES_STAGE1 += terminfo
107! endif
108! endif
109  PACKAGES_STAGE1 += haskeline
110  PACKAGES_STAGE1 += ghci
111 
112--- 451,461 ----
113  PACKAGES_STAGE1 += xhtml
114  endif
115 
116! # ifeq "$(Windows_Target)" "NO"
117! # ifneq "$(TargetOS_CPP)" "ios"
118! # PACKAGES_STAGE1 += terminfo
119! # endif
120! # endif
121  PACKAGES_STAGE1 += haskeline
122  PACKAGES_STAGE1 += ghci
123 
124diff -cr ghc-8.0.0-stock/libraries/haskeline/haskeline.cabal ghc-8.0.0.20160111/libraries/haskeline/haskeline.cabal
125*** ghc-8.0.0-stock/libraries/haskeline/haskeline.cabal 2015-12-28 09:43:26.000000000 -0500
126--- ghc-8.0.0.20160111/libraries/haskeline/haskeline.cabal      2016-01-23 01:20:50.989827722 -0500
127***************
128*** 35,41 ****
129  -- restricted to only one line and thus only shows part of the input at once.)
130  flag terminfo
131      Description: Use the terminfo package for POSIX consoles.
132!     Default: True
133 
134  -- Note that the Setup script checks whether -liconv is necessary.  This flag
135  -- lets us override that decision.  When it is True, we use -liconv.  When it
136--- 35,41 ----
137  -- restricted to only one line and thus only shows part of the input at once.)
138  flag terminfo
139      Description: Use the terminfo package for POSIX consoles.
140!     Default: False
141 
142  -- Note that the Setup script checks whether -liconv is necessary.  This flag
143  -- lets us override that decision.  When it is True, we use -liconv.  When it
144diff -cr ghc-8.0.0-stock/libraries/unix/System/Posix/Terminal/Common.hsc ghc-8.0.0.20160111/libraries/unix/System/Posix/Terminal/Common.hsc
145*** ghc-8.0.0-stock/libraries/unix/System/Posix/Terminal/Common.hsc     2015-12-28 09:43:55.000000000 -0500
146--- ghc-8.0.0.20160111/libraries/unix/System/Posix/Terminal/Common.hsc  2016-01-22 22:25:49.876933862 -0500
147***************
148*** 262,268 ****
149    withTerminalAttributes termios $ \p -> do
150      let c_cc = (#ptr struct termios, c_cc) p
151      val <- peekElemOff c_cc (cc2Word cc)
152!     if val == ((#const _POSIX_VDISABLE)::CCc)
153         then return Nothing
154         else return (Just (chr (fromEnum val)))
155 
156--- 262,268 ----
157    withTerminalAttributes termios $ \p -> do
158      let c_cc = (#ptr struct termios, c_cc) p
159      val <- peekElemOff c_cc (cc2Word cc)
160!     if val == ((-1)::CCc)
161         then return Nothing
162         else return (Just (chr (fromEnum val)))
163 
164***************
165*** 280,286 ****
166  withoutCC termios cc = unsafePerformIO $ do
167    withNewTermios termios $ \p -> do
168      let c_cc = (#ptr struct termios, c_cc) p
169!     pokeElemOff c_cc (cc2Word cc) ((#const _POSIX_VDISABLE) :: CCc)
170 
171  inputTime :: TerminalAttributes -> Int
172  inputTime termios = unsafePerformIO $ do
173--- 280,286 ----
174  withoutCC termios cc = unsafePerformIO $ do
175    withNewTermios termios $ \p -> do
176      let c_cc = (#ptr struct termios, c_cc) p
177!     pokeElemOff c_cc (cc2Word cc) ((-1) :: CCc)
178 
179  inputTime :: TerminalAttributes -> Int
180  inputTime termios = unsafePerformIO $ do
181diff -cr ghc-8.0.0-stock/mk/config.mk.in ghc-8.0.0.20160111/mk/config.mk.in
182*** ghc-8.0.0-stock/mk/config.mk.in     2015-12-28 09:42:43.000000000 -0500
183--- ghc-8.0.0.20160111/mk/config.mk.in  2016-01-23 00:41:53.474504282 -0500
184***************
185*** 109,115 ****
186  # Some platforms don't support shared libraries
187  NoSharedLibsPlatformList = \
188        x86_64-unknown-mingw32 \
189!       i386-unknown-mingw32
190 
191  ifeq "$(SOLARIS_BROKEN_SHLD)" "YES"
192  NoSharedLibsPlatformList += i386-unknown-solaris2
193--- 109,117 ----
194  # Some platforms don't support shared libraries
195  NoSharedLibsPlatformList = \
196        x86_64-unknown-mingw32 \
197!       i386-unknown-mingw32 \
198!       aarch64-linux-android \
199!       aarch64-unknown-linux-android
200 
201  ifeq "$(SOLARIS_BROKEN_SHLD)" "YES"
202  NoSharedLibsPlatformList += i386-unknown-solaris2
203diff -cr ghc-8.0.0-stock/rts/posix/OSThreads.c ghc-8.0.0.20160111/rts/posix/OSThreads.c
204*** ghc-8.0.0-stock/rts/posix/OSThreads.c       2015-12-28 09:42:43.000000000 -0500
205--- ghc-8.0.0.20160111/rts/posix/OSThreads.c    2016-01-22 22:25:49.876933862 -0500
206***************
207*** 249,312 ****
208      return nproc;
209  }
210 
211! #if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY)
212! // Schedules the thread to run on CPU n of m.  m may be less than the
213! // number of physical CPUs, in which case, the thread will be allowed
214! // to run on CPU n, n+m, n+2m etc.
215! void
216! setThreadAffinity (nat n, nat m)
217! {
218!     nat nproc;
219!     cpu_set_t cs;
220!     nat i;
221!
222!     nproc = getNumberOfProcessors();
223!     CPU_ZERO(&cs);
224!     for (i = n; i < nproc; i+=m) {
225!         CPU_SET(i, &cs);
226!     }
227!     sched_setaffinity(0, sizeof(cpu_set_t), &cs);
228! }
229!
230! #elif defined(darwin_HOST_OS) && defined(THREAD_AFFINITY_POLICY)
231! // Schedules the current thread in the affinity set identified by tag n.
232! void
233! setThreadAffinity (nat n, nat m GNUC3_ATTRIBUTE(__unused__))
234! {
235!     thread_affinity_policy_data_t policy;
236!
237!     policy.affinity_tag = n;
238!     thread_policy_set(mach_thread_self(),
239!                       THREAD_AFFINITY_POLICY,
240!                       (thread_policy_t) &policy,
241!                       THREAD_AFFINITY_POLICY_COUNT);
242! }
243!
244! #elif defined(HAVE_SYS_CPUSET_H) /* FreeBSD 7.1+ */
245! void
246! setThreadAffinity(nat n, nat m)
247! {
248!         nat nproc;
249!         cpuset_t cs;
250!         nat i;
251!
252!         nproc = getNumberOfProcessors();
253!         CPU_ZERO(&cs);
254!
255!         for (i = n; i < nproc; i += m)
256!                 CPU_SET(i, &cs);
257!
258!         cpuset_setaffinity(CPU_LEVEL_WHICH, CPU_WHICH_TID,
259!                            -1, sizeof(cpuset_t), &cs);
260! }
261!
262! #else
263  void
264  setThreadAffinity (nat n GNUC3_ATTRIBUTE(__unused__),
265                     nat m GNUC3_ATTRIBUTE(__unused__))
266  {
267  }
268! #endif
269 
270  void
271  interruptOSThread (OSThreadId id)
272--- 249,312 ----
273      return nproc;
274  }
275 
276! // #if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY)
277! // // Schedules the thread to run on CPU n of m.  m may be less than the
278! // // number of physical CPUs, in which case, the thread will be allowed
279! // // to run on CPU n, n+m, n+2m etc.
280! // void
281! // setThreadAffinity (nat n, nat m)
282! // {
283! //     nat nproc;
284! //     cpu_set_t cs;
285! //     nat i;
286! //
287! //     nproc = getNumberOfProcessors();
288! //     CPU_ZERO(&cs);
289! //     for (i = n; i < nproc; i+=m) {
290! //         CPU_SET(i, &cs);
291! //     }
292! //     sched_setaffinity(0, sizeof(cpu_set_t), &cs);
293! // }
294! //
295! // #elif defined(darwin_HOST_OS) && defined(THREAD_AFFINITY_POLICY)
296! // // Schedules the current thread in the affinity set identified by tag n.
297! // void
298! // setThreadAffinity (nat n, nat m GNUC3_ATTRIBUTE(__unused__))
299! // {
300! //     thread_affinity_policy_data_t policy;
301! //
302! //     policy.affinity_tag = n;
303! //     thread_policy_set(mach_thread_self(),
304! //                       THREAD_AFFINITY_POLICY,
305! //                       (thread_policy_t) &policy,
306! //                       THREAD_AFFINITY_POLICY_COUNT);
307! // }
308! //
309! // #elif defined(HAVE_SYS_CPUSET_H) /* FreeBSD 7.1+ */
310! // void
311! // setThreadAffinity(nat n, nat m)
312! // {
313! //         nat nproc;
314! //         cpuset_t cs;
315! //         nat i;
316! //
317! //         nproc = getNumberOfProcessors();
318! //         CPU_ZERO(&cs);
319! //
320! //         for (i = n; i < nproc; i += m)
321! //                 CPU_SET(i, &cs);
322! //
323! //         cpuset_setaffinity(CPU_LEVEL_WHICH, CPU_WHICH_TID,
324! //                            -1, sizeof(cpuset_t), &cs);
325! // }
326! //
327! // #else
328  void
329  setThreadAffinity (nat n GNUC3_ATTRIBUTE(__unused__),
330                     nat m GNUC3_ATTRIBUTE(__unused__))
331  {
332  }
333! // #endif
334 
335  void
336  interruptOSThread (OSThreadId id)
337diff -cr ghc-8.0.0-stock/utils/ghc-pkg/ghc-pkg.cabal ghc-8.0.0.20160111/utils/ghc-pkg/ghc-pkg.cabal
338*** ghc-8.0.0-stock/utils/ghc-pkg/ghc-pkg.cabal 2016-01-05 16:51:20.000000000 -0500
339--- ghc-8.0.0.20160111/utils/ghc-pkg/ghc-pkg.cabal      2016-01-23 01:35:15.509680646 -0500
340***************
341*** 31,37 ****
342                     ghc-boot,
343                     bytestring
344      if !os(windows)
345!         Build-Depends: unix,
346!                        terminfo
347      if os(windows)
348          c-sources: CRT_noglob.c
349--- 31,36 ----
350                     ghc-boot,
351                     bytestring
352      if !os(windows)
353!         Build-Depends: unix
354      if os(windows)
355          c-sources: CRT_noglob.c
356diff -cr ghc-8.0.0-stock/utils/ghc-pkg/Main.hs ghc-8.0.0.20160111/utils/ghc-pkg/Main.hs
357*** ghc-8.0.0-stock/utils/ghc-pkg/Main.hs       2015-12-28 09:42:43.000000000 -0500
358--- ghc-8.0.0.20160111/utils/ghc-pkg/Main.hs    2016-01-23 01:35:59.238660190 -0500
359***************
360*** 69,74 ****
361--- 69,76 ----
362  import qualified System.Info(os)
363  #endif
364 
365+ #define BOOTSTRAPPING
366+
367  #if !defined(mingw32_HOST_OS) && !defined(BOOTSTRAPPING)
368  import System.Console.Terminfo as Terminfo
369  #endif