Commit bb9740e545205f93a525c77aa6d1cbf4ca9371f3

Anthony Green 2013-11-30T17:54:39

Merge pull request #60 from zwaldowski/ios-redo Mac/iOS support, including aarch64 port

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
diff --git a/.gitignore b/.gitignore
index 6af76ac..95566c9 100644
--- a/.gitignore
+++ b/.gitignore
@@ -19,3 +19,5 @@ autom4te.cache
 libffi.xcodeproj/xcuserdata
 libffi.xcodeproj/project.xcworkspace
 ios/
+osx/
+build_*/
diff --git a/build-ios.sh b/build-ios.sh
deleted file mode 100755
index 3dea242..0000000
--- a/build-ios.sh
+++ /dev/null
@@ -1,67 +0,0 @@
-#!/bin/sh
-
-PLATFORM_IOS=/Developer/Platforms/iPhoneOS.platform/
-PLATFORM_IOS_SIM=/Developer/Platforms/iPhoneSimulator.platform/
-SDK_IOS_VERSION="4.2"
-MIN_IOS_VERSION="3.0"
-OUTPUT_DIR="universal-ios"
-
-build_target () {
-    local platform=$1
-    local sdk=$2
-    local arch=$3
-    local triple=$4
-    local builddir=$5
-
-    mkdir -p "${builddir}"
-    pushd "${builddir}"
-    export CC="${platform}"/Developer/usr/bin/gcc-4.2
-    export CFLAGS="-arch ${arch} -isysroot ${sdk} -miphoneos-version-min=${MIN_IOS_VERSION}"
-    ../configure --host=${triple} && make
-    popd
-}
-
-# Build all targets
-build_target "${PLATFORM_IOS}" "${PLATFORM_IOS}/Developer/SDKs/iPhoneOS${SDK_IOS_VERSION}.sdk/" armv6 arm-apple-darwin10 armv6-ios
-build_target "${PLATFORM_IOS}" "${PLATFORM_IOS}/Developer/SDKs/iPhoneOS${SDK_IOS_VERSION}.sdk/" armv7 arm-apple-darwin10 armv7-ios
-build_target "${PLATFORM_IOS_SIM}" "${PLATFORM_IOS_SIM}/Developer/SDKs/iPhoneSimulator${SDK_IOS_VERSION}.sdk/" i386 i386-apple-darwin10 i386-ios-sim
-
-# Create universal output directories
-mkdir -p "${OUTPUT_DIR}"
-mkdir -p "${OUTPUT_DIR}/include"
-mkdir -p "${OUTPUT_DIR}/include/armv6"
-mkdir -p "${OUTPUT_DIR}/include/armv7"
-mkdir -p "${OUTPUT_DIR}/include/i386"
-
-# Create the universal binary
-lipo -create armv6-ios/.libs/libffi.a armv7-ios/.libs/libffi.a i386-ios-sim/.libs/libffi.a -output "${OUTPUT_DIR}/libffi.a"
-
-# Copy in the headers
-copy_headers () {
-    local src=$1
-    local dest=$2
-
-    # Fix non-relative header reference
-    sed 's/<ffitarget.h>/"ffitarget.h"/' < "${src}/include/ffi.h" > "${dest}/ffi.h"
-    cp "${src}/include/ffitarget.h" "${dest}"
-}
-
-copy_headers armv6-ios "${OUTPUT_DIR}/include/armv6"
-copy_headers armv7-ios "${OUTPUT_DIR}/include/armv7"
-copy_headers i386-ios-sim "${OUTPUT_DIR}/include/i386"
-
-# Create top-level header
-(
-cat << EOF
-#ifdef __arm__
-  #include <arm/arch.h>
-  #ifdef _ARM_ARCH_6
-    #include "include/armv6/ffi.h"
-  #elif _ARM_ARCH_7
-    #include "include/armv7/ffi.h"
-  #endif
-#elif defined(__i386__)
-  #include "include/i386/ffi.h"
-#endif
-EOF
-) > "${OUTPUT_DIR}/ffi.h"
diff --git a/generate-ios-source-and-headers.py b/generate-ios-source-and-headers.py
index c2bca73..4d4d0ae 100644
--- a/generate-ios-source-and-headers.py
+++ b/generate-ios-source-and-headers.py
@@ -1,29 +1,40 @@
 #!/usr/bin/env python
-
 import subprocess
 import re
 import os
 import errno
 import collections
-import sys
 
 class Platform(object):
     pass
 
 sdk_re = re.compile(r'.*-sdk ([a-zA-Z0-9.]*)')
 
+
 def sdkinfo(sdkname):
     ret = {}
     for line in subprocess.Popen(['xcodebuild', '-sdk', sdkname, '-version'], stdout=subprocess.PIPE).stdout:
         kv = line.strip().split(': ', 1)
         if len(kv) == 2:
-            k,v = kv
+            k, v = kv
             ret[k] = v
     return ret
 
+
+def mkdir_p(path):
+    try:
+        os.makedirs(path)
+    except OSError as exc:  # Python >2.5
+        if exc.errno == errno.EEXIST:
+            pass
+        else:
+            raise
+
+
 sim_sdk_info = sdkinfo('iphonesimulator')
 device_sdk_info = sdkinfo('iphoneos')
 
+
 def latest_sdks():
     latest_sim = None
     latest_device = None
@@ -39,36 +50,62 @@ def latest_sdks():
 
 sim_sdk, device_sdk = latest_sdks()
 
+
 class simulator_platform(Platform):
-    sdk='iphonesimulator'
+    sdk = 'iphonesimulator'
     arch = 'i386'
-    name = 'simulator'
-    triple = 'i386-apple-darwin10'
+    short_arch = arch
+    triple = 'i386-apple-darwin11'
     sdkroot = sim_sdk_info['Path']
+    version_min = '5.1.1'
 
-    prefix = "#if !defined(__arm__) && defined(__i386__)\n\n"
+    prefix = "#ifdef __i386__\n\n"
     suffix = "\n\n#endif"
 
+
+class simulator64_platform(Platform):
+    sdk = 'iphonesimulator'
+    arch = 'x86_64'
+    short_arch = arch
+    triple = 'x86_64-apple-darwin13'
+    sdkroot = sim_sdk_info['Path']
+    version_min = '7.0'
+
+    prefix = "#ifdef __x86_64__\n\n"
+    suffix = "\n\n#endif"
+
+
 class device_platform(Platform):
-    sdk='iphoneos'
-    name = 'ios'
+    sdk = 'iphoneos'
     arch = 'armv7'
-    triple = 'arm-apple-darwin10'
+    short_arch = 'arm'
+    triple = 'arm-apple-darwin11'
     sdkroot = device_sdk_info['Path']
+    version_min = '5.1.1'
 
     prefix = "#ifdef __arm__\n\n"
     suffix = "\n\n#endif"
 
 
-def move_file(src_dir, dst_dir, filename, file_suffix=None, prefix='', suffix=''):
-    if not os.path.exists(dst_dir):
-        os.makedirs(dst_dir)
+class device64_platform(Platform):
+    sdk = 'iphoneos'
+    arch = 'arm64'
+    short_arch = 'arm64'
+    triple = 'aarch64-apple-darwin13'
+    sdkroot = device_sdk_info['Path']
+    version_min = '7.0'
 
+    prefix = "#ifdef __arm64__\n\n"
+    suffix = "\n\n#endif"
+
+
+def move_file(src_dir, dst_dir, filename, file_suffix=None, prefix='', suffix=''):
+    mkdir_p(dst_dir)
     out_filename = filename
 
     if file_suffix:
         split_name = os.path.splitext(filename)
-        out_filename =  "%s_%s%s" % (split_name[0], file_suffix, split_name[1])
+        out_filename = "%s_%s%s" % (split_name[0], file_suffix, split_name[1])
 
     with open(os.path.join(src_dir, filename)) as in_file:
         with open(os.path.join(dst_dir, out_filename), 'w') as out_file:
@@ -82,16 +119,15 @@ def move_file(src_dir, dst_dir, filename, file_suffix=None, prefix='', suffix=''
 
 headers_seen = collections.defaultdict(set)
 
+
 def move_source_tree(src_dir, dest_dir, dest_include_dir, arch=None, prefix=None, suffix=None):
     for root, dirs, files in os.walk(src_dir, followlinks=True):
-        relroot = os.path.relpath(root,src_dir)
+        relroot = os.path.relpath(root, src_dir)
 
         def move_dir(arch, prefix='', suffix='', files=[]):
             for file in files:
-                file_suffix = None
                 if file.endswith('.h'):
                     if dest_include_dir:
-                        file_suffix = arch
                         if arch:
                             headers_seen[file].add(arch)
                         move_file(root, dest_include_dir, file, arch, prefix=prefix, suffix=suffix)
@@ -109,46 +145,66 @@ def move_source_tree(src_dir, dest_dir, dest_include_dir, arch=None, prefix=None
             move_dir(arch='arm',
                      prefix="#ifdef __arm__\n\n",
                      suffix="\n\n#endif",
-                     files=files)
+                     files=['sysv.S', 'trampoline.S', 'ffi.c'])
+        elif relroot == 'aarch64':
+            move_dir(arch='arm64',
+                     prefix="#ifdef __arm64__\n\n",
+                     suffix="\n\n#endif",
+                     files=['sysv.S', 'ffi.c'])
         elif relroot == 'x86':
             move_dir(arch='i386',
-                     prefix="#if !defined(__arm__) && defined(__i386__)\n\n",
+                     prefix="#ifdef __i386__\n\n",
                      suffix="\n\n#endif",
-                     files=files)
+                     files=['darwin.S', 'ffi.c'])
+            move_dir(arch='x86_64',
+                     prefix="#ifdef __x86_64__\n\n",
+                     suffix="\n\n#endif",
+                     files=['darwin64.S', 'ffi64.c'])
+
 
 def build_target(platform):
     def xcrun_cmd(cmd):
         return subprocess.check_output(['xcrun', '-sdk', platform.sdkroot, '-find', cmd]).strip()
 
-    build_dir = 'build_' + platform.name
-    if not os.path.exists(build_dir):
-        os.makedirs(build_dir)
-        env = dict(CC=xcrun_cmd('clang'),
-                   LD=xcrun_cmd('ld'),
-                   CFLAGS='-arch %s -isysroot %s -miphoneos-version-min=4.0' % (platform.arch, platform.sdkroot))
-        working_dir=os.getcwd()
-        try:
-            os.chdir(build_dir)
-            subprocess.check_call(['../configure', '-host', platform.triple], env=env)
-            move_source_tree('.', None, '../ios/include',
-                             arch=platform.arch,
-                             prefix=platform.prefix,
-                             suffix=platform.suffix)
-            move_source_tree('./include', None, '../ios/include',
-                            arch=platform.arch,
-                            prefix=platform.prefix,
-                            suffix=platform.suffix)
-        finally:
-            os.chdir(working_dir)
-
-        for header_name, archs in headers_seen.iteritems():
-            basename, suffix = os.path.splitext(header_name)
+    build_dir = 'build_' + platform.short_arch
+    mkdir_p(build_dir)
+    env = dict(CC=xcrun_cmd('clang'),
+               LD=xcrun_cmd('ld'),
+               CFLAGS='-arch %s -isysroot %s -miphoneos-version-min=%s' % (platform.arch, platform.sdkroot, platform.version_min))
+    working_dir = os.getcwd()
+    try:
+        os.chdir(build_dir)
+        subprocess.check_call(['../configure', '-host', platform.triple], env=env)
+        move_source_tree('.', None, '../ios/include',
+                         arch=platform.short_arch,
+                         prefix=platform.prefix,
+                         suffix=platform.suffix)
+        move_source_tree('./include', None, '../ios/include',
+                         arch=platform.short_arch,
+                         prefix=platform.prefix,
+                         suffix=platform.suffix)
+    finally:
+        os.chdir(working_dir)
+
+    for header_name, archs in headers_seen.iteritems():
+        basename, suffix = os.path.splitext(header_name)
+
+
+def make_tramp():
+    with open('src/arm/trampoline.S', 'w') as tramp_out:
+        p = subprocess.Popen(['bash', 'src/arm/gentramp.sh'], stdout=tramp_out)
+        p.wait()
+
 
 def main():
+    make_tramp()
+
     move_source_tree('src', 'ios/src', 'ios/include')
     move_source_tree('include', None, 'ios/include')
     build_target(simulator_platform)
+    build_target(simulator64_platform)
     build_target(device_platform)
+    build_target(device64_platform)
 
     for header_name, archs in headers_seen.iteritems():
         basename, suffix = os.path.splitext(header_name)
diff --git a/generate-osx-source-and-headers.py b/generate-osx-source-and-headers.py
index 64313c1..97a732d 100644
--- a/generate-osx-source-and-headers.py
+++ b/generate-osx-source-and-headers.py
@@ -4,24 +4,36 @@ import re
 import os
 import errno
 import collections
-import sys
+
 
 class Platform(object):
     pass
 
 sdk_re = re.compile(r'.*-sdk ([a-zA-Z0-9.]*)')
 
+
 def sdkinfo(sdkname):
     ret = {}
     for line in subprocess.Popen(['xcodebuild', '-sdk', sdkname, '-version'], stdout=subprocess.PIPE).stdout:
         kv = line.strip().split(': ', 1)
         if len(kv) == 2:
-            k,v = kv
+            k, v = kv
             ret[k] = v
     return ret
 
+
+def mkdir_p(path):
+    try:
+        os.makedirs(path)
+    except OSError as exc:  # Python >2.5
+        if exc.errno == errno.EEXIST:
+            pass
+        else:
+            raise
+
 desktop_sdk_info = sdkinfo('macosx')
 
+
 def latest_sdks():
     latest_desktop = None
     for line in subprocess.Popen(['xcodebuild', '-showsdks'], stdout=subprocess.PIPE).stdout:
@@ -34,35 +46,38 @@ def latest_sdks():
 
 desktop_sdk = latest_sdks()
 
-class desktop_platform_32(Platform):
-    sdk='macosx'
+
+class desktop32_platform(Platform):
+    sdk = 'macosx'
     arch = 'i386'
     name = 'mac32'
-    triple = 'i386-apple-darwin10'
+    triple = 'i386-apple-darwin11'
     sdkroot = desktop_sdk_info['Path']
+    version_min = '10.7'
 
-    prefix = "#if defined(__i386__) && !defined(__x86_64__)\n\n"
+    prefix = "#ifdef __i386__\n\n"
     suffix = "\n\n#endif"
 
-class desktop_platform_64(Platform):
-    sdk='macosx'
+
+class desktop64_platform(Platform):
+    sdk = 'macosx'
     arch = 'x86_64'
     name = 'mac'
-    triple = 'x86_64-apple-darwin10'
+    triple = 'x86_64-apple-darwin11'
     sdkroot = desktop_sdk_info['Path']
+    version_min = '10.7'
 
-    prefix = "#if !defined(__i386__) && defined(__x86_64__)\n\n"
+    prefix = "#ifdef __x86_64__\n\n"
     suffix = "\n\n#endif"
 
-def move_file(src_dir, dst_dir, filename, file_suffix=None, prefix='', suffix=''):
-    if not os.path.exists(dst_dir):
-        os.makedirs(dst_dir)
 
+def move_file(src_dir, dst_dir, filename, file_suffix=None, prefix='', suffix=''):
+    mkdir_p(dst_dir)
     out_filename = filename
 
     if file_suffix:
         split_name = os.path.splitext(filename)
-        out_filename =  "%s_%s%s" % (split_name[0], file_suffix, split_name[1])
+        out_filename = "%s_%s%s" % (split_name[0], file_suffix, split_name[1])
 
     with open(os.path.join(src_dir, filename)) as in_file:
         with open(os.path.join(dst_dir, out_filename), 'w') as out_file:
@@ -76,16 +91,15 @@ def move_file(src_dir, dst_dir, filename, file_suffix=None, prefix='', suffix=''
 
 headers_seen = collections.defaultdict(set)
 
+
 def move_source_tree(src_dir, dest_dir, dest_include_dir, arch=None, prefix=None, suffix=None):
     for root, dirs, files in os.walk(src_dir, followlinks=True):
-        relroot = os.path.relpath(root,src_dir)
+        relroot = os.path.relpath(root, src_dir)
 
         def move_dir(arch, prefix='', suffix='', files=[]):
             for file in files:
-                file_suffix = None
                 if file.endswith('.h'):
                     if dest_include_dir:
-                        file_suffix = arch
                         if arch:
                             headers_seen[file].add(arch)
                         move_file(root, dest_include_dir, file, arch, prefix=prefix, suffix=suffix)
@@ -101,13 +115,14 @@ def move_source_tree(src_dir, dest_dir, dest_include_dir, arch=None, prefix=None
                      suffix=suffix)
         elif relroot == 'x86':
             move_dir(arch='i386',
-                     prefix="#if defined(__i386__) && !defined(__x86_64__)\n\n",
+                     prefix="#ifdef __i386__\n\n",
                      suffix="\n\n#endif",
-                     files=files)
+                     files=['darwin.S', 'ffi.c'])
             move_dir(arch='x86_64',
-                     prefix="#if !defined(__i386__) && defined(__x86_64__)\n\n",
+                     prefix="#ifdef __x86_64__\n\n",
                      suffix="\n\n#endif",
-                     files=files)
+                     files=['darwin64.S', 'ffi64.c'])
+
 
 def build_target(platform):
     def xcrun_cmd(cmd):
