Skip to content

Instantly share code, notes, and snippets.

@AmaanC
Created August 13, 2018 14:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AmaanC/7caf41f4d378767378b61c3e0f5f2aed to your computer and use it in GitHub Desktop.
Save AmaanC/7caf41f4d378767378b61c3e0f5f2aed to your computer and use it in GitHub Desktop.
diff --git a/gcc/config.gcc b/gcc/config.gcc
index c3aecbfe764..d0d2be19d8b 100644
--- a/gcc/config.gcc
+++ b/gcc/config.gcc
@@ -1509,7 +1509,7 @@ x86_64-*-elf*)
tm_file="${tm_file} i386/unix.h i386/att.h dbxelf.h elfos.h newlib-stdint.h i386/i386elf.h i386/x86-64.h"
;;
x86_64-*-rtems*)
- tm_file="${tm_file} i386/unix.h i386/att.h dbxelf.h elfos.h newlib-stdint.h i386/i386elf.h i386/x86-64.h i386/rtemself.h rtems.h"
+ tm_file="${tm_file} i386/unix.h i386/att.h dbxelf.h elfos.h newlib-stdint.h i386/i386elf.h i386/x86-64.h i386/rtemself64.h rtems.h"
;;
i[34567]86-*-rdos*)
tm_file="${tm_file} i386/unix.h i386/att.h dbxelf.h elfos.h newlib-stdint.h i386/i386elf.h i386/rdos.h"
diff --git a/gcc/config/i386/rtemself64.h b/gcc/config/i386/rtemself64.h
new file mode 100644
index 00000000000..74d87ccb2cb
--- /dev/null
+++ b/gcc/config/i386/rtemself64.h
@@ -0,0 +1,53 @@
+/* Definitions for rtems targeting an x86_64 using ELF.
+ Copyright (C) 1996-2018 Free Software Foundation, Inc.
+ Contributed by Joel Sherrill (joel@OARcorp.com).
+
+ 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.
+
+ Under Section 7 of GPL version 3, you are granted additional
+ permissions described in the GCC Runtime Library Exception, version
+ 3.1, as published by the Free Software Foundation.
+
+ You should have received a copy of the GNU General Public License and
+ a copy of the GCC Runtime Library Exception along with this program;
+ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
+ <http://www.gnu.org/licenses/>. */
+
+/* Specify predefined symbols in preprocessor. */
+
+#define TARGET_OS_CPP_BUILTINS() \
+ do \
+ { \
+ builtin_define ("__rtems__"); \
+ builtin_define ("__USE_INIT_FINI__"); \
+ builtin_assert ("system=rtems"); \
+ } \
+ while (0)
+
+#undef STARTFILE_SPEC
+#define STARTFILE_SPEC "\
+%{!nostdlib: %{!qrtems: crt0.o%s} crti.o%s \
+ %{!shared:crtbegin.o%s} %{shared:crtbeginS.o%s}}"
+
+#undef ENDFILE_SPEC
+#define ENDFILE_SPEC \
+ "%{!shared:crtend.o%s} %{shared:crtendS.o%s} crtn.o%s"
+
+/* Use -fPIC by default unless specified otherwise */
+#undef CC1_SPEC
+#define CC1_SPEC \
+ "%{!fno-pic:%{!fno-PIC:%{!fpic:%{!fPIC: -fPIC}}}}"
+
+#undef LINK_SPEC
+#define LINK_SPEC \
+ "%{shared:-shared}"
diff --git a/gcc/config/rtems.h b/gcc/config/rtems.h
index dcea95cddad..9a0619cb383 100644
--- a/gcc/config/rtems.h
+++ b/gcc/config/rtems.h
@@ -30,11 +30,15 @@
* Dummy start/end specification to let linker work as
* needed by autoconf scripts using this compiler.
*/
+#if 0
#undef STARTFILE_SPEC
-#define STARTFILE_SPEC "crt0.o%s"
+#define STARTFILE_SPEC "%{!qrtems: crt0.o%s}"
+#endif
+#if 0
#undef ENDFILE_SPEC
#define ENDFILE_SPEC ""
+#endif
/*
* Some targets do not set up LIB_SPECS, override it, here.
diff --git a/libgcc/config.host b/libgcc/config.host
index 18cabaf24f6..3be204a0da0 100644
--- a/libgcc/config.host
+++ b/libgcc/config.host
@@ -613,7 +613,7 @@ x86_64-*-elf* | x86_64-*-rtems*)
tmake_file="$tmake_file i386/t-crtstuff t-crtstuff-pic t-libgcc-pic"
case ${host} in
x86_64-*-rtems*)
- extra_parts="$extra_parts crti.o crtn.o"
+ extra_parts="$extra_parts crti.o crtn.o crtbeginS.o crtendS.o"
;;
esac
;;
@AmaanC
Copy link
Author

AmaanC commented Aug 13, 2018

Built on top of Joel's WIP patch here:
https://lists.rtems.org/pipermail/devel/2018-May/021587.html

I just wanted to add sane defaults for when the -fPIC -shared options are used during compilation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment