1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 21:08:12 +00:00
serenity/Toolchain/Patches/gcc.patch
Daniel Bertalan 6cf260c7af Toolchain: Upgrade to GCC 12.1.0
This release brings support for various C++23 constructs like `if
consteval` and multidimensional subscript operators. Vectorization is
now enabled for O2 too, and `-ftrivial-auto-var-init` has been added
which can help us find and prevent security issues coming from
uninitialized variables.

Toolchain/Patches/gcc.patch is now significanly smaller as some unused,
autoconf-generated code has been removed.
2022-05-12 13:12:37 +02:00

332 lines
11 KiB
Diff

diff --git a/fixincludes/mkfixinc.sh b/fixincludes/mkfixinc.sh
index df90720b7..a45cdd0de 100755
--- a/fixincludes/mkfixinc.sh
+++ b/fixincludes/mkfixinc.sh
@@ -11,6 +11,7 @@ target=fixinc.sh
# Check for special fix rules for particular targets
case $machine in
+ *-serenity* | \
i?86-*-cygwin* | \
i?86-*-mingw32* | \
x86_64-*-mingw32* | \
diff --git a/gcc/common.opt b/gcc/common.opt
index 8a0dafc52..a4f888953 100644
--- a/gcc/common.opt
+++ b/gcc/common.opt
@@ -3607,4 +3607,8 @@ fipa-ra
Common Var(flag_ipa_ra) Optimization
Use caller save register across calls if possible.
+arch
+Driver Ignore Separate
+-arch <name> Generate output for architecture <name>.
+
; This comment is to ensure we retain the blank line above.
diff --git a/gcc/config.gcc b/gcc/config.gcc
index c5064dd37..f8a468c6f 100644
--- a/gcc/config.gcc
+++ b/gcc/config.gcc
@@ -673,6 +673,13 @@ 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"
+ ;;
*-*-darwin*)
tmake_file="t-darwin "
tm_file="${tm_file} darwin.h"
@@ -1087,6 +1094,19 @@ case ${target} in
esac
case ${target} in
+i[34567]86-*-serenity*)
+ default_gnu_indirect_function=yes
+ tm_file="${tm_file} i386/unix.h i386/att.h dbxelf.h elfos.h glibc-stdint.h i386/i386elf.h serenity.h i386/serenity.h"
+ ;;
+x86_64-*-serenity*)
+ default_gnu_indirect_function=yes
+ tm_file="${tm_file} i386/unix.h i386/att.h dbxelf.h elfos.h glibc-stdint.h i386/i386elf.h i386/x86-64.h serenity.h i386/serenity.h"
+ ;;
+aarch64-*-serenity*)
+ default_gnu_indirect_function=yes
+ tm_file="${tm_file} dbxelf.h elfos.h aarch64/aarch64-elf.h glibc-stdint.h serenity.h"
+ tmake_file="${tmake_file} aarch64/t-aarch64"
+ ;;
aarch64*-*-elf | aarch64*-*-fuchsia* | aarch64*-*-rtems*)
tm_file="${tm_file} dbxelf.h 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 000000000..53a4b8e93
--- /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 000000000..dc2f5361e
--- /dev/null
+++ b/gcc/config/serenity.h
@@ -0,0 +1,47 @@
+/* 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
+ i686-serenity-gcc/x86_64-serenity-gcc toolchain */
+#undef LIB_SPEC
+#define LIB_SPEC "%{pthread:-lpthread} -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 "-ftls-model=initial-exec %{!fno-pic:%{!fno-PIC:%{!fpic:%{!fPIC: -fPIC}}}} -fno-semantic-interposition"
+
+#undef CC1PLUS_SPEC
+#define CC1PLUS_SPEC "-ftls-model=initial-exec"
+
+#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
+
+/* 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 000000000..2756a5575
--- /dev/null
+++ b/gcc/config/serenity.opt
@@ -0,0 +1,35 @@
+; SerenityOS options.
+
+; Copyright (C) 2021 Gunnar Beutner <gunnar@beutner.name>
+;
+; 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.
diff --git a/gcc/configure b/gcc/configure
index 5ce055771..2deaac5bc 100755
--- a/gcc/configure
+++ b/gcc/configure
@@ -31608,6 +31608,9 @@ case "$target" in
*-linux-musl*)
gcc_cv_target_dl_iterate_phdr=yes
;;
+ *-serenity*)
+ gcc_cv_target_dl_iterate_phdr=yes
+ ;;
esac
if test x$gcc_cv_target_dl_iterate_phdr = xyes; then
diff --git a/libgcc/config.host b/libgcc/config.host
index 8c56fcae5..f5855cfa6 100644
--- a/libgcc/config.host
+++ b/libgcc/config.host
@@ -1534,6 +1534,22 @@ nvptx-*)
tmake_file="$tmake_file nvptx/t-nvptx"
extra_parts="crt0.o"
;;
+i[34567]86-*-serenity*)
+ extra_parts="$extra_parts crti.o crtbegin.o crtbeginS.o crtend.o crtendS.o crtn.o"
+ tmake_file="$tmake_file i386/t-crtstuff t-crtstuff-pic t-libgcc-pic t-slibgcc t-eh-dw2-dip"
+ ;;
+x86_64-*-serenity*)
+ extra_parts="$extra_parts crti.o crtbegin.o crtbeginS.o crtend.o crtendS.o crtn.o"
+ tmake_file="$tmake_file i386/t-crtstuff t-crtstuff-pic t-libgcc-pic t-slibgcc t-eh-dw2-dip"
+ ;;
+aarch64-*-serenity*)
+ extra_parts="$extra_parts crti.o crtbegin.o crtend.o crtn.o"
+ extra_parts="$extra_parts crtfastmath.o"
+ tmake_file="$tmake_file ${cpu_type}/t-aarch64"
+ tmake_file="$tmake_file ${cpu_type}/t-lse t-slibgcc-libgcc"
+ tmake_file="$tmake_file ${cpu_type}/t-softfp t-softp t-crtfm"
+ md_unwind_header=aarch64/aarch64-unwind.h
+ ;;
*)
echo "*** Configuration ${host} not supported" 1>&2
exit 1
diff --git a/libgcc/config/t-slibgcc b/libgcc/config/t-slibgcc
index 4efd7b43d..932fa0cfb 100644
--- a/libgcc/config/t-slibgcc
+++ b/libgcc/config/t-slibgcc
@@ -26,7 +26,6 @@ SHLIB_MAP = @shlib_map_file@
SHLIB_OBJS = @shlib_objs@
SHLIB_DIR = @multilib_dir@
SHLIB_SLIBDIR_QUAL = @shlib_slibdir_qual@
-SHLIB_LC = -lc
SHLIB_MAKE_SOLINK = $(LN_S) $(SHLIB_SONAME) $(SHLIB_DIR)/$(SHLIB_SOLINK)
SHLIB_INSTALL_SOLINK = $(LN_S) $(SHLIB_SONAME) \
$(DESTDIR)$(slibdir)$(SHLIB_SLIBDIR_QUAL)/$(SHLIB_SOLINK)
diff --git a/libgcc/unwind-dw2-fde-dip.c b/libgcc/unwind-dw2-fde-dip.c
index 7f9be5e6b..817c3fe21 100644
--- a/libgcc/unwind-dw2-fde-dip.c
+++ b/libgcc/unwind-dw2-fde-dip.c
@@ -57,6 +57,12 @@
# define USE_PT_GNU_EH_FRAME
#endif
+#if !defined(inhibit_libc) && defined(HAVE_LD_EH_FRAME_HDR) \
+ && defined(TARGET_DL_ITERATE_PHDR) \
+ && defined(__serenity__)
+# define USE_PT_GNU_EH_FRAME
+#endif
+
#if !defined(inhibit_libc) && defined(HAVE_LD_EH_FRAME_HDR) \
&& defined(TARGET_DL_ITERATE_PHDR) \
&& defined(__linux__)
diff --git a/libstdc++-v3/acinclude.m4 b/libstdc++-v3/acinclude.m4
index 138bd58d8..6cd7564b6 100644
--- a/libstdc++-v3/acinclude.m4
+++ b/libstdc++-v3/acinclude.m4
@@ -1374,7 +1374,7 @@ AC_DEFUN([GLIBCXX_ENABLE_LIBSTDCXX_TIME], [
ac_has_nanosleep=yes
ac_has_sched_yield=yes
;;
- freebsd*|netbsd*|dragonfly*|rtems*)
+ freebsd*|netbsd*|dragonfly*|rtems*|serenity*)
ac_has_clock_monotonic=yes
ac_has_clock_realtime=yes
ac_has_nanosleep=yes
@@ -2421,7 +2421,7 @@ AC_DEFUN([GLIBCXX_ENABLE_CLOCALE], [
dragonfly* | freebsd*)
enable_clocale_flag=dragonfly
;;
- openbsd*)
+ openbsd* | serenity*)
enable_clocale_flag=newlib
;;
*)
diff --git a/libstdc++-v3/configure b/libstdc++-v3/configure
index 9b94fd71e..51e45878f 100755
--- a/libstdc++-v3/configure
+++ b/libstdc++-v3/configure
@@ -11914,6 +11914,11 @@ else
lt_cv_dlopen_libs=
;;
+ serenity*)
+ lt_cv_dlopen="dlopen"
+ lt_cv_dlopen_libs="-ldl"
+ ;;
+
darwin*)
# if libdl is installed we need to link against it
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for dlopen in -ldl" >&5
@@ -16478,7 +16483,7 @@ fi
dragonfly* | freebsd*)
enable_clocale_flag=dragonfly
;;
- openbsd*)
+ openbsd* | serenity*)
enable_clocale_flag=newlib
;;
*)
@@ -20569,7 +20574,7 @@ fi
ac_has_nanosleep=yes
ac_has_sched_yield=yes
;;
- freebsd*|netbsd*|dragonfly*|rtems*)
+ freebsd*|netbsd*|dragonfly*|rtems*|serenity*)
ac_has_clock_monotonic=yes
ac_has_clock_realtime=yes
ac_has_nanosleep=yes
@@ -29245,7 +29250,7 @@ case "${host}" in
# This is a freestanding configuration; there is nothing to do here.
;;
- avr*-*-*)
+ avr*-*-* | *serenity*)
$as_echo "#define HAVE_ACOSF 1" >>confdefs.h
$as_echo "#define HAVE_ASINF 1" >>confdefs.h
diff --git a/libstdc++-v3/configure.host b/libstdc++-v3/configure.host
index ec32980aa..e060300f3 100644
--- a/libstdc++-v3/configure.host
+++ b/libstdc++-v3/configure.host
@@ -297,6 +297,9 @@ case "${host_os}" in
# Use libatomic if necessary and avoid libstdc++ specific atomicity support
atomicity_dir="cpu/generic/atomicity_builtins"
;;
+ serenity*)
+ os_include_dir="os/newlib"
+ ;;
solaris2*)
os_include_dir="os/solaris"
;;
diff --git a/libstdc++-v3/crossconfig.m4 b/libstdc++-v3/crossconfig.m4
index ae5283b7a..b9fc96e94 100644
--- a/libstdc++-v3/crossconfig.m4
+++ b/libstdc++-v3/crossconfig.m4
@@ -9,7 +9,7 @@ case "${host}" in
# This is a freestanding configuration; there is nothing to do here.
;;
- avr*-*-*)
+ avr*-*-* | *serenity*)
AC_DEFINE(HAVE_ACOSF)
AC_DEFINE(HAVE_ASINF)
AC_DEFINE(HAVE_ATAN2F)