@@ -118,8 +133,8 @@ def build_target(platform):
         os.makedirs(build_dir)
         env = dict(CC=xcrun_cmd('clang'),
                    LD=xcrun_cmd('ld'),
-                   CFLAGS='-arch %s -isysroot %s -mmacosx-version-min=10.6' % (platform.arch, platform.sdkroot))
-        working_dir=os.getcwd()
+                   CFLAGS='-arch %s -isysroot %s -mmacosx-version-min=%s' % (platform.arch, platform.sdkroot, platform.version_min))
+        working_dir = os.getcwd()
         try:
             os.chdir(build_dir)
             subprocess.check_call(['../configure', '-host', platform.triple], env=env)
@@ -137,11 +152,12 @@ def build_target(platform):
         for header_name, archs in headers_seen.iteritems():
             basename, suffix = os.path.splitext(header_name)
 
+
 def main():
     move_source_tree('src', 'osx/src', 'osx/include')
     move_source_tree('include', None, 'osx/include')
-    build_target(desktop_platform_32)
-    build_target(desktop_platform_64)
+    build_target(desktop32_platform)
+    build_target(desktop64_platform)
 
     for header_name, archs in headers_seen.iteritems():
         basename, suffix = os.path.splitext(header_name)
diff --git a/include/ffi_common.h b/include/ffi_common.h
index 37f5a9e..be10922 100644
--- a/include/ffi_common.h
+++ b/include/ffi_common.h
@@ -48,7 +48,7 @@ char *alloca ();
 #endif
 
 /* Check for the existence of memcpy. */
-#if STDC_HEADERS
+#if STDC_HEADERS || HAVE_STRING_H
 # include <string.h>
 #else
 # ifndef HAVE_MEMCPY
diff --git a/libffi.xcodeproj/project.pbxproj b/libffi.xcodeproj/project.pbxproj
index 14c39a2..f763d0f 100644
--- a/libffi.xcodeproj/project.pbxproj
+++ b/libffi.xcodeproj/project.pbxproj
@@ -7,382 +7,422 @@
 	objects = {
 
 /* Begin PBXBuildFile section */
-		6C43CBDC1534F76F00162364 /* ffi.c in Sources */ = {isa = PBXBuildFile; fileRef = 6C43CBBD1534F76F00162364 /* ffi.c */; };
-		6C43CBDD1534F76F00162364 /* sysv.S in Sources */ = {isa = PBXBuildFile; fileRef = 6C43CBBF1534F76F00162364 /* sysv.S */; };
-		6C43CBDE1534F76F00162364 /* trampoline.S in Sources */ = {isa = PBXBuildFile; fileRef = 6C43CBC01534F76F00162364 /* trampoline.S */; };
-		6C43CBE61534F76F00162364 /* darwin.S in Sources */ = {isa = PBXBuildFile; fileRef = 6C43CBC91534F76F00162364 /* darwin.S */; };
-		6C43CBE81534F76F00162364 /* ffi.c in Sources */ = {isa = PBXBuildFile; fileRef = 6C43CBCB1534F76F00162364 /* ffi.c */; };
-		6C43CC1F1534F77800162364 /* darwin.S in Sources */ = {isa = PBXBuildFile; fileRef = 6C43CC051534F77800162364 /* darwin.S */; };
-		6C43CC201534F77800162364 /* darwin64.S in Sources */ = {isa = PBXBuildFile; fileRef = 6C43CC061534F77800162364 /* darwin64.S */; };
-		6C43CC211534F77800162364 /* ffi.c in Sources */ = {isa = PBXBuildFile; fileRef = 6C43CC071534F77800162364 /* ffi.c */; };
-		6C43CC221534F77800162364 /* ffi64.c in Sources */ = {isa = PBXBuildFile; fileRef = 6C43CC081534F77800162364 /* ffi64.c */; };
-		6C43CC2F1534F7BE00162364 /* closures.c in Sources */ = {isa = PBXBuildFile; fileRef = 6C43CC281534F7BE00162364 /* closures.c */; };
-		6C43CC301534F7BE00162364 /* closures.c in Sources */ = {isa = PBXBuildFile; fileRef = 6C43CC281534F7BE00162364 /* closures.c */; };
-		6C43CC351534F7BE00162364 /* java_raw_api.c in Sources */ = {isa = PBXBuildFile; fileRef = 6C43CC2B1534F7BE00162364 /* java_raw_api.c */; };
-		6C43CC361534F7BE00162364 /* java_raw_api.c in Sources */ = {isa = PBXBuildFile; fileRef = 6C43CC2B1534F7BE00162364 /* java_raw_api.c */; };
-		6C43CC371534F7BE00162364 /* prep_cif.c in Sources */ = {isa = PBXBuildFile; fileRef = 6C43CC2C1534F7BE00162364 /* prep_cif.c */; };
-		6C43CC381534F7BE00162364 /* prep_cif.c in Sources */ = {isa = PBXBuildFile; fileRef = 6C43CC2C1534F7BE00162364 /* prep_cif.c */; };
-		6C43CC391534F7BE00162364 /* raw_api.c in Sources */ = {isa = PBXBuildFile; fileRef = 6C43CC2D1534F7BE00162364 /* raw_api.c */; };
-		6C43CC3A1534F7BE00162364 /* raw_api.c in Sources */ = {isa = PBXBuildFile; fileRef = 6C43CC2D1534F7BE00162364 /* raw_api.c */; };
-		6C43CC3B1534F7BE00162364 /* types.c in Sources */ = {isa = PBXBuildFile; fileRef = 6C43CC2E1534F7BE00162364 /* types.c */; };
-		6C43CC3C1534F7BE00162364 /* types.c in Sources */ = {isa = PBXBuildFile; fileRef = 6C43CC2E1534F7BE00162364 /* types.c */; };
-		6C43CC971535032600162364 /* ffi.h in Headers */ = {isa = PBXBuildFile; fileRef = 6C43CC8D1535032600162364 /* ffi.h */; settings = {ATTRIBUTES = (Public, ); }; };
-		6C43CC981535032600162364 /* ffi_common.h in Headers */ = {isa = PBXBuildFile; fileRef = 6C43CC8E1535032600162364 /* ffi_common.h */; settings = {ATTRIBUTES = (Public, ); }; };
-		6C43CC991535032600162364 /* ffi_i386.h in Headers */ = {isa = PBXBuildFile; fileRef = 6C43CC8F1535032600162364 /* ffi_i386.h */; settings = {ATTRIBUTES = (Public, ); }; };
-		6C43CC9A1535032600162364 /* ffi_x86_64.h in Headers */ = {isa = PBXBuildFile; fileRef = 6C43CC901535032600162364 /* ffi_x86_64.h */; settings = {ATTRIBUTES = (Public, ); }; };
-		6C43CC9B1535032600162364 /* fficonfig.h in Headers */ = {isa = PBXBuildFile; fileRef = 6C43CC911535032600162364 /* fficonfig.h */; };
-		6C43CC9C1535032600162364 /* fficonfig_i386.h in Headers */ = {isa = PBXBuildFile; fileRef = 6C43CC921535032600162364 /* fficonfig_i386.h */; };
-		6C43CC9D1535032600162364 /* fficonfig_x86_64.h in Headers */ = {isa = PBXBuildFile; fileRef = 6C43CC931535032600162364 /* fficonfig_x86_64.h */; };
-		6C43CC9E1535032600162364 /* ffitarget.h in Headers */ = {isa = PBXBuildFile; fileRef = 6C43CC941535032600162364 /* ffitarget.h */; settings = {ATTRIBUTES = (Public, ); }; };
-		6C43CC9F1535032600162364 /* ffitarget_i386.h in Headers */ = {isa = PBXBuildFile; fileRef = 6C43CC951535032600162364 /* ffitarget_i386.h */; settings = {ATTRIBUTES = (Public, ); }; };
-		6C43CCA01535032600162364 /* ffitarget_x86_64.h in Headers */ = {isa = PBXBuildFile; fileRef = 6C43CC961535032600162364 /* ffitarget_x86_64.h */; settings = {ATTRIBUTES = (Public, ); }; };
-		6C43CCAD1535039600162364 /* ffi.h in Headers */ = {isa = PBXBuildFile; fileRef = 6C43CCA21535039600162364 /* ffi.h */; settings = {ATTRIBUTES = (Public, ); }; };
-		6C43CCAE1535039600162364 /* ffi_armv7.h in Headers */ = {isa = PBXBuildFile; fileRef = 6C43CCA31535039600162364 /* ffi_armv7.h */; settings = {ATTRIBUTES = (Public, ); }; };
-		6C43CCAF1535039600162364 /* ffi_common.h in Headers */ = {isa = PBXBuildFile; fileRef = 6C43CCA41535039600162364 /* ffi_common.h */; settings = {ATTRIBUTES = (Public, ); }; };
-		6C43CCB01535039600162364 /* ffi_i386.h in Headers */ = {isa = PBXBuildFile; fileRef = 6C43CCA51535039600162364 /* ffi_i386.h */; settings = {ATTRIBUTES = (Public, ); }; };
-		6C43CCB11535039600162364 /* fficonfig.h in Headers */ = {isa = PBXBuildFile; fileRef = 6C43CCA61535039600162364 /* fficonfig.h */; };
-		6C43CCB21535039600162364 /* fficonfig_armv7.h in Headers */ = {isa = PBXBuildFile; fileRef = 6C43CCA71535039600162364 /* fficonfig_armv7.h */; };
-		6C43CCB31535039600162364 /* fficonfig_i386.h in Headers */ = {isa = PBXBuildFile; fileRef = 6C43CCA81535039600162364 /* fficonfig_i386.h */; };
-		6C43CCB41535039600162364 /* ffitarget.h in Headers */ = {isa = PBXBuildFile; fileRef = 6C43CCA91535039600162364 /* ffitarget.h */; settings = {ATTRIBUTES = (Public, ); }; };
-		6C43CCB51535039600162364 /* ffitarget_arm.h in Headers */ = {isa = PBXBuildFile; fileRef = 6C43CCAA1535039600162364 /* ffitarget_arm.h */; settings = {ATTRIBUTES = (Public, ); }; };
-		6C43CCB61535039600162364 /* ffitarget_armv7.h in Headers */ = {isa = PBXBuildFile; fileRef = 6C43CCAB1535039600162364 /* ffitarget_armv7.h */; settings = {ATTRIBUTES = (Public, ); }; };
-		6C43CCB71535039600162364 /* ffitarget_i386.h in Headers */ = {isa = PBXBuildFile; fileRef = 6C43CCAC1535039600162364 /* ffitarget_i386.h */; settings = {ATTRIBUTES = (Public, ); }; };
+		DB13B16A1849DF1E0010F42D /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DB13B1691849DF1E0010F42D /* Foundation.framework */; };
+		DB13B1931849DF510010F42D /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DB13B1921849DF510010F42D /* Cocoa.framework */; };
+		DB13B33D1849E0CE0010F42D /* ffi.c in Sources */ = {isa = PBXBuildFile; fileRef = DB13B3301849E0CE0010F42D /* ffi.c */; };
+		DB13B33E1849E0CE0010F42D /* sysv.S in Sources */ = {isa = PBXBuildFile; fileRef = DB13B3311849E0CE0010F42D /* sysv.S */; };
+		DB13B33F1849E0CE0010F42D /* trampoline.S in Sources */ = {isa = PBXBuildFile; fileRef = DB13B3321849E0CE0010F42D /* trampoline.S */; };
+		DB13B3401849E0CE0010F42D /* closures.c in Sources */ = {isa = PBXBuildFile; fileRef = DB13B3331849E0CE0010F42D /* closures.c */; };
+		DB13B3441849E0CE0010F42D /* prep_cif.c in Sources */ = {isa = PBXBuildFile; fileRef = DB13B3371849E0CE0010F42D /* prep_cif.c */; };
+		DB13B3451849E0CE0010F42D /* raw_api.c in Sources */ = {isa = PBXBuildFile; fileRef = DB13B3381849E0CE0010F42D /* raw_api.c */; };
+		DB13B3461849E0CE0010F42D /* types.c in Sources */ = {isa = PBXBuildFile; fileRef = DB13B3391849E0CE0010F42D /* types.c */; };
+		DB13B3471849E0CE0010F42D /* darwin.S in Sources */ = {isa = PBXBuildFile; fileRef = DB13B33B1849E0CE0010F42D /* darwin.S */; };
+		DB13B3481849E0CE0010F42D /* ffi.c in Sources */ = {isa = PBXBuildFile; fileRef = DB13B33C1849E0CE0010F42D /* ffi.c */; };
+		DB13B3631849E0FF0010F42D /* ffi.h in Headers */ = {isa = PBXBuildFile; fileRef = DB13B34C1849E0FF0010F42D /* ffi.h */; settings = {ATTRIBUTES = (Public, ); }; };
+		DB13B3641849E0FF0010F42D /* ffi_common.h in Headers */ = {isa = PBXBuildFile; fileRef = DB13B34D1849E0FF0010F42D /* ffi_common.h */; settings = {ATTRIBUTES = (Public, ); }; };
+		DB13B3651849E0FF0010F42D /* ffi_i386.h in Headers */ = {isa = PBXBuildFile; fileRef = DB13B34E1849E0FF0010F42D /* ffi_i386.h */; settings = {ATTRIBUTES = (Public, ); }; };
+		DB13B3661849E0FF0010F42D /* ffi_x86_64.h in Headers */ = {isa = PBXBuildFile; fileRef = DB13B34F1849E0FF0010F42D /* ffi_x86_64.h */; settings = {ATTRIBUTES = (Public, ); }; };
+		DB13B3671849E0FF0010F42D /* fficonfig.h in Headers */ = {isa = PBXBuildFile; fileRef = DB13B3501849E0FF0010F42D /* fficonfig.h */; settings = {ATTRIBUTES = (Public, ); }; };
+		DB13B3681849E0FF0010F42D /* fficonfig_i386.h in Headers */ = {isa = PBXBuildFile; fileRef = DB13B3511849E0FF0010F42D /* fficonfig_i386.h */; settings = {ATTRIBUTES = (Public, ); }; };
+		DB13B3691849E0FF0010F42D /* fficonfig_x86_64.h in Headers */ = {isa = PBXBuildFile; fileRef = DB13B3521849E0FF0010F42D /* fficonfig_x86_64.h */; settings = {ATTRIBUTES = (Public, ); }; };
+		DB13B36A1849E0FF0010F42D /* ffitarget.h in Headers */ = {isa = PBXBuildFile; fileRef = DB13B3531849E0FF0010F42D /* ffitarget.h */; settings = {ATTRIBUTES = (Public, ); }; };
+		DB13B36B1849E0FF0010F42D /* ffitarget_i386.h in Headers */ = {isa = PBXBuildFile; fileRef = DB13B3541849E0FF0010F42D /* ffitarget_i386.h */; settings = {ATTRIBUTES = (Public, ); }; };
+		DB13B36C1849E0FF0010F42D /* ffitarget_x86_64.h in Headers */ = {isa = PBXBuildFile; fileRef = DB13B3551849E0FF0010F42D /* ffitarget_x86_64.h */; settings = {ATTRIBUTES = (Public, ); }; };
+		DB13B36D1849E0FF0010F42D /* closures.c in Sources */ = {isa = PBXBuildFile; fileRef = DB13B3571849E0FF0010F42D /* closures.c */; };
+		DB13B3711849E0FF0010F42D /* prep_cif.c in Sources */ = {isa = PBXBuildFile; fileRef = DB13B35B1849E0FF0010F42D /* prep_cif.c */; };
+		DB13B3721849E0FF0010F42D /* raw_api.c in Sources */ = {isa = PBXBuildFile; fileRef = DB13B35C1849E0FF0010F42D /* raw_api.c */; };
+		DB13B3731849E0FF0010F42D /* types.c in Sources */ = {isa = PBXBuildFile; fileRef = DB13B35D1849E0FF0010F42D /* types.c */; };
+		DB13B3741849E0FF0010F42D /* darwin.S in Sources */ = {isa = PBXBuildFile; fileRef = DB13B35F1849E0FF0010F42D /* darwin.S */; };
+		DB13B3751849E0FF0010F42D /* darwin64.S in Sources */ = {isa = PBXBuildFile; fileRef = DB13B3601849E0FF0010F42D /* darwin64.S */; };
+		DB13B3761849E0FF0010F42D /* ffi.c in Sources */ = {isa = PBXBuildFile; fileRef = DB13B3611849E0FF0010F42D /* ffi.c */; };
+		DB13B3771849E0FF0010F42D /* ffi64.c in Sources */ = {isa = PBXBuildFile; fileRef = DB13B3621849E0FF0010F42D /* ffi64.c */; };
+		DB13B381184A50CC0010F42D /* ffi.c in Sources */ = {isa = PBXBuildFile; fileRef = DB13B37F184A50CC0010F42D /* ffi.c */; };
+		DB13B382184A50CC0010F42D /* sysv.S in Sources */ = {isa = PBXBuildFile; fileRef = DB13B380184A50CC0010F42D /* sysv.S */; };
+		DB13B385184A50D60010F42D /* darwin64.S in Sources */ = {isa = PBXBuildFile; fileRef = DB13B383184A50D60010F42D /* darwin64.S */; };
+		DB13B386184A50D60010F42D /* ffi64.c in Sources */ = {isa = PBXBuildFile; fileRef = DB13B384184A50D60010F42D /* ffi64.c */; };
+		DB13B387184A64FA0010F42D /* ffi.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = DB13B3241849E0CE0010F42D /* ffi.h */; };
+		DB13B388184A64FA0010F42D /* ffi_arm.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = DB13B3251849E0CE0010F42D /* ffi_arm.h */; };
+		DB13B389184A64FA0010F42D /* ffi_arm64.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = DB13B378184A50BF0010F42D /* ffi_arm64.h */; };
+		DB13B38A184A64FA0010F42D /* ffi_common.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = DB13B3261849E0CE0010F42D /* ffi_common.h */; };
+		DB13B38B184A64FA0010F42D /* ffi_i386.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = DB13B3271849E0CE0010F42D /* ffi_i386.h */; };
+		DB13B38C184A64FA0010F42D /* ffi_x86_64.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = DB13B379184A50BF0010F42D /* ffi_x86_64.h */; };
+		DB13B38D184A64FA0010F42D /* fficonfig.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = DB13B3281849E0CE0010F42D /* fficonfig.h */; };
+		DB13B38E184A64FA0010F42D /* fficonfig_arm.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = DB13B3291849E0CE0010F42D /* fficonfig_arm.h */; };
+		DB13B38F184A64FA0010F42D /* fficonfig_arm64.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = DB13B37A184A50BF0010F42D /* fficonfig_arm64.h */; };
+		DB13B390184A64FA0010F42D /* fficonfig_i386.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = DB13B32A1849E0CE0010F42D /* fficonfig_i386.h */; };
+		DB13B391184A64FA0010F42D /* fficonfig_x86_64.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = DB13B37B184A50BF0010F42D /* fficonfig_x86_64.h */; };
+		DB13B392184A64FA0010F42D /* ffitarget.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = DB13B32B1849E0CE0010F42D /* ffitarget.h */; };
+		DB13B393184A64FA0010F42D /* ffitarget_arm.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = DB13B32C1849E0CE0010F42D /* ffitarget_arm.h */; };
+		DB13B394184A64FA0010F42D /* ffitarget_arm64.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = DB13B37C184A50BF0010F42D /* ffitarget_arm64.h */; };
+		DB13B395184A64FA0010F42D /* ffitarget_i386.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = DB13B32D1849E0CE0010F42D /* ffitarget_i386.h */; };
+		DB13B396184A64FA0010F42D /* ffitarget_x86_64.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = DB13B37D184A50BF0010F42D /* ffitarget_x86_64.h */; };
 /* End PBXBuildFile section */
 
