forked from SerenityOS/serenity
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path0001-Add-a-gcc-driver-for-SerenityOS.patch
179 lines (173 loc) Β· 6.38 KB
/
0001-Add-a-gcc-driver-for-SerenityOS.patch
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
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Andreas Kling <[email protected]>
Date: Fri, 5 Apr 2019 03:02:52 +0200
Subject: [PATCH] Add a gcc driver for SerenityOS
This patch adds support for the `*-*-serenity` target to gcc.
It specifies which flags need to be passed to the linker, defines the
__serenity__ macro, sets the correct underlying type of `size_t` and
`ptrdiff_t`, and enables IFUNCs.
Co-Authored-By: Gunnar Beutner <[email protected]>
Co-Authored-By: Itamar <[email protected]>
Co-Authored-By: Daniel Bertalan <[email protected]>
Co-Authored-By: Nico Weber <[email protected]>
Co-Authored-By: Tim Schumacher <[email protected]>
Co-Authored-By: Andrew Kaster <[email protected]>
Co-Authored-By: Brian Gianforcaro <[email protected]>
Co-Authored-By: Philip Herron <[email protected]>
Co-Authored-By: Shannon Booth <[email protected]>
---
gcc/config.gcc | 23 ++++++++++++++++++
gcc/config/i386/serenity.h | 7 ++++++
gcc/config/serenity.h | 48 ++++++++++++++++++++++++++++++++++++++
gcc/config/serenity.opt | 35 +++++++++++++++++++++++++++
4 files changed, 113 insertions(+)
create mode 100644 gcc/config/i386/serenity.h
create mode 100644 gcc/config/serenity.h
create mode 100644 gcc/config/serenity.opt
diff --git a/gcc/config.gcc b/gcc/config.gcc
index 648b3dc21103e43a315b676c827ff9e6d2923e11..e8a7ea2f50bf908c30b14479bb695cd645261f9e 100644
--- a/gcc/config.gcc
+++ b/gcc/config.gcc
@@ -690,6 +690,18 @@ x86_cpus="generic intel"
# Common parts for widely ported systems.
case ${target} in
+*-*-serenity*)
+ gas=yes
+ gnu_ld=yes
+ default_use_cxa_atexit=yes
+ extra_options="${extra_options} serenity.opt"
+ tmake_file="t-slibgcc"
+ case ${target} in
+ aarch64*-* | riscv64-* | x86_64-*)
+ default_gnu_indirect_function=yes
+ ;;
+ esac
+ ;;
*-*-darwin*)
tmake_file="t-darwin "
tm_file="${tm_file} darwin.h"
@@ -1126,6 +1138,17 @@ case ${target} in
esac
case ${target} in
+x86_64-*-serenity*)
+ tm_file="${tm_file} i386/unix.h i386/att.h elfos.h glibc-stdint.h i386/i386elf.h i386/x86-64.h serenity.h i386/serenity.h"
+ ;;
+aarch64*-*-serenity*)
+ tm_file="${tm_file} elfos.h glibc-stdint.h aarch64/aarch64-elf.h serenity.h"
+ tmake_file="${tmake_file} aarch64/t-aarch64"
+ ;;
+riscv64-*-serenity*)
+ tm_file="${tm_file} elfos.h glibc-stdint.h riscv/elf.h serenity.h"
+ tmake_file="${tmake_file} riscv/t-riscv"
+ ;;
aarch64*-*-elf | aarch64*-*-fuchsia* | aarch64*-*-rtems*)
tm_file="${tm_file} elfos.h newlib-stdint.h"
tm_file="${tm_file} aarch64/aarch64-elf.h aarch64/aarch64-errata.h aarch64/aarch64-elf-raw.h"
diff --git a/gcc/config/i386/serenity.h b/gcc/config/i386/serenity.h
new file mode 100644
index 0000000000000000000000000000000000000000..53a4b8e93b74b4808a4bfed91c4d5558217c584a
--- /dev/null
+++ b/gcc/config/i386/serenity.h
@@ -0,0 +1,7 @@
+/* Ensure that we are using the SIZE_TYPE indicated by SysV */
+#undef SIZE_TYPE
+#define SIZE_TYPE (TARGET_64BIT ? "long unsigned int" : "unsigned int")
+
+/* Ensure that ptrdiff_t matches the actual pointer size */
+#undef PTRDIFF_TYPE
+#define PTRDIFF_TYPE (TARGET_64BIT ? "long int" : "int")
diff --git a/gcc/config/serenity.h b/gcc/config/serenity.h
new file mode 100644
index 0000000000000000000000000000000000000000..10c6f16fbe13eab36bab8f6896f8e2a6ae48df02
--- /dev/null
+++ b/gcc/config/serenity.h
@@ -0,0 +1,48 @@
+/* Useful if you wish to make target-specific GCC changes. */
+#undef TARGET_SERENITY
+#define TARGET_SERENITY 1
+
+#if defined(HAVE_LD_EH_FRAME_HDR)
+#define LINK_EH_SPEC "%{!static|static-pie:--eh-frame-hdr} "
+#endif
+
+/* Default arguments you want when running your
+ x86_64-serenity-gcc toolchain */
+#undef LIB_SPEC
+#define LIB_SPEC "-lc" /* link against C standard library */
+
+/* Files that are linked before user code.
+ The %s tells GCC to look for these files in the library directory. */
+#undef STARTFILE_SPEC
+#define STARTFILE_SPEC "%{!shared:crt0.o%s} crti.o%s %{shared: %{!fbuilding-libgcc:crt0_shared.o%s}} %{shared|static-pie|!no-pie:crtbeginS.o%s; :crtbegin.o%s}"
+
+/* Files that are linked after user code. */
+#undef ENDFILE_SPEC
+#define ENDFILE_SPEC "%{shared|static-pie|!no-pie:crtendS.o%s; :crtend.o%s} crtn.o%s"
+
+#undef LINK_SPEC
+#define LINK_SPEC "%{shared:-shared} %{static:-static} %{!static: %{rdynamic:-export-dynamic} -dynamic-linker /usr/lib/Loader.so}"
+
+#undef CC1_SPEC
+#define CC1_SPEC "-fno-semantic-interposition"
+
+#undef CPP_SPEC
+#define CPP_SPEC "%{posix:-D_POSIX_SOURCE} %{pthread:-D_REENTRANT}"
+
+/* Use --as-needed -lgcc_s for eh support. */
+#define USE_LD_AS_NEEDED 1
+
+/* We don't have a separate math library, it's included within libc. While we do have compatibility
+ linker scripts in place, just don't add it to the linker invocation to begin with. */
+#define MATH_LIBRARY ""
+
+/* Additional predefined macros. */
+#undef TARGET_OS_CPP_BUILTINS
+#define TARGET_OS_CPP_BUILTINS() \
+ do { \
+ builtin_define ("__serenity__"); \
+ builtin_define ("__unix__"); \
+ builtin_assert ("system=serenity"); \
+ builtin_assert ("system=unix"); \
+ builtin_assert ("system=posix"); \
+ } while(0);
diff --git a/gcc/config/serenity.opt b/gcc/config/serenity.opt
new file mode 100644
index 0000000000000000000000000000000000000000..2756a5575480449a2c46b9fdfde541ba2787a263
--- /dev/null
+++ b/gcc/config/serenity.opt
@@ -0,0 +1,35 @@
+; SerenityOS options.
+
+; Copyright (C) 2021 Gunnar Beutner <[email protected]>
+;
+; This file is part of GCC.
+;
+; GCC is free software; you can redistribute it and/or modify it under
+; the terms of the GNU General Public License as published by the Free
+; Software Foundation; either version 3, or (at your option) any later
+; version.
+;
+; GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+; WARRANTY; without even the implied warranty of MERCHANTABILITY or
+; FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+; for more details.
+;
+; You should have received a copy of the GNU General Public License
+; along with GCC; see the file COPYING3. If not see
+; <http://www.gnu.org/licenses/>.
+
+; See the GCC internals manual (options.texi) for a description of
+; this file's format.
+
+; Please try to keep this file in ASCII collating order.
+
+posix
+Driver
+
+pthread
+Driver
+
+rdynamic
+Driver
+
+; This comment is to ensure we retain the blank line above.