Hello,

for RTEMS we have in gcc/config/rtems.h the following LIB_SPEC:

#undef LIB_SPEC
#define LIB_SPEC "%{!qrtems:" STD_LIB_SPEC "} " \
"%{qrtems:%{!nostdlib:%{!nodefaultlibs:" \
"--start-group -lrtemsbsp -lrtemscpu -latomic -lc -lgcc --end-group} " \
"%{!qnolinkcmds:-T linkcmds%s}}}"

The intention was that a GCC command line to link an executable with

-qrtems -nodefaultlibs

still uses "-T linkcmds", however, this didn't work. I think this is due to

*link_gcc_c_sequence:
%G %{!nolibc:%L %G}

*link_command:
... %{!nostdlib:%{!r:%{!nodefaultlibs:%(link_ssp) %(link_gcc_c_sequence)}}} ...
%(post_link) }}}}}}

So, if nodefaultlib is present, the LIB_SPEC is not evaluated at all?

The problem is that LINK_SPEC is specialized by target. For RTEMS, we have to use the target definitions. In the default definition of LINK_COMMAND_SPEC (gcc/gcc.c) there is no define for operating system customization. Would it be possible to add something this?

diff --git a/gcc/config/rtems.h b/gcc/config/rtems.h
index 743161c4bac..a7cea9b1d2f 100644
--- a/gcc/config/rtems.h
+++ b/gcc/config/rtems.h
@@ -49,9 +49,9 @@

 #undef LIB_SPEC
 #define LIB_SPEC "%{!qrtems:" STD_LIB_SPEC "} " \
-"%{qrtems:%{!nostdlib:%{!nodefaultlibs:" \
-"--start-group -lrtemsbsp -lrtemscpu -latomic -lc -lgcc --end-group} " \
-"%{!qnolinkcmds:-T linkcmds%s}}}"
+"%{qrtems:--start-group -lrtemsbsp -lrtemscpu -latomic -lc -lgcc --end-group}"
+
+#define SYSTEM_LINK_SPEC "%{qrtems:%{!qnolinkcmds:-T linkcmds%s}}"

 #define TARGET_POSIX_IO

diff --git a/gcc/gcc.c b/gcc/gcc.c
index 7dccfadfef2..eff72cb3412 100644
--- a/gcc/gcc.c
+++ b/gcc/gcc.c
@@ -1107,6 +1107,11 @@ proper position among the other output files.  */
     %{%:sanitize(leak):" LIBLSAN_SPEC "}}}}"
 #endif

+/* Linker command line options defined by the operating system. */
+#ifndef SYSTEM_LINK_SPEC
+#define SYSTEM_LINK_SPEC ""
+#endif
+
 #ifndef POST_LINK_SPEC
 #define POST_LINK_SPEC ""
 #endif
@@ -1158,7 +1163,8 @@ proper position among the other output files.  */
        %:include(libgomp.spec)%(link_gomp)}\
     %{fgnu-tm:%:include(libitm.spec)%(link_itm)}\
     %(mflib) " STACK_SPLIT_SPEC "\
-    %{fprofile-arcs|fprofile-generate*|coverage:-lgcov} " SANITIZER_SPEC " \
+    %{fprofile-arcs|fprofile-generate*|coverage:-lgcov} " \
+    SANITIZER_SPEC " " SYSTEM_LINK_SPEC " \
     %{!nostdlib:%{!r:%{!nodefaultlibs:%(link_ssp) %(link_gcc_c_sequence)}}}\
     %{!nostdlib:%{!r:%{!nostartfiles:%E}}} %{T*}  \n%(post_link) }}}}}}"
 #endif

--
embedded brains GmbH
Herr Sebastian HUBER
Dornierstr. 4
82178 Puchheim
Germany
email: sebastian.hu...@embedded-brains.de
phone: +49-89-18 94 741 - 16
fax:   +49-89-18 94 741 - 08

Registergericht: Amtsgericht München
Registernummer: HRB 157899
Vertretungsberechtigte Geschäftsführer: Peter Rasmussen, Thomas Dörfler
Unsere Datenschutzerklärung finden Sie hier:
https://embedded-brains.de/datenschutzerklaerung/

Reply via email to