Skip to content

Commit d775226

Browse files
committed
Support targeting macOS aarch64 in older GCCs
This adds backports of a couple of patches necessary to support macOS arm64 hosts for gcc. It was ported from richfelker/musl-cross-make#129 with some small fixups to make the patches apply cleanly. Signed-off-by: Steven Fackler <[email protected]>
1 parent 9a08601 commit d775226

11 files changed

+506
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
diff -ru a/config.guess b/config.guess
2+
--- a/config.guess 2015-12-31 22:13:28.000000000 +0100
3+
+++ b/config.guess 2021-12-20 01:44:40.000000000 +0100
4+
@@ -1278,6 +1278,9 @@
5+
*:Rhapsody:*:*)
6+
echo ${UNAME_MACHINE}-apple-rhapsody${UNAME_RELEASE}
7+
exit ;;
8+
+ arm64:Darwin:*:*)
9+
+ echo aarch64-apple-darwin"$UNAME_RELEASE"
10+
+ exit ;;
11+
*:Darwin:*:*)
12+
UNAME_PROCESSOR=`uname -p` || UNAME_PROCESSOR=unknown
13+
eval $set_cc_for_build
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
--- a/gcc/config.host 2017-01-09 22:01:26.000000000 +0100
2+
+++ b/gcc/config.host 2021-12-27 23:11:12.000000000 +0100
3+
@@ -99,7 +99,7 @@
4+
esac
5+
6+
case ${host} in
7+
- aarch64*-*-freebsd* | aarch64*-*-linux*)
8+
+ aarch64*-*-freebsd* | aarch64*-*-linux* | aarch64*-*-darwin*)
9+
case ${target} in
10+
aarch64*-*-*)
11+
host_extra_gcc_objs="driver-aarch64.o"
12+
@@ -249,6 +249,10 @@
13+
out_host_hook_obj=host-mingw32.o
14+
host_lto_plugin_soname=liblto_plugin-0.dll
15+
;;
16+
+ aarch64*-*-darwin*)
17+
+ out_host_hook_obj="${out_host_hook_obj} host-aarch64-darwin.o"
18+
+ host_xmake_file="${host_xmake_file} aarch64/x-darwin"
19+
+ ;;
20+
i[34567]86-*-darwin* | x86_64-*-darwin*)
21+
out_host_hook_obj="${out_host_hook_obj} host-i386-darwin.o"
22+
host_xmake_file="${host_xmake_file} i386/x-darwin"
23+
diff --git a/gcc/config/aarch64/host-aarch64-darwin.c b/gcc/config/aarch64/host-aarch64-darwin.c
24+
new file mode 100644
25+
index 0000000000000..d70f2df3bf1b3
26+
--- /dev/null
27+
+++ b/gcc/config/aarch64/host-aarch64-darwin.c
28+
@@ -0,0 +1,33 @@
29+
+/* aarch64/arm64-darwin host-specific hook definitions.
30+
+
31+
+Copyright The GNU Toolchain Authors.
32+
+
33+
+This file is part of GCC.
34+
+
35+
+GCC is free software; you can redistribute it and/or modify it under
36+
+the terms of the GNU General Public License as published by the Free
37+
+Software Foundation; either version 3, or (at your option) any later
38+
+version.
39+
+
40+
+GCC is distributed in the hope that it will be useful, but WITHOUT ANY
41+
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
42+
+FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
43+
+for more details.
44+
+
45+
+You should have received a copy of the GNU General Public License
46+
+along with GCC; see the file COPYING3. If not see
47+
+<http://www.gnu.org/licenses/>. */
48+
+
49+
+#define IN_TARGET_CODE 1
50+
+
51+
+#include "config.h"
52+
+#include "system.h"
53+
+#include "coretypes.h"
54+
+#include "hosthooks.h"
55+
+#include "hosthooks-def.h"
56+
+#include "config/host-darwin.h"
57+
+
58+
+/* Darwin doesn't do anything special for arm64/aarch64 hosts; this file
59+
+ exists just to include the generic config/host-darwin.h. */
60+
+
61+
+const struct host_hooks host_hooks = HOST_HOOKS_INITIALIZER;
62+
diff --git a/gcc/config/aarch64/x-darwin b/gcc/config/aarch64/x-darwin
63+
new file mode 100644
64+
index 0000000000000..6d788d5e89cfb
65+
--- /dev/null
66+
+++ b/gcc/config/aarch64/x-darwin
67+
@@ -0,0 +1,3 @@
68+
+host-aarch64-darwin.o : $(srcdir)/config/aarch64/host-aarch64-darwin.c
69+
+ $(COMPILE) $<
70+
+ $(POSTCOMPILE)
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
From ac2ca688140dbf103ad18efbc8fb98e62ec40e27 Mon Sep 17 00:00:00 2001
2+
From: Iain Sandoe <[email protected]>
3+
Date: Sat, 8 Aug 2020 12:15:09 +0100
4+
Subject: [PATCH] Darwin: Adjust the PCH area to allow for 16384byte page size.
5+
6+
Newer versions of Darwin report pagesize 20 which means that we
7+
need to adjust the aligment of the PCH area.
8+
9+
gcc/ChangeLog:
10+
11+
* config/host-darwin.c: Align pch_address_space to 16384.
12+
13+
(cherry picked from commit 590febb5f6624f78b36402a7c9a9c318978f1efa)
14+
---
15+
gcc/config/host-darwin.c | 5 ++++-
16+
1 file changed, 4 insertions(+), 1 deletion(-)
17+
18+
diff --git a/gcc/config/host-darwin.c b/gcc/config/host-darwin.c
19+
index 49d3af77a9237..b9cf347f1e847 100644
20+
--- a/gcc/config/host-darwin.c
21+
+++ b/gcc/config/host-darwin.c
22+
@@ -24,7 +24,10 @@
23+
#include "config/host-darwin.h"
24+
25+
/* Yes, this is really supposed to work. */
26+
-static char pch_address_space[1024*1024*1024] __attribute__((aligned (4096)));
27+
+/* This allows for a pagesize of 16384, which we have on Darwin20, but should
28+
+ continue to work OK for pagesize 4096 which we have on earlier versions.
29+
+ The size is 1 (binary) Gb. */
30+
+static char pch_address_space[65536*16384] __attribute__((aligned (16384)));
31+
32+
/* Return the address of the PCH address space, if the PCH will fit in it. */
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
diff -ru a/config.guess b/config.guess
2+
--- a/config.guess 2017-03-18 19:22:06.000000000 +0100
3+
+++ b/config.guess 2021-12-20 01:41:00.000000000 +0100
4+
@@ -1295,6 +1295,9 @@
5+
*:Rhapsody:*:*)
6+
echo ${UNAME_MACHINE}-apple-rhapsody${UNAME_RELEASE}
7+
exit ;;
8+
+ arm64:Darwin:*:*)
9+
+ echo aarch64-apple-darwin"$UNAME_RELEASE"
10+
+ exit ;;
11+
*:Darwin:*:*)
12+
UNAME_PROCESSOR=`uname -p` || UNAME_PROCESSOR=unknown
13+
eval $set_cc_for_build
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
From 834c8749ced550af3f17ebae4072fb7dfb90d271 Mon Sep 17 00:00:00 2001
2+
From: Iain Sandoe <[email protected]>
3+
Date: Tue, 18 Aug 2020 22:29:51 +0100
4+
Subject: [PATCH] Darwin, aarch64 : Initial support for the self-host driver.
5+
6+
At present, there is no special action needed for aarch64-darwin
7+
this just pulls in generic Darwin code.
8+
9+
Signed-off-by: Iain Sandoe <[email protected]>
10+
11+
gcc/ChangeLog:
12+
13+
* config.host: Add support for aarch64-*-darwin.
14+
* config/aarch64/host-aarch64-darwin.c: New file.
15+
* config/aarch64/x-darwin: New file.
16+
---
17+
gcc/config.host | 7 ++++-
18+
gcc/config/aarch64/host-aarch64-darwin.c | 33 ++++++++++++++++++++++++
19+
gcc/config/aarch64/x-darwin | 3 +++
20+
3 files changed, 42 insertions(+), 1 deletion(-)
21+
create mode 100644 gcc/config/aarch64/host-aarch64-darwin.c
22+
create mode 100644 gcc/config/aarch64/x-darwin
23+
24+
diff --git a/gcc/config.host b/gcc/config.host
25+
index 0a02c33cc8044..81ff7ed1043e2 100644
26+
--- a/gcc/config.host
27+
+++ b/gcc/config.host
28+
@@ -99,7 +99,8 @@ case ${host} in
29+
esac
30+
31+
case ${host} in
32+
- aarch64*-*-freebsd* | aarch64*-*-linux* | aarch64*-*-fuchsia*)
33+
+ aarch64*-*-freebsd* | aarch64*-*-linux* | aarch64*-*-fuchsia* |\
34+
+ aarch64*-*-darwin*)
35+
case ${target} in
36+
aarch64*-*-*)
37+
host_extra_gcc_objs="driver-aarch64.o"
38+
@@ -249,6 +250,10 @@ case ${host} in
39+
out_host_hook_obj=host-mingw32.o
40+
host_lto_plugin_soname=liblto_plugin-0.dll
41+
;;
42+
+ aarch64*-*-darwin*)
43+
+ out_host_hook_obj="${out_host_hook_obj} host-aarch64-darwin.o"
44+
+ host_xmake_file="${host_xmake_file} aarch64/x-darwin"
45+
+ ;;
46+
i[34567]86-*-darwin* | x86_64-*-darwin*)
47+
out_host_hook_obj="${out_host_hook_obj} host-i386-darwin.o"
48+
host_xmake_file="${host_xmake_file} i386/x-darwin"
49+
diff --git a/gcc/config/aarch64/host-aarch64-darwin.c b/gcc/config/aarch64/host-aarch64-darwin.c
50+
new file mode 100644
51+
index 0000000000000..d70f2df3bf1b3
52+
--- /dev/null
53+
+++ b/gcc/config/aarch64/host-aarch64-darwin.c
54+
@@ -0,0 +1,33 @@
55+
+/* aarch64/arm64-darwin host-specific hook definitions.
56+
+
57+
+Copyright The GNU Toolchain Authors.
58+
+
59+
+This file is part of GCC.
60+
+
61+
+GCC is free software; you can redistribute it and/or modify it under
62+
+the terms of the GNU General Public License as published by the Free
63+
+Software Foundation; either version 3, or (at your option) any later
64+
+version.
65+
+
66+
+GCC is distributed in the hope that it will be useful, but WITHOUT ANY
67+
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
68+
+FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
69+
+for more details.
70+
+
71+
+You should have received a copy of the GNU General Public License
72+
+along with GCC; see the file COPYING3. If not see
73+
+<http://www.gnu.org/licenses/>. */
74+
+
75+
+#define IN_TARGET_CODE 1
76+
+
77+
+#include "config.h"
78+
+#include "system.h"
79+
+#include "coretypes.h"
80+
+#include "hosthooks.h"
81+
+#include "hosthooks-def.h"
82+
+#include "config/host-darwin.h"
83+
+
84+
+/* Darwin doesn't do anything special for arm64/aarch64 hosts; this file
85+
+ exists just to include the generic config/host-darwin.h. */
86+
+
87+
+const struct host_hooks host_hooks = HOST_HOOKS_INITIALIZER;
88+
diff --git a/gcc/config/aarch64/x-darwin b/gcc/config/aarch64/x-darwin
89+
new file mode 100644
90+
index 0000000000000..6d788d5e89cfb
91+
--- /dev/null
92+
+++ b/gcc/config/aarch64/x-darwin
93+
@@ -0,0 +1,3 @@
94+
+host-aarch64-darwin.o : $(srcdir)/config/aarch64/host-aarch64-darwin.c
95+
+ $(COMPILE) $<
96+
+ $(POSTCOMPILE)
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
From ac2ca688140dbf103ad18efbc8fb98e62ec40e27 Mon Sep 17 00:00:00 2001
2+
From: Iain Sandoe <[email protected]>
3+
Date: Sat, 8 Aug 2020 12:15:09 +0100
4+
Subject: [PATCH] Darwin: Adjust the PCH area to allow for 16384byte page size.
5+
6+
Newer versions of Darwin report pagesize 20 which means that we
7+
need to adjust the aligment of the PCH area.
8+
9+
gcc/ChangeLog:
10+
11+
* config/host-darwin.c: Align pch_address_space to 16384.
12+
13+
(cherry picked from commit 590febb5f6624f78b36402a7c9a9c318978f1efa)
14+
---
15+
gcc/config/host-darwin.c | 5 ++++-
16+
1 file changed, 4 insertions(+), 1 deletion(-)
17+
18+
diff --git a/gcc/config/host-darwin.c b/gcc/config/host-darwin.c
19+
index 49d3af77a9237..b9cf347f1e847 100644
20+
--- a/gcc/config/host-darwin.c
21+
+++ b/gcc/config/host-darwin.c
22+
@@ -24,7 +24,10 @@
23+
#include "config/host-darwin.h"
24+
25+
/* Yes, this is really supposed to work. */
26+
-static char pch_address_space[1024*1024*1024] __attribute__((aligned (4096)));
27+
+/* This allows for a pagesize of 16384, which we have on Darwin20, but should
28+
+ continue to work OK for pagesize 4096 which we have on earlier versions.
29+
+ The size is 1 (binary) Gb. */
30+
+static char pch_address_space[65536*16384] __attribute__((aligned (16384)));
31+
32+
/* Return the address of the PCH address space, if the PCH will fit in it. */
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
diff -ru a/config.guess b/config.guess
2+
--- a/config.guess 2021-05-14 10:42:08.000000000 +0200
3+
+++ b/config.guess 2021-12-20 01:38:22.000000000 +0100
4+
@@ -1276,6 +1276,9 @@
5+
*:Rhapsody:*:*)
6+
echo ${UNAME_MACHINE}-apple-rhapsody${UNAME_RELEASE}
7+
exit ;;
8+
+ arm64:Darwin:*:*)
9+
+ echo aarch64-apple-darwin"$UNAME_RELEASE"
10+
+ exit ;;
11+
*:Darwin:*:*)
12+
UNAME_PROCESSOR=`uname -p` || UNAME_PROCESSOR=unknown
13+
eval $set_cc_for_build
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
From 834c8749ced550af3f17ebae4072fb7dfb90d271 Mon Sep 17 00:00:00 2001
2+
From: Iain Sandoe <[email protected]>
3+
Date: Tue, 18 Aug 2020 22:29:51 +0100
4+
Subject: [PATCH] Darwin, aarch64 : Initial support for the self-host driver.
5+
6+
At present, there is no special action needed for aarch64-darwin
7+
this just pulls in generic Darwin code.
8+
9+
Signed-off-by: Iain Sandoe <[email protected]>
10+
11+
gcc/ChangeLog:
12+
13+
* config.host: Add support for aarch64-*-darwin.
14+
* config/aarch64/host-aarch64-darwin.c: New file.
15+
* config/aarch64/x-darwin: New file.
16+
---
17+
gcc/config.host | 7 ++++-
18+
gcc/config/aarch64/host-aarch64-darwin.c | 33 ++++++++++++++++++++++++
19+
gcc/config/aarch64/x-darwin | 3 +++
20+
3 files changed, 42 insertions(+), 1 deletion(-)
21+
create mode 100644 gcc/config/aarch64/host-aarch64-darwin.c
22+
create mode 100644 gcc/config/aarch64/x-darwin
23+
24+
diff --git a/gcc/config.host b/gcc/config.host
25+
index 0a02c33cc8044..81ff7ed1043e2 100644
26+
--- a/gcc/config.host
27+
+++ b/gcc/config.host
28+
@@ -99,7 +99,8 @@ case ${host} in
29+
esac
30+
31+
case ${host} in
32+
- aarch64*-*-freebsd* | aarch64*-*-linux* | aarch64*-*-fuchsia*)
33+
+ aarch64*-*-freebsd* | aarch64*-*-linux* | aarch64*-*-fuchsia* |\
34+
+ aarch64*-*-darwin*)
35+
case ${target} in
36+
aarch64*-*-*)
37+
host_extra_gcc_objs="driver-aarch64.o"
38+
@@ -256,6 +257,10 @@ case ${host} in
39+
host_extra_gcc_objs="${host_extra_gcc_objs} driver-mingw32.o"
40+
host_lto_plugin_soname=liblto_plugin-0.dll
41+
;;
42+
+ aarch64*-*-darwin*)
43+
+ out_host_hook_obj="${out_host_hook_obj} host-aarch64-darwin.o"
44+
+ host_xmake_file="${host_xmake_file} aarch64/x-darwin"
45+
+ ;;
46+
i[34567]86-*-darwin* | x86_64-*-darwin*)
47+
out_host_hook_obj="${out_host_hook_obj} host-i386-darwin.o"
48+
host_xmake_file="${host_xmake_file} i386/x-darwin"
49+
diff --git a/gcc/config/aarch64/host-aarch64-darwin.c b/gcc/config/aarch64/host-aarch64-darwin.c
50+
new file mode 100644
51+
index 0000000000000..d70f2df3bf1b3
52+
--- /dev/null
53+
+++ b/gcc/config/aarch64/host-aarch64-darwin.c
54+
@@ -0,0 +1,33 @@
55+
+/* aarch64/arm64-darwin host-specific hook definitions.
56+
+
57+
+Copyright The GNU Toolchain Authors.
58+
+
59+
+This file is part of GCC.
60+
+
61+
+GCC is free software; you can redistribute it and/or modify it under
62+
+the terms of the GNU General Public License as published by the Free
63+
+Software Foundation; either version 3, or (at your option) any later
64+
+version.
65+
+
66+
+GCC is distributed in the hope that it will be useful, but WITHOUT ANY
67+
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
68+
+FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
69+
+for more details.
70+
+
71+
+You should have received a copy of the GNU General Public License
72+
+along with GCC; see the file COPYING3. If not see
73+
+<http://www.gnu.org/licenses/>. */
74+
+
75+
+#define IN_TARGET_CODE 1
76+
+
77+
+#include "config.h"
78+
+#include "system.h"
79+
+#include "coretypes.h"
80+
+#include "hosthooks.h"
81+
+#include "hosthooks-def.h"
82+
+#include "config/host-darwin.h"
83+
+
84+
+/* Darwin doesn't do anything special for arm64/aarch64 hosts; this file
85+
+ exists just to include the generic config/host-darwin.h. */
86+
+
87+
+const struct host_hooks host_hooks = HOST_HOOKS_INITIALIZER;
88+
diff --git a/gcc/config/aarch64/x-darwin b/gcc/config/aarch64/x-darwin
89+
new file mode 100644
90+
index 0000000000000..6d788d5e89cfb
91+
--- /dev/null
92+
+++ b/gcc/config/aarch64/x-darwin
93+
@@ -0,0 +1,3 @@
94+
+host-aarch64-darwin.o : $(srcdir)/config/aarch64/host-aarch64-darwin.c
95+
+ $(COMPILE) $<
96+
+ $(POSTCOMPILE)

0 commit comments

Comments
 (0)