+/* Begin PBXCopyFilesBuildPhase section */
+		DB13B1641849DF1E0010F42D /* CopyFiles */ = {
+			isa = PBXCopyFilesBuildPhase;
+			buildActionMask = 8;
+			dstPath = "include/$(PRODUCT_NAME)";
+			dstSubfolderSpec = 16;
+			files = (
+				DB13B387184A64FA0010F42D /* ffi.h in CopyFiles */,
+				DB13B388184A64FA0010F42D /* ffi_arm.h in CopyFiles */,
+				DB13B389184A64FA0010F42D /* ffi_arm64.h in CopyFiles */,
+				DB13B38A184A64FA0010F42D /* ffi_common.h in CopyFiles */,
+				DB13B38B184A64FA0010F42D /* ffi_i386.h in CopyFiles */,
+				DB13B38C184A64FA0010F42D /* ffi_x86_64.h in CopyFiles */,
+				DB13B38D184A64FA0010F42D /* fficonfig.h in CopyFiles */,
+				DB13B38E184A64FA0010F42D /* fficonfig_arm.h in CopyFiles */,
+				DB13B38F184A64FA0010F42D /* fficonfig_arm64.h in CopyFiles */,
+				DB13B390184A64FA0010F42D /* fficonfig_i386.h in CopyFiles */,
+				DB13B391184A64FA0010F42D /* fficonfig_x86_64.h in CopyFiles */,
+				DB13B392184A64FA0010F42D /* ffitarget.h in CopyFiles */,
+				DB13B393184A64FA0010F42D /* ffitarget_arm.h in CopyFiles */,
+				DB13B394184A64FA0010F42D /* ffitarget_arm64.h in CopyFiles */,
+				DB13B395184A64FA0010F42D /* ffitarget_i386.h in CopyFiles */,
+				DB13B396184A64FA0010F42D /* ffitarget_x86_64.h in CopyFiles */,
+			);
+			runOnlyForDeploymentPostprocessing = 1;
+		};
+/* End PBXCopyFilesBuildPhase section */
+
 /* Begin PBXFileReference section */
-		6C43CB3D1534E9D100162364 /* libffi.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libffi.a; sourceTree = BUILT_PRODUCTS_DIR; };
-		6C43CBBD1534F76F00162364 /* ffi.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = ffi.c; sourceTree = "<group>"; };
-		6C43CBBF1534F76F00162364 /* sysv.S */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.asm; path = sysv.S; sourceTree = "<group>"; };
-		6C43CBC01534F76F00162364 /* trampoline.S */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.asm; path = trampoline.S; sourceTree = "<group>"; };
-		6C43CBC91534F76F00162364 /* darwin.S */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.asm; path = darwin.S; sourceTree = "<group>"; };
-		6C43CBCB1534F76F00162364 /* ffi.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = ffi.c; sourceTree = "<group>"; };
-		6C43CC051534F77800162364 /* darwin.S */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.asm; path = darwin.S; sourceTree = "<group>"; };
-		6C43CC061534F77800162364 /* darwin64.S */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.asm; path = darwin64.S; sourceTree = "<group>"; };
-		6C43CC071534F77800162364 /* ffi.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = ffi.c; sourceTree = "<group>"; };
-		6C43CC081534F77800162364 /* ffi64.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = ffi64.c; sourceTree = "<group>"; };
-		6C43CC281534F7BE00162364 /* closures.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = closures.c; path = src/closures.c; sourceTree = SOURCE_ROOT; };
-		6C43CC2B1534F7BE00162364 /* java_raw_api.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = java_raw_api.c; path = src/java_raw_api.c; sourceTree = SOURCE_ROOT; };
-		6C43CC2C1534F7BE00162364 /* prep_cif.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = prep_cif.c; path = src/prep_cif.c; sourceTree = SOURCE_ROOT; };
-		6C43CC2D1534F7BE00162364 /* raw_api.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = raw_api.c; path = src/raw_api.c; sourceTree = SOURCE_ROOT; };
-		6C43CC2E1534F7BE00162364 /* types.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = types.c; path = src/types.c; sourceTree = SOURCE_ROOT; };
-		6C43CC8D1535032600162364 /* ffi.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ffi.h; sourceTree = "<group>"; };
-		6C43CC8E1535032600162364 /* ffi_common.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ffi_common.h; sourceTree = "<group>"; };
-		6C43CC8F1535032600162364 /* ffi_i386.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ffi_i386.h; sourceTree = "<group>"; };
-		6C43CC901535032600162364 /* ffi_x86_64.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ffi_x86_64.h; sourceTree = "<group>"; };
-		6C43CC911535032600162364 /* fficonfig.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = fficonfig.h; sourceTree = "<group>"; };
-		6C43CC921535032600162364 /* fficonfig_i386.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = fficonfig_i386.h; sourceTree = "<group>"; };
-		6C43CC931535032600162364 /* fficonfig_x86_64.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = fficonfig_x86_64.h; sourceTree = "<group>"; };
-		6C43CC941535032600162364 /* ffitarget.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ffitarget.h; sourceTree = "<group>"; };
-		6C43CC951535032600162364 /* ffitarget_i386.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ffitarget_i386.h; sourceTree = "<group>"; };
-		6C43CC961535032600162364 /* ffitarget_x86_64.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ffitarget_x86_64.h; sourceTree = "<group>"; };
-		6C43CCA21535039600162364 /* ffi.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ffi.h; sourceTree = "<group>"; };
-		6C43CCA31535039600162364 /* ffi_armv7.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ffi_armv7.h; sourceTree = "<group>"; };
-		6C43CCA41535039600162364 /* ffi_common.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ffi_common.h; sourceTree = "<group>"; };
-		6C43CCA51535039600162364 /* ffi_i386.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ffi_i386.h; sourceTree = "<group>"; };
-		6C43CCA61535039600162364 /* fficonfig.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = fficonfig.h; sourceTree = "<group>"; };
-		6C43CCA71535039600162364 /* fficonfig_armv7.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = fficonfig_armv7.h; sourceTree = "<group>"; };
-		6C43CCA81535039600162364 /* fficonfig_i386.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = fficonfig_i386.h; sourceTree = "<group>"; };
-		6C43CCA91535039600162364 /* ffitarget.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ffitarget.h; sourceTree = "<group>"; };
-		6C43CCAA1535039600162364 /* ffitarget_arm.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ffitarget_arm.h; sourceTree = "<group>"; };
-		6C43CCAB1535039600162364 /* ffitarget_armv7.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ffitarget_armv7.h; sourceTree = "<group>"; };
-		6C43CCAC1535039600162364 /* ffitarget_i386.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ffitarget_i386.h; sourceTree = "<group>"; };
-		F6F980BA147386130008F121 /* libffi.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libffi.a; sourceTree = BUILT_PRODUCTS_DIR; };
+		DB13B1661849DF1E0010F42D /* libffi.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libffi.a; sourceTree = BUILT_PRODUCTS_DIR; };
+		DB13B1691849DF1E0010F42D /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
+		DB13B1911849DF510010F42D /* ffi.dylib */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.dylib"; includeInIndex = 0; path = ffi.dylib; sourceTree = BUILT_PRODUCTS_DIR; };
+		DB13B1921849DF510010F42D /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = System/Library/Frameworks/Cocoa.framework; sourceTree = SDKROOT; };
+		DB13B3241849E0CE0010F42D /* ffi.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ffi.h; sourceTree = "<group>"; };
+		DB13B3251849E0CE0010F42D /* ffi_arm.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ffi_arm.h; sourceTree = "<group>"; };
+		DB13B3261849E0CE0010F42D /* ffi_common.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ffi_common.h; sourceTree = "<group>"; };
+		DB13B3271849E0CE0010F42D /* ffi_i386.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ffi_i386.h; sourceTree = "<group>"; };
+		DB13B3281849E0CE0010F42D /* fficonfig.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = fficonfig.h; sourceTree = "<group>"; };
+		DB13B3291849E0CE0010F42D /* fficonfig_arm.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = fficonfig_arm.h; sourceTree = "<group>"; };
+		DB13B32A1849E0CE0010F42D /* fficonfig_i386.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = fficonfig_i386.h; sourceTree = "<group>"; };
+		DB13B32B1849E0CE0010F42D /* ffitarget.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ffitarget.h; sourceTree = "<group>"; };
+		DB13B32C1849E0CE0010F42D /* ffitarget_arm.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ffitarget_arm.h; sourceTree = "<group>"; };
+		DB13B32D1849E0CE0010F42D /* ffitarget_i386.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ffitarget_i386.h; sourceTree = "<group>"; };
+		DB13B3301849E0CE0010F42D /* ffi.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = ffi.c; sourceTree = "<group>"; };
+		DB13B3311849E0CE0010F42D /* sysv.S */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.asm; path = sysv.S; sourceTree = "<group>"; };
+		DB13B3321849E0CE0010F42D /* trampoline.S */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.asm; path = trampoline.S; sourceTree = "<group>"; };
+		DB13B3331849E0CE0010F42D /* closures.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = closures.c; sourceTree = "<group>"; };
+		DB13B3351849E0CE0010F42D /* dlmalloc.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = dlmalloc.c; sourceTree = "<group>"; };
+		DB13B3371849E0CE0010F42D /* prep_cif.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = prep_cif.c; sourceTree = "<group>"; };
+		DB13B3381849E0CE0010F42D /* raw_api.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = raw_api.c; sourceTree = "<group>"; };
+		DB13B3391849E0CE0010F42D /* types.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = types.c; sourceTree = "<group>"; };
+		DB13B33B1849E0CE0010F42D /* darwin.S */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.asm; path = darwin.S; sourceTree = "<group>"; };
+		DB13B33C1849E0CE0010F42D /* ffi.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = ffi.c; sourceTree = "<group>"; };
+		DB13B34C1849E0FF0010F42D /* ffi.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ffi.h; sourceTree = "<group>"; };
+		DB13B34D1849E0FF0010F42D /* ffi_common.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ffi_common.h; sourceTree = "<group>"; };
+		DB13B34E1849E0FF0010F42D /* ffi_i386.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ffi_i386.h; sourceTree = "<group>"; };
+		DB13B34F1849E0FF0010F42D /* ffi_x86_64.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ffi_x86_64.h; sourceTree = "<group>"; };
+		DB13B3501849E0FF0010F42D /* fficonfig.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = fficonfig.h; sourceTree = "<group>"; };
+		DB13B3511849E0FF0010F42D /* fficonfig_i386.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = fficonfig_i386.h; sourceTree = "<group>"; };
+		DB13B3521849E0FF0010F42D /* fficonfig_x86_64.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = fficonfig_x86_64.h; sourceTree = "<group>"; };
+		DB13B3531849E0FF0010F42D /* ffitarget.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ffitarget.h; sourceTree = "<group>"; };
+		DB13B3541849E0FF0010F42D /* ffitarget_i386.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ffitarget_i386.h; sourceTree = "<group>"; };
+		DB13B3551849E0FF0010F42D /* ffitarget_x86_64.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ffitarget_x86_64.h; sourceTree = "<group>"; };
+		DB13B3571849E0FF0010F42D /* closures.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = closures.c; sourceTree = "<group>"; };
+		DB13B3591849E0FF0010F42D /* dlmalloc.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = dlmalloc.c; sourceTree = "<group>"; };
+		DB13B35B1849E0FF0010F42D /* prep_cif.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = prep_cif.c; sourceTree = "<group>"; };
+		DB13B35C1849E0FF0010F42D /* raw_api.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = raw_api.c; sourceTree = "<group>"; };
+		DB13B35D1849E0FF0010F42D /* types.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = types.c; sourceTree = "<group>"; };
+		DB13B35F1849E0FF0010F42D /* darwin.S */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.asm; path = darwin.S; sourceTree = "<group>"; };
+		DB13B3601849E0FF0010F42D /* darwin64.S */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.asm; path = darwin64.S; sourceTree = "<group>"; };
+		DB13B3611849E0FF0010F42D /* ffi.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = ffi.c; sourceTree = "<group>"; };
+		DB13B3621849E0FF0010F42D /* ffi64.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = ffi64.c; sourceTree = "<group>"; };
+		DB13B378184A50BF0010F42D /* ffi_arm64.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ffi_arm64.h; sourceTree = "<group>"; };
+		DB13B379184A50BF0010F42D /* ffi_x86_64.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ffi_x86_64.h; sourceTree = "<group>"; };
+		DB13B37A184A50BF0010F42D /* fficonfig_arm64.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = fficonfig_arm64.h; sourceTree = "<group>"; };
+		DB13B37B184A50BF0010F42D /* fficonfig_x86_64.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = fficonfig_x86_64.h; sourceTree = "<group>"; };
+		DB13B37C184A50BF0010F42D /* ffitarget_arm64.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ffitarget_arm64.h; sourceTree = "<group>"; };
+		DB13B37D184A50BF0010F42D /* ffitarget_x86_64.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ffitarget_x86_64.h; sourceTree = "<group>"; };
+		DB13B37F184A50CC0010F42D /* ffi.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = ffi.c; sourceTree = "<group>"; };
+		DB13B380184A50CC0010F42D /* sysv.S */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.asm; path = sysv.S; sourceTree = "<group>"; };
+		DB13B383184A50D60010F42D /* darwin64.S */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.asm; path = darwin64.S; sourceTree = "<group>"; };
+		DB13B384184A50D60010F42D /* ffi64.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = ffi64.c; sourceTree = "<group>"; };
 /* End PBXFileReference section */
 
 /* Begin PBXFrameworksBuildPhase section */
