From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Andreas Kling 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 Co-Authored-By: Itamar Co-Authored-By: Daniel Bertalan Co-Authored-By: Nico Weber Co-Authored-By: Tim Schumacher Co-Authored-By: Andrew Kaster Co-Authored-By: Brian Gianforcaro Co-Authored-By: Philip Herron Co-Authored-By: Shannon Booth --- gcc/config.gcc | 19 ++++++++++++++ gcc/config/i386/serenity.h | 7 ++++++ gcc/config/serenity.h | 51 ++++++++++++++++++++++++++++++++++++++ gcc/config/serenity.opt | 35 ++++++++++++++++++++++++++ 4 files changed, 112 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 6fd1594480a1d2054f499573b498781dfafd1d93..8e3d6c378796f324b904a7c58b274472362600fb 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*-* | x86_64-*) + default_gnu_indirect_function=yes + ;; + esac + ;; *-*-darwin*) tmake_file="t-darwin " tm_file="${tm_file} darwin.h" @@ -1126,6 +1138,13 @@ 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" + ;; 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..b1fc4bb63facc9514bf300a84edbaefe56fee324 --- /dev/null +++ b/gcc/config/serenity.h @@ -0,0 +1,51 @@ +/* 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 "-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 + +/* 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 +; +; 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 +; . + +; 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.