mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 11:02:43 +00:00 
			
		
		
		
	
		
			
				
	
	
		
			179 lines
		
	
	
	
		
			6.6 KiB
		
	
	
	
		
			Diff
		
	
	
	
	
	
			
		
		
	
	
			179 lines
		
	
	
	
		
			6.6 KiB
		
	
	
	
		
			Diff
		
	
	
	
	
	
| From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
 | |
| From: Andreas Kling <awesomekling@gmail.com>
 | |
| 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 <gbeutner@serenityos.org>
 | |
| Co-Authored-By: Itamar <itamar8910@gmail.com>
 | |
| Co-Authored-By: Daniel Bertalan <dani@danielbertalan.dev>
 | |
| Co-Authored-By: Nico Weber <thakis@chromium.org>
 | |
| Co-Authored-By: Tim Schumacher <timschumi@gmx.de>
 | |
| Co-Authored-By: Andrew Kaster <andrewdkaster@gmail.com>
 | |
| Co-Authored-By: Brian Gianforcaro <bgianf@serenityos.org>
 | |
| Co-Authored-By: Philip Herron <herron.philip@googlemail.com>
 | |
| Co-Authored-By: Shannon Booth <shannon.ml.booth@gmail.com>
 | |
| ---
 | |
|  gcc/config.gcc             | 20 +++++++++++++++
 | |
|  gcc/config/i386/serenity.h |  7 ++++++
 | |
|  gcc/config/serenity.h      | 51 ++++++++++++++++++++++++++++++++++++++
 | |
|  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 c5064dd376660c192d5573997b4fc86b6b3e3838..f8a468c6f86c559eda37f780cf592245e42c78ac 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 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..17551aaa1a07e6c0b7365f98899375122ba12529
 | |
| --- /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:%:if-exists-else(crtbeginS.o%s crtbegin.o%s); :crtbegin.o%s}"
 | |
| +
 | |
| +/* Files that are linked after user code. */
 | |
| +#undef ENDFILE_SPEC
 | |
| +#define ENDFILE_SPEC "%{shared|static-pie|!no-pie:%:if-exists-else(crtendS.o%s crtend.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 <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.
 | 