-		6C43CB3A1534E9D100162364 /* Frameworks */ = {
+		DB13B1631849DF1E0010F42D /* Frameworks */ = {
 			isa = PBXFrameworksBuildPhase;
 			buildActionMask = 2147483647;
 			files = (
+				DB13B16A1849DF1E0010F42D /* Foundation.framework in Frameworks */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};
-		F6F980B7147386130008F121 /* Frameworks */ = {
+		DB13B18E1849DF510010F42D /* Frameworks */ = {
 			isa = PBXFrameworksBuildPhase;
 			buildActionMask = 2147483647;
 			files = (
+				DB13B1931849DF510010F42D /* Cocoa.framework in Frameworks */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};
 /* End PBXFrameworksBuildPhase section */
 
 /* Begin PBXGroup section */
-		6C43CBAF1534F76F00162364 /* iOS */ = {
+		DB13B15B1849DEB70010F42D = {
 			isa = PBXGroup;
 			children = (
-				6C43CCA11535039600162364 /* include */,
-				6C43CBBB1534F76F00162364 /* src */,
+				DB13B3221849E0CE0010F42D /* ios */,
+				DB13B34A1849E0FF0010F42D /* osx */,
+				DB13B1681849DF1E0010F42D /* Frameworks */,
+				DB13B1671849DF1E0010F42D /* Products */,
 			);
-			name = iOS;
-			path = ios;
 			sourceTree = "<group>";
 		};
-		6C43CBBB1534F76F00162364 /* src */ = {
+		DB13B1671849DF1E0010F42D /* Products */ = {
 			isa = PBXGroup;
 			children = (
-				6C43CBC81534F76F00162364 /* x86 */,
-				6C43CBBC1534F76F00162364 /* arm */,
+				DB13B1661849DF1E0010F42D /* libffi.a */,
+				DB13B1911849DF510010F42D /* ffi.dylib */,
 			);
-			path = src;
+			name = Products;
 			sourceTree = "<group>";
 		};
-		6C43CBBC1534F76F00162364 /* arm */ = {
+		DB13B1681849DF1E0010F42D /* Frameworks */ = {
 			isa = PBXGroup;
 			children = (
-				6C43CBBD1534F76F00162364 /* ffi.c */,
-				6C43CBBF1534F76F00162364 /* sysv.S */,
-				6C43CBC01534F76F00162364 /* trampoline.S */,
+				DB13B1691849DF1E0010F42D /* Foundation.framework */,
+				DB13B1921849DF510010F42D /* Cocoa.framework */,
 			);
-			path = arm;
+			name = Frameworks;
 			sourceTree = "<group>";
 		};
-		6C43CBC81534F76F00162364 /* x86 */ = {
+		DB13B3221849E0CE0010F42D /* ios */ = {
 			isa = PBXGroup;
 			children = (
-				6C43CBC91534F76F00162364 /* darwin.S */,
-				6C43CBCB1534F76F00162364 /* ffi.c */,
+				DB13B3231849E0CE0010F42D /* include */,
+				DB13B32E1849E0CE0010F42D /* src */,
 			);
-			path = x86;
+			path = ios;
 			sourceTree = "<group>";
 		};
-		6C43CBF01534F77800162364 /* OS X */ = {
+		DB13B3231849E0CE0010F42D /* include */ = {
 			isa = PBXGroup;
 			children = (
-				6C43CC8C1535032600162364 /* include */,
-				6C43CBFC1534F77800162364 /* src */,
+				DB13B3241849E0CE0010F42D /* ffi.h */,
+				DB13B3251849E0CE0010F42D /* ffi_arm.h */,
+				DB13B378184A50BF0010F42D /* ffi_arm64.h */,
+				DB13B3261849E0CE0010F42D /* ffi_common.h */,
+				DB13B3271849E0CE0010F42D /* ffi_i386.h */,
+				DB13B379184A50BF0010F42D /* ffi_x86_64.h */,
+				DB13B3281849E0CE0010F42D /* fficonfig.h */,
+				DB13B3291849E0CE0010F42D /* fficonfig_arm.h */,
+				DB13B37A184A50BF0010F42D /* fficonfig_arm64.h */,
+				DB13B32A1849E0CE0010F42D /* fficonfig_i386.h */,
+				DB13B37B184A50BF0010F42D /* fficonfig_x86_64.h */,
+				DB13B32B1849E0CE0010F42D /* ffitarget.h */,
+				DB13B32C1849E0CE0010F42D /* ffitarget_arm.h */,
+				DB13B37C184A50BF0010F42D /* ffitarget_arm64.h */,
+				DB13B32D1849E0CE0010F42D /* ffitarget_i386.h */,
+				DB13B37D184A50BF0010F42D /* ffitarget_x86_64.h */,
 			);
-			name = "OS X";
-			path = osx;
+			path = include;
 			sourceTree = "<group>";
 		};
-		6C43CBFC1534F77800162364 /* src */ = {
+		DB13B32E1849E0CE0010F42D /* src */ = {
 			isa = PBXGroup;
 			children = (
-				6C43CC041534F77800162364 /* x86 */,
+				DB13B37E184A50CC0010F42D /* aarch64 */,
+				DB13B32F1849E0CE0010F42D /* arm */,
+				DB13B3331849E0CE0010F42D /* closures.c */,
+				DB13B3351849E0CE0010F42D /* dlmalloc.c */,
+				DB13B3371849E0CE0010F42D /* prep_cif.c */,
+				DB13B3381849E0CE0010F42D /* raw_api.c */,
+				DB13B3391849E0CE0010F42D /* types.c */,
+				DB13B33A1849E0CE0010F42D /* x86 */,
 			);
 			path = src;
 			sourceTree = "<group>";
 		};
-		6C43CC041534F77800162364 /* x86 */ = {
+		DB13B32F1849E0CE0010F42D /* arm */ = {
 			isa = PBXGroup;
 			children = (
-				6C43CC051534F77800162364 /* darwin.S */,
-				6C43CC061534F77800162364 /* darwin64.S */,
-				6C43CC071534F77800162364 /* ffi.c */,
-				6C43CC081534F77800162364 /* ffi64.c */,
+				DB13B3301849E0CE0010F42D /* ffi.c */,
+				DB13B3311849E0CE0010F42D /* sysv.S */,
+				DB13B3321849E0CE0010F42D /* trampoline.S */,
+			);
+			path = arm;
+			sourceTree = "<group>";
+		};
+		DB13B33A1849E0CE0010F42D /* x86 */ = {
+			isa = PBXGroup;
+			children = (
+				DB13B33B1849E0CE0010F42D /* darwin.S */,
+				DB13B383184A50D60010F42D /* darwin64.S */,
+				DB13B33C1849E0CE0010F42D /* ffi.c */,
+				DB13B384184A50D60010F42D /* ffi64.c */,
 			);
 			path = x86;
 			sourceTree = "<group>";
 		};
-		6C43CC3D1534F7C400162364 /* src */ = {
+		DB13B34A1849E0FF0010F42D /* osx */ = {
 			isa = PBXGroup;
 			children = (
-				6C43CC281534F7BE00162364 /* closures.c */,
-				6C43CC2B1534F7BE00162364 /* java_raw_api.c */,
-				6C43CC2C1534F7BE00162364 /* prep_cif.c */,
-				6C43CC2D1534F7BE00162364 /* raw_api.c */,
-				6C43CC2E1534F7BE00162364 /* types.c */,
+				DB13B34B1849E0FF0010F42D /* include */,
+				DB13B3561849E0FF0010F42D /* src */,
 			);
-			name = src;
-			path = ios;
+			path = osx;
 			sourceTree = "<group>";
 		};
-		6C43CC8C1535032600162364 /* include */ = {
+		DB13B34B1849E0FF0010F42D /* include */ = {
 			isa = PBXGroup;
 			children = (
-				6C43CC8D1535032600162364 /* ffi.h */,
-				6C43CC8E1535032600162364 /* ffi_common.h */,
-				6C43CC8F1535032600162364 /* ffi_i386.h */,
-				6C43CC901535032600162364 /* ffi_x86_64.h */,
-				6C43CC911535032600162364 /* fficonfig.h */,
-				6C43CC921535032600162364 /* fficonfig_i386.h */,
-				6C43CC931535032600162364 /* fficonfig_x86_64.h */,
-				6C43CC941535032600162364 /* ffitarget.h */,
-				6C43CC951535032600162364 /* ffitarget_i386.h */,
-				6C43CC961535032600162364 /* ffitarget_x86_64.h */,
+				DB13B34C1849E0FF0010F42D /* ffi.h */,
+				DB13B34D1849E0FF0010F42D /* ffi_common.h */,
+				DB13B34E1849E0FF0010F42D /* ffi_i386.h */,
+				DB13B34F1849E0FF0010F42D /* ffi_x86_64.h */,
+				DB13B3501849E0FF0010F42D /* fficonfig.h */,
+				DB13B3511849E0FF0010F42D /* fficonfig_i386.h */,
+				DB13B3521849E0FF0010F42D /* fficonfig_x86_64.h */,
+				DB13B3531849E0FF0010F42D /* ffitarget.h */,
+				DB13B3541849E0FF0010F42D /* ffitarget_i386.h */,
+				DB13B3551849E0FF0010F42D /* ffitarget_x86_64.h */,
 			);
 			path = include;
 			sourceTree = "<group>";
 		};
-		6C43CCA11535039600162364 /* include */ = {
+		DB13B3561849E0FF0010F42D /* src */ = {
 			isa = PBXGroup;
 			children = (
-				6C43CCA21535039600162364 /* ffi.h */,
-				6C43CCA31535039600162364 /* ffi_armv7.h */,
-				6C43CCA41535039600162364 /* ffi_common.h */,
-				6C43CCA51535039600162364 /* ffi_i386.h */,
-				6C43CCA61535039600162364 /* fficonfig.h */,
-				6C43CCA71535039600162364 /* fficonfig_armv7.h */,
-				6C43CCA81535039600162364 /* fficonfig_i386.h */,
-				6C43CCA91535039600162364 /* ffitarget.h */,
-				6C43CCAA1535039600162364 /* ffitarget_arm.h */,
-				6C43CCAB1535039600162364 /* ffitarget_armv7.h */,
-				6C43CCAC1535039600162364 /* ffitarget_i386.h */,
+				DB13B3571849E0FF0010F42D /* closures.c */,
+				DB13B3591849E0FF0010F42D /* dlmalloc.c */,
+				DB13B35B1849E0FF0010F42D /* prep_cif.c */,
+				DB13B35C1849E0FF0010F42D /* raw_api.c */,
+				DB13B35D1849E0FF0010F42D /* types.c */,
+				DB13B35E1849E0FF0010F42D /* x86 */,
 			);
-			path = include;
+			path = src;
 			sourceTree = "<group>";
 		};
-		F6B0839514721EE50031D8A1 = {
+		DB13B35E1849E0FF0010F42D /* x86 */ = {
 			isa = PBXGroup;
 			children = (
-				6C43CC3D1534F7C400162364 /* src */,
-				6C43CBAF1534F76F00162364 /* iOS */,
-				6C43CBF01534F77800162364 /* OS X */,
-				F6F980C6147386260008F121 /* Products */,
+				DB13B35F1849E0FF0010F42D /* darwin.S */,
+				DB13B3601849E0FF0010F42D /* darwin64.S */,
+				DB13B3611849E0FF0010F42D /* ffi.c */,
+				DB13B3621849E0FF0010F42D /* ffi64.c */,
 			);
+			path = x86;
 			sourceTree = "<group>";
 		};
-		F6F980C6147386260008F121 /* Products */ = {
+		DB13B37E184A50CC0010F42D /* aarch64 */ = {
 			isa = PBXGroup;
 			children = (
-				F6F980BA147386130008F121 /* libffi.a */,
-				6C43CB3D1534E9D100162364 /* libffi.a */,
+				DB13B37F184A50CC0010F42D /* ffi.c */,
+				DB13B380184A50CC0010F42D /* sysv.S */,
 			);
-			name = Products;
-			path = ../..;
-			sourceTree = BUILT_PRODUCTS_DIR;
+			path = aarch64;
+			sourceTree = "<group>";
 		};
 /* End PBXGroup section */
 
 /* Begin PBXHeadersBuildPhase section */
-		6C43CB3B1534E9D100162364 /* Headers */ = {
-			isa = PBXHeadersBuildPhase;
-			buildActionMask = 2147483647;
-			files = (
-				6C43CC971535032600162364 /* ffi.h in Headers */,
-				6C43CC981535032600162364 /* ffi_common.h in Headers */,
-				6C43CC991535032600162364 /* ffi_i386.h in Headers */,
-				6C43CC9A1535032600162364 /* ffi_x86_64.h in Headers */,
-				6C43CC9E1535032600162364 /* ffitarget.h in Headers */,
-				6C43CC9F1535032600162364 /* ffitarget_i386.h in Headers */,
-				6C43CCA01535032600162364 /* ffitarget_x86_64.h in Headers */,
-				6C43CC9B1535032600162364 /* fficonfig.h in Headers */,
-				6C43CC9C1535032600162364 /* fficonfig_i386.h in Headers */,
-				6C43CC9D1535032600162364 /* fficonfig_x86_64.h in Headers */,
-			);
-			runOnlyForDeploymentPostprocessing = 0;
-		};
-		F6F980B8147386130008F121 /* Headers */ = {
+		DB13B18F1849DF510010F42D /* Headers */ = {
 			isa = PBXHeadersBuildPhase;
 			buildActionMask = 2147483647;
 			files = (
-				6C43CCAD1535039600162364 /* ffi.h in Headers */,
-				6C43CCAE1535039600162364 /* ffi_armv7.h in Headers */,
-				6C43CCAF1535039600162364 /* ffi_common.h in Headers */,
-				6C43CCB01535039600162364 /* ffi_i386.h in Headers */,
-				6C43CCB41535039600162364 /* ffitarget.h in Headers */,
-				6C43CCB51535039600162364 /* ffitarget_arm.h in Headers */,
-				6C43CCB61535039600162364 /* ffitarget_armv7.h in Headers */,
-				6C43CCB71535039600162364 /* ffitarget_i386.h in Headers */,
-				6C43CCB11535039600162364 /* fficonfig.h in Headers */,
-				6C43CCB21535039600162364 /* fficonfig_armv7.h in Headers */,
-				6C43CCB31535039600162364 /* fficonfig_i386.h in Headers */,
+				DB13B3681849E0FF0010F42D /* fficonfig_i386.h in Headers */,
+				DB13B3651849E0FF0010F42D /* ffi_i386.h in Headers */,
+				DB13B36B1849E0FF0010F42D /* ffitarget_i386.h in Headers */,
+				DB13B3691849E0FF0010F42D /* fficonfig_x86_64.h in Headers */,
+				DB13B3661849E0FF0010F42D /* ffi_x86_64.h in Headers */,
+				DB13B3631849E0FF0010F42D /* ffi.h in Headers */,
+				DB13B36A1849E0FF0010F42D /* ffitarget.h in Headers */,
+				DB13B3641849E0FF0010F42D /* ffi_common.h in Headers */,
+				DB13B36C1849E0FF0010F42D /* ffitarget_x86_64.h in Headers */,
+				DB13B3671849E0FF0010F42D /* fficonfig.h in Headers */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};
 /* End PBXHeadersBuildPhase section */
 
 /* Begin PBXNativeTarget section */
-		6C43CB3C1534E9D100162364 /* libffi OS X */ = {
+		DB13B1651849DF1E0010F42D /* libffi-iOS */ = {
 			isa = PBXNativeTarget;
-			buildConfigurationList = 6C43CB4A1534E9D100162364 /* Build configuration list for PBXNativeTarget "libffi OS X" */;
+			buildConfigurationList = DB13B18B1849DF1E0010F42D /* Build configuration list for PBXNativeTarget "libffi-iOS" */;
 			buildPhases = (
-				6C43CC401534FF3B00162364 /* Generate Source and Headers */,
-				6C43CB391534E9D100162364 /* Sources */,
-				6C43CB3A1534E9D100162364 /* Frameworks */,
-				6C43CB3B1534E9D100162364 /* Headers */,
+				DB13B3051849E01C0010F42D /* ShellScript */,
+				DB13B1621849DF1E0010F42D /* Sources */,
+				DB13B1631849DF1E0010F42D /* Frameworks */,
+				DB13B1641849DF1E0010F42D /* CopyFiles */,
 			);
 			buildRules = (
 			);
 			dependencies = (
 			);
-			name = "libffi OS X";
-			productName = "ffi OS X";
-			productReference = 6C43CB3D1534E9D100162364 /* libffi.a */;
+			name = "libffi-iOS";
+			productName = ffi;
+			productReference = DB13B1661849DF1E0010F42D /* libffi.a */;
 			productType = "com.apple.product-type.library.static";
 		};
-		F6F980B9147386130008F121 /* libffi iOS */ = {
+		DB13B1901849DF510010F42D /* libffi-Mac */ = {
 			isa = PBXNativeTarget;
-			buildConfigurationList = F6F980C4147386130008F121 /* Build configuration list for PBXNativeTarget "libffi iOS" */;
+			buildConfigurationList = DB13B1B01849DF520010F42D /* Build configuration list for PBXNativeTarget "libffi-Mac" */;
 			buildPhases = (
-				6C43CC3E1534F8E200162364 /* Generate Trampoline */,
-				6C43CC3F1534FF1B00162364 /* Generate Source and Headers */,
-				F6F980B6147386130008F121 /* Sources */,
-				F6F980B7147386130008F121 /* Frameworks */,
-				F6F980B8147386130008F121 /* Headers */,
+				DB13B3061849E0490010F42D /* ShellScript */,
+				DB13B18D1849DF510010F42D /* Sources */,
+				DB13B18E1849DF510010F42D /* Frameworks */,
+				DB13B18F1849DF510010F42D /* Headers */,
 			);
 			buildRules = (
 			);
 			dependencies = (
 			);
-			name = "libffi iOS";
+			name = "libffi-Mac";
 			productName = ffi;
-			productReference = F6F980BA147386130008F121 /* libffi.a */;
-			productType = "com.apple.product-type.library.static";
+			productReference = DB13B1911849DF510010F42D /* ffi.dylib */;
+			productType = "com.apple.product-type.library.dynamic";
 		};
 /* End PBXNativeTarget section */
 
 /* Begin PBXProject section */
-		F6B0839714721EE50031D8A1 /* Project object */ = {
+		DB13B15C1849DEB70010F42D /* Project object */ = {
 			isa = PBXProject;
 			attributes = {
-				LastUpgradeCheck = 0430;
+				LastUpgradeCheck = 0510;
 			};
-			buildConfigurationList = F6B0839A14721EE50031D8A1 /* Build configuration list for PBXProject "libffi" */;
+			buildConfigurationList = DB13B15F1849DEB70010F42D /* Build configuration list for PBXProject "libffi" */;
 			compatibilityVersion = "Xcode 3.2";
 			developmentRegion = English;
 			hasScannedForEncodings = 0;
 			knownRegions = (
 				en,
 			);
-			mainGroup = F6B0839514721EE50031D8A1;
-			productRefGroup = F6B0839514721EE50031D8A1;
+			mainGroup = DB13B15B1849DEB70010F42D;
+			productRefGroup = DB13B1671849DF1E0010F42D /* Products */;
 			projectDirPath = "";
 			projectRoot = "";
 			targets = (
-				F6F980B9147386130008F121 /* libffi iOS */,
-				6C43CB3C1534E9D100162364 /* libffi OS X */,
+				DB13B1651849DF1E0010F42D /* libffi-iOS */,
+				DB13B1901849DF510010F42D /* libffi-Mac */,
 			);
 		};
 /* End PBXProject section */
 
 /* Begin PBXShellScriptBuildPhase section */
-		6C43CC3E1534F8E200162364 /* Generate Trampoline */ = {
-			isa = PBXShellScriptBuildPhase;
-			buildActionMask = 2147483647;
-			files = (
-			);
-			inputPaths = (
-			);
-			name = "Generate Trampoline";
-			outputPaths = (
-			);
-			runOnlyForDeploymentPostprocessing = 0;
-			shellPath = /usr/bin/python;
-			shellScript = "import subprocess\nimport re\nimport os\nimport errno\nimport sys\n\ndef main():\n    with open('src/arm/trampoline.S', 'w') as tramp_out:\n        p = subprocess.Popen(['bash', 'src/arm/gentramp.sh'], stdout=tramp_out)\n        p.wait()\n\nif __name__ == '__main__':\n    main()";
-		};
-		6C43CC3F1534FF1B00162364 /* Generate Source and Headers */ = {
+		DB13B3051849E01C0010F42D /* ShellScript */ = {
 			isa = PBXShellScriptBuildPhase;
 			buildActionMask = 2147483647;
 			files = (
 			);
 			inputPaths = (
 			);
-			name = "Generate Source and Headers";
 			outputPaths = (
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 			shellPath = /bin/sh;
 			shellScript = "/usr/bin/python generate-ios-source-and-headers.py";
 		};
-		6C43CC401534FF3B00162364 /* Generate Source and Headers */ = {
+		DB13B3061849E0490010F42D /* ShellScript */ = {
 			isa = PBXShellScriptBuildPhase;
 			buildActionMask = 2147483647;
 			files = (
 			);
 			inputPaths = (
 			);
-			name = "Generate Source and Headers";
 			outputPaths = (
 			);
 			runOnlyForDeploymentPostprocessing = 0;
@@ -392,88 +432,75 @@
 /* End PBXShellScriptBuildPhase section */
 
 /* Begin PBXSourcesBuildPhase section */
-		6C43CB391534E9D100162364 /* Sources */ = {
+		DB13B1621849DF1E0010F42D /* Sources */ = {
 			isa = PBXSourcesBuildPhase;
 			buildActionMask = 2147483647;
 			files = (
-				6C43CC1F1534F77800162364 /* darwin.S in Sources */,
-				6C43CC201534F77800162364 /* darwin64.S in Sources */,
-				6C43CC211534F77800162364 /* ffi.c in Sources */,
-				6C43CC221534F77800162364 /* ffi64.c in Sources */,
-				6C43CC301534F7BE00162364 /* closures.c in Sources */,
-				6C43CC361534F7BE00162364 /* java_raw_api.c in Sources */,
-				6C43CC381534F7BE00162364 /* prep_cif.c in Sources */,
-				6C43CC3A1534F7BE00162364 /* raw_api.c in Sources */,
-				6C43CC3C1534F7BE00162364 /* types.c in Sources */,
+				DB13B3461849E0CE0010F42D /* types.c in Sources */,
+				DB13B33E1849E0CE0010F42D /* sysv.S in Sources */,
+				DB13B3451849E0CE0010F42D /* raw_api.c in Sources */,
+				DB13B382184A50CC0010F42D /* sysv.S in Sources */,
+				DB13B3401849E0CE0010F42D /* closures.c in Sources */,
+				DB13B33F1849E0CE0010F42D /* trampoline.S in Sources */,
+				DB13B386184A50D60010F42D /* ffi64.c in Sources */,
+				DB13B385184A50D60010F42D /* darwin64.S in Sources */,
+				DB13B33D1849E0CE0010F42D /* ffi.c in Sources */,
+				DB13B3481849E0CE0010F42D /* ffi.c in Sources */,
+				DB13B381184A50CC0010F42D /* ffi.c in Sources */,
+				DB13B3471849E0CE0010F42D /* darwin.S in Sources */,
+				DB13B3441849E0CE0010F42D /* prep_cif.c in Sources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};
-		F6F980B6147386130008F121 /* Sources */ = {
+		DB13B18D1849DF510010F42D /* Sources */ = {
 			isa = PBXSourcesBuildPhase;
 			buildActionMask = 2147483647;
 			files = (
-				6C43CBDC1534F76F00162364 /* ffi.c in Sources */,
-				6C43CBDD1534F76F00162364 /* sysv.S in Sources */,
-				6C43CBDE1534F76F00162364 /* trampoline.S in Sources */,
-				6C43CBE61534F76F00162364 /* darwin.S in Sources */,
-				6C43CBE81534F76F00162364 /* ffi.c in Sources */,
-				6C43CC2F1534F7BE00162364 /* closures.c in Sources */,
-				6C43CC351534F7BE00162364 /* java_raw_api.c in Sources */,
-				6C43CC371534F7BE00162364 /* prep_cif.c in Sources */,
-				6C43CC391534F7BE00162364 /* raw_api.c in Sources */,
-				6C43CC3B1534F7BE00162364 /* types.c in Sources */,
+				DB13B3761849E0FF0010F42D /* ffi.c in Sources */,
+				DB13B3731849E0FF0010F42D /* types.c in Sources */,
+				DB13B3721849E0FF0010F42D /* raw_api.c in Sources */,
+				DB13B3711849E0FF0010F42D /* prep_cif.c in Sources */,
+				DB13B36D1849E0FF0010F42D /* closures.c in Sources */,
+				DB13B3741849E0FF0010F42D /* darwin.S in Sources */,
+				DB13B3771849E0FF0010F42D /* ffi64.c in Sources */,
+				DB13B3751849E0FF0010F42D /* darwin64.S in Sources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};
 /* End PBXSourcesBuildPhase section */
 
 /* Begin XCBuildConfiguration section */
-		6C43CB4B1534E9D100162364 /* Debug */ = {
+		DB13B1601849DEB70010F42D /* Debug */ = {
 			isa = XCBuildConfiguration;
 			buildSettings = {
-				ARCHS = "$(ARCHS_STANDARD_32_64_BIT)";
-				DSTROOT = /tmp/ffi.dst;
-				FRAMEWORK_SEARCH_PATHS = (
-					"$(inherited)",
-					"\"$(SYSTEM_APPS_DIR)/Xcode.app/Contents/Developer/Library/Frameworks\"",
-				);
-				GCC_ENABLE_OBJC_EXCEPTIONS = YES;
-				GCC_VERSION = com.apple.compilers.llvm.clang.1_0;
-				GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
-				GCC_WARN_UNINITIALIZED_AUTOS = YES;
-				MACOSX_DEPLOYMENT_TARGET = 10.6;
-				ONLY_ACTIVE_ARCH = YES;
-				PRODUCT_NAME = ffi;
-				SDKROOT = macosx;
 			};
 			name = Debug;
 		};
-		6C43CB4C1534E9D100162364 /* Release */ = {
+		DB13B1611849DEB70010F42D /* Release */ = {
 			isa = XCBuildConfiguration;
 			buildSettings = {
-				ARCHS = "$(ARCHS_STANDARD_32_64_BIT)";
-				DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
-				DSTROOT = /tmp/ffi.dst;
-				FRAMEWORK_SEARCH_PATHS = (
-					"$(inherited)",
-					"\"$(SYSTEM_APPS_DIR)/Xcode.app/Contents/Developer/Library/Frameworks\"",
-				);
-				GCC_ENABLE_OBJC_EXCEPTIONS = YES;
-				GCC_VERSION = com.apple.compilers.llvm.clang.1_0;
-				GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
-				GCC_WARN_UNINITIALIZED_AUTOS = YES;
-				MACOSX_DEPLOYMENT_TARGET = 10.6;
-				PRODUCT_NAME = ffi;
-				SDKROOT = macosx;
 			};
 			name = Release;
 		};
-		F6B083AB14721EE50031D8A1 /* Debug */ = {
+		DB13B1871849DF1E0010F42D /* Debug */ = {
 			isa = XCBuildConfiguration;
 			buildSettings = {
 				ALWAYS_SEARCH_USER_PATHS = NO;
-				ARCHS = "$(ARCHS_STANDARD_32_BIT)";
+				ARCHS = "$(ARCHS_STANDARD_INCLUDING_64_BIT)";
+				CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
+				CLANG_CXX_LIBRARY = "libc++";
+				CLANG_ENABLE_MODULES = YES;
+				CLANG_ENABLE_OBJC_ARC = YES;
+				CLANG_WARN_BOOL_CONVERSION = YES;
+				CLANG_WARN_CONSTANT_CONVERSION = YES;
+				CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
+				CLANG_WARN_EMPTY_BODY = YES;
+				CLANG_WARN_ENUM_CONVERSION = YES;
+				CLANG_WARN_INT_CONVERSION = YES;
+				CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
+				CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
 				COPY_PHASE_STRIP = NO;
+				DSTROOT = /tmp/ffi.dst;
 				GCC_C_LANGUAGE_STANDARD = gnu99;
 				GCC_DYNAMIC_NO_PIC = NO;
 				GCC_OPTIMIZATION_LEVEL = 0;
@@ -482,98 +509,182 @@
 					"$(inherited)",
 				);
 				GCC_SYMBOLS_PRIVATE_EXTERN = NO;
-				GCC_WARN_ABOUT_MISSING_PROTOTYPES = NO;
-				GCC_WARN_ABOUT_RETURN_TYPE = YES;
-				GCC_WARN_UNUSED_VALUE = NO;
+				GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
+				GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
+				GCC_WARN_UNDECLARED_SELECTOR = YES;
+				GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
+				GCC_WARN_UNUSED_FUNCTION = YES;
 				GCC_WARN_UNUSED_VARIABLE = YES;
-				HEADER_SEARCH_PATHS = ios/include;
+				HEADER_SEARCH_PATHS = (
+					"$(inherited)",
+					ios/include,
+				);
+				IPHONEOS_DEPLOYMENT_TARGET = 6.0;
+				ONLY_ACTIVE_ARCH = YES;
+				OTHER_LDFLAGS = "-ObjC";
+				PRODUCT_NAME = ffi;
 				SDKROOT = iphoneos;
+				SKIP_INSTALL = YES;
 			};
 			name = Debug;
 		};
-		F6B083AC14721EE50031D8A1 /* Release */ = {
+		DB13B1881849DF1E0010F42D /* Release */ = {
 			isa = XCBuildConfiguration;
 			buildSettings = {
 				ALWAYS_SEARCH_USER_PATHS = NO;
-				ARCHS = "$(ARCHS_STANDARD_32_BIT)";
+				ARCHS = "$(ARCHS_STANDARD_INCLUDING_64_BIT)";
+				CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
+				CLANG_CXX_LIBRARY = "libc++";
+				CLANG_ENABLE_MODULES = YES;
+				CLANG_ENABLE_OBJC_ARC = YES;
+				CLANG_WARN_BOOL_CONVERSION = YES;
+				CLANG_WARN_CONSTANT_CONVERSION = YES;
+				CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
+				CLANG_WARN_EMPTY_BODY = YES;
+				CLANG_WARN_ENUM_CONVERSION = YES;
+				CLANG_WARN_INT_CONVERSION = YES;
+				CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
+				CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
 				COPY_PHASE_STRIP = YES;
+				DSTROOT = /tmp/ffi.dst;
+				ENABLE_NS_ASSERTIONS = NO;
 				GCC_C_LANGUAGE_STANDARD = gnu99;
-				GCC_PREPROCESSOR_DEFINITIONS = "";
-				GCC_WARN_ABOUT_MISSING_PROTOTYPES = NO;
-				GCC_WARN_ABOUT_RETURN_TYPE = YES;
-				GCC_WARN_UNUSED_VALUE = NO;
+				GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
+				GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
+				GCC_WARN_UNDECLARED_SELECTOR = YES;
+				GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
+				GCC_WARN_UNUSED_FUNCTION = YES;
 				GCC_WARN_UNUSED_VARIABLE = YES;
-				HEADER_SEARCH_PATHS = ios/include;
+				HEADER_SEARCH_PATHS = (
+					"$(inherited)",
+					ios/include,
+				);
+				IPHONEOS_DEPLOYMENT_TARGET = 6.0;
+				OTHER_LDFLAGS = "-ObjC";
+				PRODUCT_NAME = ffi;
 				SDKROOT = iphoneos;
+				SKIP_INSTALL = YES;
 				VALIDATE_PRODUCT = YES;
 			};
 			name = Release;
 		};
-		F6F980C2147386130008F121 /* Debug */ = {
+		DB13B1B11849DF520010F42D /* Debug */ = {
 			isa = XCBuildConfiguration;
 			buildSettings = {
-				ARCHS = (
-					armv6,
-					armv7,
+				ALWAYS_SEARCH_USER_PATHS = NO;
+				ARCHS = "$(ARCHS_STANDARD_32_64_BIT)";
+				CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
+				CLANG_CXX_LIBRARY = "libc++";
+				CLANG_ENABLE_OBJC_ARC = YES;
+				CLANG_WARN_BOOL_CONVERSION = YES;
+				CLANG_WARN_CONSTANT_CONVERSION = YES;
+				CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
+				CLANG_WARN_EMPTY_BODY = YES;
+				CLANG_WARN_ENUM_CONVERSION = YES;
+				CLANG_WARN_INT_CONVERSION = YES;
+				CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
+				CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
+				COPY_PHASE_STRIP = NO;
+				DYLIB_COMPATIBILITY_VERSION = 1;
+				DYLIB_CURRENT_VERSION = 1;
+				GCC_C_LANGUAGE_STANDARD = gnu99;
+				GCC_DYNAMIC_NO_PIC = NO;
+				GCC_ENABLE_OBJC_EXCEPTIONS = YES;
+				GCC_OPTIMIZATION_LEVEL = 0;
+				GCC_PREPROCESSOR_DEFINITIONS = (
+					"DEBUG=1",
+					"$(inherited)",
 				);
-				DSTROOT = /tmp/ffi.dst;
-				GCC_PRECOMPILE_PREFIX_HEADER = YES;
-				GCC_THUMB_SUPPORT = NO;
-				IPHONEOS_DEPLOYMENT_TARGET = 4.0;
-				OTHER_LDFLAGS = "-ObjC";
+				GCC_SYMBOLS_PRIVATE_EXTERN = NO;
+				GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
+				GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
+				GCC_WARN_UNDECLARED_SELECTOR = YES;
+				GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
+				GCC_WARN_UNUSED_FUNCTION = YES;
+				GCC_WARN_UNUSED_VARIABLE = YES;
+				HEADER_SEARCH_PATHS = (
+					"$(inherited)",
+					osx/include,
+				);
+				MACOSX_DEPLOYMENT_TARGET = 10.7;
+				ONLY_ACTIVE_ARCH = YES;
+				OTHER_LDFLAGS = "-Wl,-no_compact_unwind";
 				PRODUCT_NAME = ffi;
-				SKIP_INSTALL = YES;
+				SDKROOT = macosx;
 			};
 			name = Debug;
 		};
-		F6F980C3147386130008F121 /* Release */ = {
+		DB13B1B21849DF520010F42D /* Release */ = {
 			isa = XCBuildConfiguration;
 			buildSettings = {
-				ARCHS = (
-					armv6,
-					armv7,
+				ALWAYS_SEARCH_USER_PATHS = NO;
+				ARCHS = "$(ARCHS_STANDARD_32_64_BIT)";
+				CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
+				CLANG_CXX_LIBRARY = "libc++";
+				CLANG_ENABLE_OBJC_ARC = YES;
+				CLANG_WARN_BOOL_CONVERSION = YES;
+				CLANG_WARN_CONSTANT_CONVERSION = YES;
+				CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
+				CLANG_WARN_EMPTY_BODY = YES;
+				CLANG_WARN_ENUM_CONVERSION = YES;
+				CLANG_WARN_INT_CONVERSION = YES;
+				CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
+				CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
+				COPY_PHASE_STRIP = YES;
+				DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
+				DYLIB_COMPATIBILITY_VERSION = 1;
+				DYLIB_CURRENT_VERSION = 1;
+				ENABLE_NS_ASSERTIONS = NO;
+				GCC_C_LANGUAGE_STANDARD = gnu99;
+				GCC_ENABLE_OBJC_EXCEPTIONS = YES;
+				GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
+				GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
+				GCC_WARN_UNDECLARED_SELECTOR = YES;
+				GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
+				GCC_WARN_UNUSED_FUNCTION = YES;
+				GCC_WARN_UNUSED_VARIABLE = YES;
+				HEADER_SEARCH_PATHS = (
+					"$(inherited)",
+					osx/include,
 				);
-				DSTROOT = /tmp/ffi.dst;
-				GCC_PRECOMPILE_PREFIX_HEADER = YES;
-				GCC_THUMB_SUPPORT = NO;
-				IPHONEOS_DEPLOYMENT_TARGET = 4.0;
-				OTHER_LDFLAGS = "-ObjC";
+				MACOSX_DEPLOYMENT_TARGET = 10.7;
+				OTHER_LDFLAGS = "-Wl,-no_compact_unwind";
 				PRODUCT_NAME = ffi;
-				SKIP_INSTALL = YES;
+				SDKROOT = macosx;
 			};
 			name = Release;
 		};
 /* End XCBuildConfiguration section */
 
 /* Begin XCConfigurationList section */
-		6C43CB4A1534E9D100162364 /* Build configuration list for PBXNativeTarget "libffi OS X" */ = {
+		DB13B15F1849DEB70010F42D /* Build configuration list for PBXProject "libffi" */ = {
 			isa = XCConfigurationList;
 			buildConfigurations = (
-				6C43CB4B1534E9D100162364 /* Debug */,
-				6C43CB4C1534E9D100162364 /* Release */,
+				DB13B1601849DEB70010F42D /* Debug */,
+				DB13B1611849DEB70010F42D /* Release */,
 			);
 			defaultConfigurationIsVisible = 0;
 			defaultConfigurationName = Release;
 		};
-		F6B0839A14721EE50031D8A1 /* Build configuration list for PBXProject "libffi" */ = {
+		DB13B18B1849DF1E0010F42D /* Build configuration list for PBXNativeTarget "libffi-iOS" */ = {
 			isa = XCConfigurationList;
 			buildConfigurations = (
-				F6B083AB14721EE50031D8A1 /* Debug */,
-				F6B083AC14721EE50031D8A1 /* Release */,
+				DB13B1871849DF1E0010F42D /* Debug */,
+				DB13B1881849DF1E0010F42D /* Release */,
 			);
 			defaultConfigurationIsVisible = 0;
 			defaultConfigurationName = Release;
 		};
-		F6F980C4147386130008F121 /* Build configuration list for PBXNativeTarget "libffi iOS" */ = {
+		DB13B1B01849DF520010F42D /* Build configuration list for PBXNativeTarget "libffi-Mac" */ = {
 			isa = XCConfigurationList;
 			buildConfigurations = (
-				F6F980C2147386130008F121 /* Debug */,
-				F6F980C3147386130008F121 /* Release */,
+				DB13B1B11849DF520010F42D /* Debug */,
+				DB13B1B21849DF520010F42D /* Release */,
 			);
 			defaultConfigurationIsVisible = 0;
 			defaultConfigurationName = Release;
 		};
 /* End XCConfigurationList section */
 	};
-	rootObject = F6B0839714721EE50031D8A1 /* Project object */;
+	rootObject = DB13B15C1849DEB70010F42D /* Project object */;
 }
diff --git a/src/aarch64/ffi.c b/src/aarch64/ffi.c
index f1a063d..ec773d6 100644
--- a/src/aarch64/ffi.c
+++ b/src/aarch64/ffi.c
@@ -49,14 +49,29 @@ struct call_context
   } v [AARCH64_N_VREG];
 };
 
+#if defined(__clang__) && defined(__APPLE__)
+void sys_icache_invalidate(void *start, size_t len);
+#endif
+
+static inline void ffi_clear_cache(void *start, void *end)
+{
+#if defined(__clang__) && defined(__APPLE__)
+	sys_icache_invalidate(start, (char *)end-(char *)start);
+#elif defined(__GNUC__)
+	__builtin___clear_cache(start, end);
+#else
+#error "Missing builtin to flush instruction cache"
+#endif
+}
+
 static void *
-get_x_addr (struct call_context *context, unsigned n)
+get_x_addr (struct call_context *context, size_t n)
 {
   return &context->x[n];
 }
 
 static void *
-get_s_addr (struct call_context *context, unsigned n)
+get_s_addr (struct call_context *context, size_t n)
 {
 #if defined __AARCH64EB__
   return &context->v[n].d[1].s[1];
@@ -66,7 +81,7 @@ get_s_addr (struct call_context *context, unsigned n)
 }
 
 static void *
-get_d_addr (struct call_context *context, unsigned n)
+get_d_addr (struct call_context *context, size_t n)
 {
 #if defined __AARCH64EB__
   return &context->v[n].d[1];
@@ -76,7 +91,7 @@ get_d_addr (struct call_context *context, unsigned n)
 }
 
 static void *
-get_v_addr (struct call_context *context, unsigned n)
+get_v_addr (struct call_context *context, size_t n)
 {
   return &context->v[n];
 }
@@ -94,8 +109,10 @@ get_basic_type_addr (unsigned short type, struct call_context *context,
       return get_s_addr (context, n);
     case FFI_TYPE_DOUBLE:
       return get_d_addr (context, n);
+#if FFI_TYPE_DOUBLE != FFI_TYPE_LONGDOUBLE
     case FFI_TYPE_LONGDOUBLE:
       return get_v_addr (context, n);
+#endif
     case FFI_TYPE_UINT8:
     case FFI_TYPE_SINT8:
     case FFI_TYPE_UINT16:
@@ -123,8 +140,10 @@ get_basic_type_alignment (unsigned short type)
     case FFI_TYPE_FLOAT:
     case FFI_TYPE_DOUBLE:
       return sizeof (UINT64);
+#if FFI_TYPE_DOUBLE != FFI_TYPE_LONGDOUBLE
     case FFI_TYPE_LONGDOUBLE:
       return sizeof (long double);
+#endif
     case FFI_TYPE_UINT8:
     case FFI_TYPE_SINT8:
     case FFI_TYPE_UINT16:
@@ -154,8 +173,10 @@ get_basic_type_size (unsigned short type)
       return sizeof (UINT32);
     case FFI_TYPE_DOUBLE:
       return sizeof (UINT64);
+#if FFI_TYPE_DOUBLE != FFI_TYPE_LONGDOUBLE
     case FFI_TYPE_LONGDOUBLE:
       return sizeof (long double);
+#endif
     case FFI_TYPE_UINT8:
       return sizeof (UINT8);
     case FFI_TYPE_SINT8:
@@ -186,7 +207,7 @@ ffi_call_SYSV (unsigned (*)(struct call_context *context, unsigned char *,
 			    extended_cif *),
                struct call_context *context,
                extended_cif *,
-               unsigned,
+               size_t,
                void (*fn)(void));
 
 extern void
@@ -305,7 +326,9 @@ is_register_candidate (ffi_type *ty)
     case FFI_TYPE_VOID:
     case FFI_TYPE_FLOAT:
     case FFI_TYPE_DOUBLE:
+#if FFI_TYPE_DOUBLE != FFI_TYPE_LONGDOUBLE
     case FFI_TYPE_LONGDOUBLE:
+#endif
     case FFI_TYPE_UINT8:
     case FFI_TYPE_UINT16:
     case FFI_TYPE_UINT32:
@@ -365,14 +388,14 @@ is_v_register_candidate (ffi_type *ty)
 
 struct arg_state
 {
-  unsigned ngrn;                /* Next general-purpose register number. */
-  unsigned nsrn;                /* Next vector register number. */
-  unsigned nsaa;                /* Next stack offset. */
+  size_t ngrn;                /* Next general-purpose register number. */
+  size_t nsrn;                /* Next vector register number. */
+  size_t nsaa;                /* Next stack offset. */
 };
 
 /* Initialize a procedure call argument marshalling state.  */
 static void
-arg_init (struct arg_state *state, unsigned call_frame_size)
+arg_init (struct arg_state *state, size_t call_frame_size)
 {
   state->ngrn = 0;
   state->nsrn = 0;
@@ -382,7 +405,7 @@ arg_init (struct arg_state *state, unsigned call_frame_size)
 /* Return the number of available consecutive core argument
    registers.  */
 
-static unsigned
+static size_t
 available_x (struct arg_state *state)
 {
   return N_X_ARG_REG - state->ngrn;
@@ -391,7 +414,7 @@ available_x (struct arg_state *state)
 /* Return the number of available consecutive vector argument
    registers.  */
 
-static unsigned
+static size_t
 available_v (struct arg_state *state)
 {
   return N_V_ARG_REG - state->nsrn;
@@ -427,8 +450,8 @@ allocate_to_v (struct call_context *context, struct arg_state *state)
 
 /* Allocate an aligned slot on the stack and return a pointer to it.  */
 static void *
-allocate_to_stack (struct arg_state *state, void *stack, unsigned alignment,
-		   unsigned size)
+allocate_to_stack (struct arg_state *state, void *stack, size_t alignment,
+		   size_t size)
 {
   void *allocation;
 
@@ -457,9 +480,11 @@ copy_basic_type (void *dest, void *source, unsigned short type)
     case FFI_TYPE_DOUBLE:
       *(double *) dest = *(double *) source;
       break;
+#if FFI_TYPE_DOUBLE != FFI_TYPE_LONGDOUBLE
     case FFI_TYPE_LONGDOUBLE:
       *(long double *) dest = *(long double *) source;
       break;
+#endif
     case FFI_TYPE_UINT8:
       *(ffi_arg *) dest = *(UINT8 *) source;
       break;
@@ -514,8 +539,8 @@ copy_hfa_to_reg_or_stack (void *memory,
     {
       int i;
       unsigned short type = get_homogeneous_type (ty);
-      unsigned elems = element_count (ty);
-      for (i = 0; i < elems; i++)
+	  unsigned count = element_count (ty);
+	  for (i = 0; i < count; i++)
 	{
 	  void *reg = allocate_to_v (context, state);
 	  copy_basic_type (reg, memory, type);
@@ -548,11 +573,13 @@ allocate_to_register_or_stack (struct call_context *context,
 	return allocate_to_d (context, state);
       state->nsrn = N_V_ARG_REG;
       break;
+#if FFI_TYPE_DOUBLE != FFI_TYPE_LONGDOUBLE
     case FFI_TYPE_LONGDOUBLE:
       if (state->nsrn < N_V_ARG_REG)
 	return allocate_to_v (context, state);
       state->nsrn = N_V_ARG_REG;
       break;
+#endif
     case FFI_TYPE_UINT8:
     case FFI_TYPE_SINT8:
     case FFI_TYPE_UINT16:
@@ -615,7 +642,9 @@ aarch64_prep_args (struct call_context *context, unsigned char *stack,
 	   appropriate register, or if none are available, to the stack.  */
 	case FFI_TYPE_FLOAT:
 	case FFI_TYPE_DOUBLE:
+#if FFI_TYPE_DOUBLE != FFI_TYPE_LONGDOUBLE
 	case FFI_TYPE_LONGDOUBLE:
+#endif
 	case FFI_TYPE_UINT8:
 	case FFI_TYPE_SINT8:
 	case FFI_TYPE_UINT16:
@@ -728,7 +757,7 @@ ffi_call (ffi_cif *cif, void (*fn)(void), void *rvalue, void **avalue)
     case FFI_SYSV:
       {
         struct call_context context;
-	unsigned stack_bytes;
+	size_t stack_bytes;
 
 	/* Figure out the total amount of stack space we need, the
 	   above call frame space needs to be 16 bytes aligned to
@@ -745,7 +774,9 @@ ffi_call (ffi_cif *cif, void (*fn)(void), void *rvalue, void **avalue)
               case FFI_TYPE_VOID:
               case FFI_TYPE_FLOAT:
               case FFI_TYPE_DOUBLE:
+#if FFI_TYPE_DOUBLE != FFI_TYPE_LONGDOUBLE
               case FFI_TYPE_LONGDOUBLE:
+#endif
               case FFI_TYPE_UINT8:
               case FFI_TYPE_SINT8:
               case FFI_TYPE_UINT16:
@@ -778,7 +809,7 @@ ffi_call (ffi_cif *cif, void (*fn)(void), void *rvalue, void **avalue)
 		  }
                 else if ((cif->rtype->size + 7) / 8 < N_X_ARG_REG)
                   {
-                    unsigned size = ALIGN (cif->rtype->size, sizeof (UINT64));
+                    size_t size = ALIGN (cif->rtype->size, sizeof (UINT64));
                     memcpy (rvalue, get_x_addr (&context, 0), size);
                   }
                 else
@@ -824,7 +855,7 @@ static unsigned char trampoline [] =
     memcpy (__tramp + 12, &__fun, sizeof (__fun));			\
     memcpy (__tramp + 20, &__ctx, sizeof (__ctx));			\
     memcpy (__tramp + 28, &__flags, sizeof (__flags));			\
-    __clear_cache(__tramp, __tramp + FFI_TRAMPOLINE_SIZE);		\
+	ffi_clear_cache(__tramp, __tramp + FFI_TRAMPOLINE_SIZE);		\
   })
 
 ffi_status
@@ -865,6 +896,9 @@ ffi_prep_closure_loc (ffi_closure* closure,
 
 void
 ffi_closure_SYSV_inner (ffi_closure *closure, struct call_context *context,
+	  void *stack);
+void
+ffi_closure_SYSV_inner (ffi_closure *closure, struct call_context *context,
 			void *stack)
 {
   ffi_cif *cif = closure->cif;
@@ -897,11 +931,12 @@ ffi_closure_SYSV_inner (ffi_closure *closure, struct call_context *context,
 	case FFI_TYPE_SINT64:
 	case  FFI_TYPE_FLOAT:
 	case  FFI_TYPE_DOUBLE:
+#if FFI_TYPE_DOUBLE != FFI_TYPE_LONGDOUBLE
 	case  FFI_TYPE_LONGDOUBLE:
 	  avalue[i] = allocate_to_register_or_stack (context, stack,
 						     &state, ty->type);
 	  break;
-
+#endif
 	case FFI_TYPE_STRUCT:
 	  if (is_hfa (ty))
 	    {
@@ -958,11 +993,13 @@ ffi_closure_SYSV_inner (ffi_closure *closure, struct call_context *context,
 			break;
 		      }
 
+#if FFI_TYPE_DOUBLE != FFI_TYPE_LONGDOUBLE
 		    case FFI_TYPE_LONGDOUBLE:
 			  memcpy (&avalue[i],
 				  allocate_to_v (context, &state),
 				  sizeof (*avalue));
 		      break;
+#endif
 
 		    default:
 		      FFI_ASSERT (0);
@@ -1033,7 +1070,9 @@ ffi_closure_SYSV_inner (ffi_closure *closure, struct call_context *context,
         case FFI_TYPE_SINT64:
         case FFI_TYPE_FLOAT:
         case FFI_TYPE_DOUBLE:
+#if FFI_TYPE_DOUBLE != FFI_TYPE_LONGDOUBLE
         case FFI_TYPE_LONGDOUBLE:
+#endif
 	  {
 	    void *addr = get_basic_type_addr (cif->rtype->type, context, 0);
 	    copy_basic_type (addr, rvalue, cif->rtype->type);
@@ -1042,10 +1081,10 @@ ffi_closure_SYSV_inner (ffi_closure *closure, struct call_context *context,
         case FFI_TYPE_STRUCT:
           if (is_hfa (cif->rtype))
 	    {
-	      int i;
+		  int j;
 	      unsigned short type = get_homogeneous_type (cif->rtype);
 	      unsigned elems = element_count (cif->rtype);
-	      for (i = 0; i < elems; i++)
+		  for (j = 0; j < elems; i++)
 		{
 		  void *reg = get_basic_type_addr (type, context, i);
 		  copy_basic_type (reg, rvalue, type);
@@ -1054,7 +1093,7 @@ ffi_closure_SYSV_inner (ffi_closure *closure, struct call_context *context,
 	    }
           else if ((cif->rtype->size + 7) / 8 < N_X_ARG_REG)
             {
-              unsigned size = ALIGN (cif->rtype->size, sizeof (UINT64)) ;
+              size_t size = ALIGN (cif->rtype->size, sizeof (UINT64)) ;
               memcpy (get_x_addr (context, 0), rvalue, size);
             }
           else
@@ -1073,4 +1112,3 @@ ffi_closure_SYSV_inner (ffi_closure *closure, struct call_context *context,
       (closure->fun) (cif, rvalue, avalue, closure->user_data);
     }
 }
-
diff --git a/src/aarch64/sysv.S b/src/aarch64/sysv.S
index 1022454..901ee6a 100644
--- a/src/aarch64/sysv.S
+++ b/src/aarch64/sysv.S
@@ -23,15 +23,25 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.  */
 #include <fficonfig.h>
 #include <ffi.h>
 
+#ifdef HAVE_MACHINE_ASM_H
+#include <machine/asm.h>
+#else
+#ifdef __USER_LABEL_PREFIX__
+#define CONCAT1(a, b) CONCAT2(a, b)
+#define CONCAT2(a, b) a ## b
+
+/* Use the right prefix for global labels.  */
+#define CNAME(x) CONCAT1 (__USER_LABEL_PREFIX__, x)
+#else
+#define CNAME(x) x
+#endif
+#endif
+
 #define cfi_adjust_cfa_offset(off)	.cfi_adjust_cfa_offset off
 #define cfi_rel_offset(reg, off)	.cfi_rel_offset reg, off
 #define cfi_restore(reg)		.cfi_restore reg
 #define cfi_def_cfa_register(reg)	.cfi_def_cfa_register reg
 
-        .text
-        .globl ffi_call_SYSV
-        .type ffi_call_SYSV, #function
-
 /* ffi_call_SYSV()
 
    Create a stack frame, setup an argument context, call the callee
@@ -53,7 +63,7 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.  */
 			   extended_cif *),
                   struct call_context *context,
                   extended_cif *,
-                  unsigned required_stack_size,
+                  size_t required_stack_size,
                   void (*fn)(void));
 
    Therefore on entry we have:
@@ -81,8 +91,13 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.  */
 
 #define ffi_call_SYSV_FS (8 * 4)
 
+	.text
+	.globl CNAME(ffi_call_SYSV)
+#ifdef __ELF__
+	.type CNAME(ffi_call_SYSV), #function
+#endif
         .cfi_startproc
-ffi_call_SYSV:
+CNAME(ffi_call_SYSV):
         stp     x29, x30, [sp, #-16]!
 	cfi_adjust_cfa_offset (16)
         cfi_rel_offset (x29, 0)
@@ -92,11 +107,11 @@ ffi_call_SYSV:
 	cfi_def_cfa_register (x29)
         sub     sp, sp, #ffi_call_SYSV_FS
 
-        stp     x21, x22, [sp, 0]
+		stp     x21, x22, [sp, #0]
         cfi_rel_offset (x21, 0 - ffi_call_SYSV_FS)
         cfi_rel_offset (x22, 8 - ffi_call_SYSV_FS)
 
-        stp     x23, x24, [sp, 16]
+		stp     x23, x24, [sp, #16]
         cfi_rel_offset (x23, 16 - ffi_call_SYSV_FS)
         cfi_rel_offset (x24, 24 - ffi_call_SYSV_FS)
 
@@ -180,7 +195,9 @@ ffi_call_SYSV:
         ret
 
         .cfi_endproc
-        .size ffi_call_SYSV, .-ffi_call_SYSV
+#ifdef __ELF__
+		.size CNAME(ffi_call_SYSV), .-CNAME(ffi_call_SYSV)
+#endif
 
 #define ffi_closure_SYSV_FS (8 * 2 + AARCH64_CALL_CONTEXT_SIZE)
 
@@ -221,10 +238,10 @@ ffi_call_SYSV:
 
    Voila!  */
 
-        .text
-        .globl ffi_closure_SYSV
+		.text
+		.globl CNAME(ffi_closure_SYSV)
         .cfi_startproc
-ffi_closure_SYSV:
+CNAME(ffi_closure_SYSV):
         stp     x29, x30, [sp, #-16]!
 	cfi_adjust_cfa_offset (16)
         cfi_rel_offset (x29, 0)
@@ -270,7 +287,7 @@ ffi_closure_SYSV:
            trampoline was called.  */
         add     x2, x29, #16
 
-        bl      ffi_closure_SYSV_inner
+		bl      CNAME(ffi_closure_SYSV_inner)
 
         /* Figure out if we should touch the vector registers.  */
         ldr     x0, [x22, #8]
@@ -304,4 +321,6 @@ ffi_closure_SYSV:
 
         ret
         .cfi_endproc
-        .size ffi_closure_SYSV, .-ffi_closure_SYSV
+#ifdef __ELF__
+		.size CNAME(ffi_closure_SYSV), .-CNAME(ffi_closure_SYSV)
+#endif
diff --git a/src/arm/ffi.c b/src/arm/ffi.c
index e452a6e..e2a8380 100644
--- a/src/arm/ffi.c
+++ b/src/arm/ffi.c
@@ -77,19 +77,19 @@ static size_t ffi_put_arg(ffi_type **arg_type, void **arg, char *stack)
       case FFI_TYPE_SINT8:
         *(signed int *) argp = (signed int)*(SINT8 *)(* p_argv);
         break;
-        
+
       case FFI_TYPE_UINT8:
         *(unsigned int *) argp = (unsigned int)*(UINT8 *)(* p_argv);
         break;
-        
+
       case FFI_TYPE_SINT16:
         *(signed int *) argp = (signed int)*(SINT16 *)(* p_argv);
         break;
-        
+
       case FFI_TYPE_UINT16:
         *(unsigned int *) argp = (unsigned int)*(UINT16 *)(* p_argv);
         break;
-        
+
       case FFI_TYPE_STRUCT:
         memcpy(argp, *p_argv, (*p_arg)->size);
         break;
@@ -117,11 +117,12 @@ static size_t ffi_put_arg(ffi_type **arg_type, void **arg, char *stack)
 }
 /* ffi_prep_args is called by the assembly routine once stack space
    has been allocated for the function's arguments
-   
+
    The vfp_space parameter is the load area for VFP regs, the return
    value is cif->vfp_used (word bitset of VFP regs used for passing
    arguments). These are only used for the VFP hard-float ABI.
 */
+int ffi_prep_args_SYSV(char *stack, extended_cif *ecif, float *vfp_space);
 int ffi_prep_args_SYSV(char *stack, extended_cif *ecif, float *vfp_space)
 {
   register unsigned int i;
@@ -129,7 +130,7 @@ int ffi_prep_args_SYSV(char *stack, extended_cif *ecif, float *vfp_space)
   register char *argp;
   register ffi_type **p_arg;
   argp = stack;
-  
+
 
   if ( ecif->cif->flags == FFI_TYPE_STRUCT ) {
     *(void **) argp = ecif->rvalue;
@@ -149,6 +150,7 @@ int ffi_prep_args_SYSV(char *stack, extended_cif *ecif, float *vfp_space)
   return 0;
 }
 
+int ffi_prep_args_VFP(char *stack, extended_cif *ecif, float *vfp_space);
 int ffi_prep_args_VFP(char *stack, extended_cif *ecif, float *vfp_space)
 {
   // make sure we are using FFI_VFP
@@ -160,13 +162,13 @@ int ffi_prep_args_VFP(char *stack, extended_cif *ecif, float *vfp_space)
   register ffi_type **p_arg;
   char stack_used = 0;
   char done_with_regs = 0;
-  char is_vfp_type;
+  int is_vfp_type;
 
   /* the first 4 words on the stack are used for values passed in core
    * registers. */
   regp = stack;
   eo_regp = argp = regp + 16;
-  
+
 
   /* if the function returns an FFI_TYPE_STRUCT in memory, that address is
    * passed in r0 to the function */
@@ -194,7 +196,7 @@ int ffi_prep_args_VFP(char *stack, extended_cif *ecif, float *vfp_space)
       else if (!done_with_regs && !is_vfp_type)
         {
           char *tregp = ffi_align(p_arg, regp);
-          size_t size = (*p_arg)->size; 
+          size_t size = (*p_arg)->size;
           size = (size < 4)? 4 : size; // pad
           /* Check if there is space left in the aligned register area to place
            * the argument */
@@ -206,10 +208,10 @@ int ffi_prep_args_VFP(char *stack, extended_cif *ecif, float *vfp_space)
               FFI_ASSERT(regp <= argp);
               continue;
             }
-          /* In case there are no arguments in the stack area yet, 
+          /* In case there are no arguments in the stack area yet,
           the argument is passed in the remaining core registers and on the
           stack. */
-          else if (!stack_used) 
+          else if (!stack_used)
             {
               stack_used = 1;
               done_with_regs = 1;
@@ -231,7 +233,7 @@ int ffi_prep_args_VFP(char *stack, extended_cif *ecif, float *vfp_space)
 ffi_status ffi_prep_cif_machdep(ffi_cif *cif)
 {
   int type_code;
-  /* Round the stack up to a multiple of 8 bytes.  This isn't needed 
+  /* Round the stack up to a multiple of 8 bytes.  This isn't needed
      everywhere, but it is on some platforms, and it doesn't harm anything
      when it isn't needed.  */
   cif->bytes = (cif->bytes + 7) & ~7;
@@ -302,7 +304,7 @@ void ffi_call(ffi_cif *cif, void (*fn)(void), void *rvalue, void **avalue)
 {
   extended_cif ecif;
 
-  int small_struct = (cif->flags == FFI_TYPE_INT 
+  int small_struct = (cif->flags == FFI_TYPE_INT
 		      && cif->rtype->type == FFI_TYPE_STRUCT);
   int vfp_struct = (cif->flags == FFI_TYPE_STRUCT_VFP_FLOAT
 		    || cif->flags == FFI_TYPE_STRUCT_VFP_DOUBLE);
@@ -315,7 +317,7 @@ void ffi_call(ffi_cif *cif, void (*fn)(void), void *rvalue, void **avalue)
   /* If the return value is a struct and we don't have a return	*/
   /* value address then we need to make one			*/
 
-  if ((rvalue == NULL) && 
+  if ((rvalue == NULL) &&
       (cif->flags == FFI_TYPE_STRUCT))
     {
       ecif.rvalue = alloca(cif->rtype->size);
@@ -330,7 +332,7 @@ void ffi_call(ffi_cif *cif, void (*fn)(void), void *rvalue, void **avalue)
   else
     ecif.rvalue = rvalue;
 
-  switch (cif->abi) 
+  switch (cif->abi)
     {
     case FFI_SYSV:
       ffi_call_SYSV (fn, &ecif, cif->bytes, cif->flags, ecif.rvalue);
@@ -346,9 +348,9 @@ void ffi_call(ffi_cif *cif, void (*fn)(void), void *rvalue, void **avalue)
       FFI_ASSERT(0);
       break;
     }
-  if (small_struct)
+  if (small_struct && rvalue != NULL)
     memcpy (rvalue, &temp, cif->rtype->size);
-  else if (vfp_struct)
+  else if (vfp_struct && rvalue != NULL)
     memcpy (rvalue, ecif.rvalue, cif->rtype->size);
 }
 
@@ -366,6 +368,7 @@ void ffi_closure_VFP (ffi_closure *);
 
 /* This function is jumped to by the trampoline */
 
+unsigned int ffi_closure_inner (ffi_closure *closure, void **respp, void *args, void *vfp_args);
 unsigned int
 ffi_closure_inner (ffi_closure *closure, 
 		   void **respp, void *args, void *vfp_args)
@@ -375,10 +378,10 @@ ffi_closure_inner (ffi_closure *closure,
   void         **arg_area;
 
   cif         = closure->cif;
-  arg_area    = (void**) alloca (cif->nargs * sizeof (void*));  
+  arg_area    = (void**) alloca (cif->nargs * sizeof (void*));
 
   /* this call will initialize ARG_AREA, such that each
-   * element in that array points to the corresponding 
+   * element in that array points to the corresponding
    * value on the stack; and if the function returns
    * a structure, it will re-set RESP to point to the
    * structure return address.  */
@@ -393,7 +396,7 @@ ffi_closure_inner (ffi_closure *closure,
 }
 
 /*@-exportheader@*/
-static void 
+static void
 ffi_prep_incoming_args_SYSV(char *stack, void **rvalue,
 			    void **avalue, ffi_cif *cif,
 			    /* Used only under VFP hard-float ABI. */
@@ -429,12 +432,12 @@ ffi_prep_incoming_args_SYSV(char *stack, void **rvalue,
       p_argv++;
       argp += z;
     }
-  
+
   return;
 }
 
 /*@-exportheader@*/
-static void 
+static void
 ffi_prep_incoming_args_VFP(char *stack, void **rvalue,
 			    void **avalue, ffi_cif *cif,
 			    /* Used only under VFP hard-float ABI. */
@@ -447,7 +450,7 @@ ffi_prep_incoming_args_VFP(char *stack, void **rvalue,
   register ffi_type **p_arg;
   char done_with_regs = 0;
   char stack_used = 0;
-  char is_vfp_type;
+  int is_vfp_type;
 
   FFI_ASSERT(cif->abi == FFI_VFP);
   regp = stack;
@@ -463,7 +466,7 @@ ffi_prep_incoming_args_VFP(char *stack, void **rvalue,
   for (i = cif->nargs, p_arg = cif->arg_types; (i != 0); i--, p_arg++)
     {
     size_t z;
-    is_vfp_type = vfp_type_p (*p_arg); 
+    is_vfp_type = vfp_type_p (*p_arg);
 
     if(vi < cif->vfp_nargs && is_vfp_type)
       {
@@ -474,12 +477,12 @@ ffi_prep_incoming_args_VFP(char *stack, void **rvalue,
       {
         char* tregp = ffi_align(p_arg, regp);
 
-        z = (*p_arg)->size; 
+        z = (*p_arg)->size;
         z = (z < 4)? 4 : z; // pad
-        
+
         /* if the arguments either fits into the registers or uses registers
          * and stack, while we haven't read other things from the stack */
-        if(tregp + z <= eo_regp || !stack_used) 
+        if(tregp + z <= eo_regp || !stack_used)
           {
           /* because we're little endian, this is what it turns into. */
           *p_argv = (void*) tregp;
@@ -518,7 +521,7 @@ ffi_prep_incoming_args_VFP(char *stack, void **rvalue,
     p_argv++;
     argp += z;
     }
-  
+
   return;
 }
 
@@ -881,7 +884,7 @@ static int place_vfp_arg (ffi_cif *cif, ffi_type *t)
 	}
       /* Found regs to allocate. */
       cif->vfp_used |= new_used;
-      cif->vfp_args[cif->vfp_nargs++] = reg;
+      cif->vfp_args[cif->vfp_nargs++] = (typeof(*(cif->vfp_args)))reg;
 
       /* Update vfp_reg_free. */
       if (cif->vfp_used & (1 << cif->vfp_reg_free))
@@ -889,7 +892,7 @@ static int place_vfp_arg (ffi_cif *cif, ffi_type *t)
 	  reg += nregs;
 	  while (cif->vfp_used & (1 << reg))
 	    reg += 1;
-	  cif->vfp_reg_free = reg;
+	  cif->vfp_reg_free = (typeof(cif->vfp_reg_free))reg;
 	}
       return 0;
     next_reg: ;
diff --git a/src/arm/sysv.S b/src/arm/sysv.S
index 454dfc9..ef33fc9 100644
--- a/src/arm/sysv.S
+++ b/src/arm/sysv.S
@@ -1,8 +1,8 @@
 /* -----------------------------------------------------------------------
    sysv.S - Copyright (c) 1998, 2008, 2011 Red Hat, Inc.
 	    Copyright (c) 2011 Plausible Labs Cooperative, Inc.
-   
-   ARM Foreign Function Interface 
+
+   ARM Foreign Function Interface
 
    Permission is hereby granted, free of charge, to any person obtaining
    a copy of this software and associated documentation files (the
@@ -25,7 +25,7 @@
    DEALINGS IN THE SOFTWARE.
    ----------------------------------------------------------------------- */
 
-#define LIBFFI_ASM	
+#define LIBFFI_ASM
 #include <fficonfig.h>
 #include <ffi.h>
 #ifdef HAVE_MACHINE_ASM_H
@@ -59,7 +59,7 @@
 #define __SOFTFP__
 #endif
 
-/* We need a better way of testing for this, but for now, this is all 
+/* We need a better way of testing for this, but for now, this is all
    we can do.  */
 @ This selects the minimum architecture level required.
 #define __ARM_ARCH__ 3
@@ -68,7 +68,7 @@
 # undef __ARM_ARCH__
 # define __ARM_ARCH__ 4
 #endif
-        
+
 #if defined(__ARM_ARCH_5__) || defined(__ARM_ARCH_5T__) \
 	|| defined(__ARM_ARCH_5E__) || defined(__ARM_ARCH_5TE__) \
 	|| defined(__ARM_ARCH_5TEJ__)
@@ -107,60 +107,37 @@
 #define UNWIND
 #else
 #define UNWIND @
-#endif	
+#endif
+
+.syntax unified
 
-	
 #if defined(__thumb__) && !defined(__THUMB_INTERWORK__)
-.macro	ARM_FUNC_START name
-	.text
-	.align 0
-	.thumb
-	.thumb_func
-#ifdef __APPLE__
-	ENTRY($0)
+#define ARM_FUNC_START(name) \
+	.text; \
+	.align 2; \
+	.thumb; \
+	.thumb_func; \
+	ENTRY(name); \
+	bx pc; \
+	nop; \
+	.arm; \
+	UNWIND .fnstart; \
+_L__##name:
 #else
-	ENTRY(\name)
-#endif
-	bx	pc
-	nop
-	.arm
+#define ARM_FUNC_START(name) \
+	.text; \
+	.align 2; \
+	.arm; \
+	ENTRY(name); \
 	UNWIND .fnstart
-/* A hook to tell gdb that we've switched to ARM mode.  Also used to call
-   directly from other local arm routines.  */
-#ifdef __APPLE__
-_L__$0:
-#else
-_L__\name:
-#endif
-.endm
-#else
-.macro	ARM_FUNC_START name
-	.text
-	.align 0
-	.arm
-#ifdef __APPLE__
-	ENTRY($0)
-#else
-	ENTRY(\name)
-#endif
-	UNWIND .fnstart
-.endm
 #endif
 
-.macro	RETLDM	regs=, cond=, dirn=ia
+.macro	RETLDM
 #if defined (__INTERWORKING__)
-	.ifc "\regs",""
-	ldr\cond	lr, [sp], #4
-	.else
-	ldm\cond\dirn	sp!, {\regs, lr}
-	.endif
-	bx\cond	lr
+	ldr	lr, [sp], #4
+	bx	lr
 #else
-	.ifc "\regs",""
-	ldr\cond	pc, [sp], #4
-	.else
-	ldm\cond\dirn	sp!, {\regs, pc}
-	.endif
+	ldr	pc, [sp], #4
 #endif
 .endm
 
@@ -171,7 +148,7 @@ _L__\name:
 	@ sp+0: ecif.rvalue
 
 	@ This assumes we are using gas.
-ARM_FUNC_START ffi_call_SYSV
+ARM_FUNC_START(ffi_call_SYSV)
 	@ Save registers
         stmfd	sp!, {r0-r3, fp, lr}
 	UNWIND .save	{r0-r3, fp, lr}
@@ -201,14 +178,14 @@ ARM_FUNC_START ffi_call_SYSV
 
 	@ call (fn) (...)
 	call_reg(ip)
-	
+
 	@ Remove the space we pushed for the args
 	mov	sp, fp
 
 	@ Load r2 with the pointer to storage for the return value
 	ldr	r2, [sp, #24]
 
-	@ Load r3 with the return type code 
+	@ Load r3 with the return type code
 	ldr	r3, [sp, #12]
 
 	@ If the return value pointer is NULL, assume no return value.
@@ -228,7 +205,7 @@ ARM_FUNC_START ffi_call_SYSV
 #if defined(__SOFTFP__) || defined(__ARM_EABI__)
 	cmpne	r3, #FFI_TYPE_DOUBLE
 #endif
-	stmeqia	r2, {r0, r1}
+	stmiaeq	r2, {r0, r1}
 
 #if !defined(__SOFTFP__) && !defined(__ARM_EABI__)
 	beq	LSYM(Lepilogue)
@@ -266,7 +243,7 @@ LSYM(Lepilogue):
   	     void *args;
 */
 
-ARM_FUNC_START ffi_closure_SYSV
+ARM_FUNC_START(ffi_closure_SYSV)
 	UNWIND .pad #16
 	add	ip, sp, #16
 	stmfd	sp!, {ip, lr}
@@ -345,7 +322,7 @@ ARM_FUNC_START ffi_closure_SYSV
 	@ r3:   fig->flags
 	@ sp+0: ecif.rvalue
 
-ARM_FUNC_START ffi_call_VFP
+ARM_FUNC_START(ffi_call_VFP)
 	@ Save registers
         stmfd	sp!, {r0-r3, fp, lr}
 	UNWIND .save	{r0-r3, fp, lr}
@@ -397,7 +374,7 @@ LSYM(Lbase_args):
 	@ the return value
 	ldr	r2, [sp, #24]
 
-	@ Load r3 with the return type code 
+	@ Load r3 with the return type code
 	ldr	r3, [sp, #12]
 
 	@ If the return value pointer is NULL,
@@ -416,7 +393,7 @@ LSYM(Lbase_args):
 	cmp	r3, #FFI_TYPE_FLOAT
 	fstseq	s0, [r2]
 	beq	LSYM(Lepilogue_vfp)
-	
+
 	cmp	r3, #FFI_TYPE_DOUBLE
 	fstdeq	d0, [r2]
 	beq	LSYM(Lepilogue_vfp)
@@ -433,7 +410,7 @@ LSYM(Lepilogue_vfp):
         .size    CNAME(ffi_call_VFP),.ffi_call_VFP_end-CNAME(ffi_call_VFP)
 
 
-ARM_FUNC_START ffi_closure_VFP
+ARM_FUNC_START(ffi_closure_VFP)
 	fstmfdd	sp!, {d0-d7}
 	@ r0-r3, then d0-d7
 	UNWIND .pad #80
@@ -466,7 +443,7 @@ ARM_FUNC_START ffi_closure_VFP
 
 	cmp	r0, #FFI_TYPE_STRUCT_VFP_DOUBLE
 	beq	.Lretdouble_struct_vfp
-	
+
 .Lclosure_epilogue_vfp:
 	add	sp, sp, #72
 	ldmfd	sp, {sp, pc}
diff --git a/src/closures.c b/src/closures.c
index 4d0a0b6..6eac601 100644
--- a/src/closures.c
+++ b/src/closures.c
@@ -264,7 +264,7 @@ static int
 open_temp_exec_file_dir (const char *dir)
 {
   static const char suffix[] = "/ffiXXXXXX";
-  int lendir = strlen (dir);
+  size_t lendir = strlen (dir);
   char *tempname = __builtin_alloca (lendir + sizeof (suffix));
 
   if (!tempname)
diff --git a/src/dlmalloc.c b/src/dlmalloc.c
index 3e2ea6f..8725b4f 100644
--- a/src/dlmalloc.c
+++ b/src/dlmalloc.c
@@ -1661,7 +1661,7 @@ struct malloc_chunk {
 typedef struct malloc_chunk  mchunk;
 typedef struct malloc_chunk* mchunkptr;
 typedef struct malloc_chunk* sbinptr;  /* The type of bins of chunks */
-typedef unsigned int bindex_t;         /* Described below */
+typedef size_t bindex_t;               /* Described below */
 typedef unsigned int binmap_t;         /* Described below */
 typedef unsigned int flag_t;           /* The type of various bit flag sets */
 
@@ -3388,7 +3388,7 @@ static void add_segment(mstate m, char* tbase, size_t tsize, flag_t mmapped) {
   *ss = m->seg; /* Push current record */
   m->seg.base = tbase;
   m->seg.size = tsize;
-  set_segment_flags(&m->seg, mmapped);
+  (void)set_segment_flags(&m->seg, mmapped);
   m->seg.next = ss;
 
   /* Insert trailing fenceposts */
@@ -3548,7 +3548,7 @@ static void* sys_alloc(mstate m, size_t nb) {
     if (!is_initialized(m)) { /* first-time initialization */
       m->seg.base = m->least_addr = tbase;
       m->seg.size = tsize;
-      set_segment_flags(&m->seg, mmap_flag);
+      (void)set_segment_flags(&m->seg, mmap_flag);
       m->magic = mparams.magic;
       init_bins(m);
       if (is_global(m)) 
diff --git a/src/prep_cif.c b/src/prep_cif.c
index a66ee23..e216ef0 100644
--- a/src/prep_cif.c
+++ b/src/prep_cif.c
@@ -187,7 +187,7 @@ ffi_status FFI_HIDDEN ffi_prep_cif_core(ffi_cif *cif, ffi_abi abi,
 	{
 	  /* Add any padding if necessary */
 	  if (((*ptr)->alignment - 1) & bytes)
-	    bytes = ALIGN(bytes, (*ptr)->alignment);
+	    bytes = (unsigned)ALIGN(bytes, (*ptr)->alignment);
 
 #ifdef TILE
 	  if (bytes < 10 * FFI_SIZEOF_ARG &&
diff --git a/src/x86/ffi.c b/src/x86/ffi.c
index 307cd19..ba33775 100644
--- a/src/x86/ffi.c
+++ b/src/x86/ffi.c
@@ -42,6 +42,7 @@
 /* ffi_prep_args is called by the assembly routine once stack space
    has been allocated for the function's arguments */
 
+void ffi_prep_args(char *stack, extended_cif *ecif);
 void ffi_prep_args(char *stack, extended_cif *ecif)
 {
   register unsigned int i;
@@ -341,7 +342,7 @@ void ffi_call(ffi_cif *cif, void (*fn)(void), void *rvalue, void **avalue)
 
   ecif.cif = cif;
   ecif.avalue = avalue;
-  
+
   /* If the return value is a struct and we don't have a return */
   /* value address then we need to make one                     */
 
@@ -363,9 +364,9 @@ void ffi_call(ffi_cif *cif, void (*fn)(void), void *rvalue, void **avalue)
 #endif
   else
     ecif.rvalue = rvalue;
-    
-  
-  switch (cif->abi) 
+
+
+  switch (cif->abi)
     {
 #ifdef X86_WIN64
     case FFI_WIN64:
@@ -456,16 +457,16 @@ ffi_closure_win64_inner (ffi_closure *closure, void *args) {
   void          *resp = &result;
 
   cif         = closure->cif;
-  arg_area    = (void**) alloca (cif->nargs * sizeof (void*));  
+  arg_area    = (void**) alloca (cif->nargs * sizeof (void*));
 
   /* this call will initialize ARG_AREA, such that each
-   * element in that array points to the corresponding 
+   * element in that array points to the corresponding
    * value on the stack; and if the function returns
    * a structure, it will change RESP to point to the
    * structure return address.  */
 
   ffi_prep_incoming_args_SYSV(args, &resp, arg_area, cif);
-  
+
   (closure->fun) (cif, resp, arg_area, closure->user_data);
 
   /* The result is returned in rax.  This does the right thing for
@@ -485,10 +486,10 @@ ffi_closure_SYSV_inner (ffi_closure *closure, void **respp, void *args)
   void         **arg_area;
 
   cif         = closure->cif;
-  arg_area    = (void**) alloca (cif->nargs * sizeof (void*));  
+  arg_area    = (void**) alloca (cif->nargs * sizeof (void*));
 
   /* this call will initialize ARG_AREA, such that each
-   * element in that array points to the corresponding 
+   * element in that array points to the corresponding
    * value on the stack; and if the function returns
    * a structure, it will change RESP to point to the
    * structure return address.  */
@@ -552,12 +553,12 @@ ffi_prep_incoming_args_SYSV(char *stack, void **rvalue, void **avalue,
 #endif
         {
           z = (*p_arg)->size;
-          
+
           /* because we're little endian, this is what it turns into.   */
-          
+
           *p_argv = (void*) argp;
         }
-          
+
       p_argv++;
 #ifdef X86_WIN64
       argp += (z + sizeof(void*) - 1) & ~(sizeof(void*) - 1);
@@ -565,7 +566,7 @@ ffi_prep_incoming_args_SYSV(char *stack, void **rvalue, void **avalue,
       argp += z;
 #endif
     }
-  
+
   return;
 }
 
@@ -653,7 +654,7 @@ ffi_prep_closure_loc (ffi_closure* closure,
 #ifdef X86_WIN64
 #define ISFLOAT(IDX) (cif->arg_types[IDX]->type == FFI_TYPE_FLOAT || cif->arg_types[IDX]->type == FFI_TYPE_DOUBLE)
 #define FLAG(IDX) (cif->nargs>(IDX)&&ISFLOAT(IDX)?(1<<(IDX)):0)
-  if (cif->abi == FFI_WIN64) 
+  if (cif->abi == FFI_WIN64)
     {
       int mask = FLAG(0)|FLAG(1)|FLAG(2)|FLAG(3);
       FFI_INIT_TRAMPOLINE_WIN64 (&closure->tramp[0],
@@ -694,7 +695,7 @@ ffi_prep_closure_loc (ffi_closure* closure,
     {
       return FFI_BAD_ABI;
     }
-    
+
   closure->cif  = cif;
   closure->user_data = user_data;
   closure->fun  = fun;
@@ -732,7 +733,7 @@ ffi_prep_raw_closure_loc (ffi_raw_closure* closure,
       FFI_ASSERT (cif->arg_types[i]->type != FFI_TYPE_STRUCT);
       FFI_ASSERT (cif->arg_types[i]->type != FFI_TYPE_LONGDOUBLE);
     }
-  
+
 #ifdef X86_WIN32
   if (cif->abi == FFI_SYSV)
     {
@@ -754,7 +755,7 @@ ffi_prep_raw_closure_loc (ffi_raw_closure* closure,
   return FFI_OK;
 }
 
-static void 
+static void
 ffi_prep_args_raw(char *stack, extended_cif *ecif)
 {
   memcpy (stack, ecif->avalue, ecif->cif->bytes);
@@ -773,7 +774,7 @@ ffi_raw_call(ffi_cif *cif, void (*fn)(void), void *rvalue, ffi_raw *fake_avalue)
 
   ecif.cif = cif;
   ecif.avalue = avalue;
-  
+
   /* If the return value is a struct and we don't have a return */
   /* value address then we need to make one                     */
 
@@ -785,9 +786,9 @@ ffi_raw_call(ffi_cif *cif, void (*fn)(void), void *rvalue, ffi_raw *fake_avalue)
     }
   else
     ecif.rvalue = rvalue;
-    
-  
-  switch (cif->abi) 
+
+
+  switch (cif->abi)
     {
 #ifdef X86_WIN32
     case FFI_SYSV:
diff --git a/src/x86/ffi64.c b/src/x86/ffi64.c
index bd917f0..bd241ef 100644
--- a/src/x86/ffi64.c
+++ b/src/x86/ffi64.c
@@ -168,7 +168,7 @@ classify_argument (ffi_type *type, enum x86_64_reg_class classes[],
     case FFI_TYPE_SINT64:
     case FFI_TYPE_POINTER:
       {
-	int size = byte_offset + type->size;
+	size_t size = byte_offset + type->size;
 
 	if (size <= 4)
 	  {
@@ -210,7 +210,7 @@ classify_argument (ffi_type *type, enum x86_64_reg_class classes[],
     case FFI_TYPE_STRUCT:
       {
 	const int UNITS_PER_WORD = 8;
-	int words = (type->size + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
+	int words = ((int)type->size + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
 	ffi_type **ptr;
 	int i;
 	enum x86_64_reg_class subclasses[MAX_CLASSES];
@@ -242,7 +242,7 @@ classify_argument (ffi_type *type, enum x86_64_reg_class classes[],
 	      return 0;
 	    for (i = 0; i < num; i++)
 	      {
-		int pos = byte_offset / 8;
+		size_t pos = byte_offset / 8;
 		classes[i + pos] =
 		  merge_classes (subclasses[i], classes[i + pos]);
 	      }
@@ -411,7 +411,7 @@ ffi_prep_cif_machdep (ffi_cif *cif)
   if (ssecount)
     flags |= 1 << 11;
   cif->flags = flags;
-  cif->bytes = ALIGN (bytes, 8);
+  cif->bytes = (unsigned)ALIGN (bytes, 8);
 
   return FFI_OK;
 }