* How can operating systems add linker flags to the GCC specs?
@ 2021-01-22 9:46 Sebastian Huber
2021-01-22 11:58 ` Sebastian Huber
0 siblings, 1 reply; 2+ messages in thread
From: Sebastian Huber @ 2021-01-22 9:46 UTC (permalink / raw)
To: gcc
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.huber@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/
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: How can operating systems add linker flags to the GCC specs?
2021-01-22 9:46 How can operating systems add linker flags to the GCC specs? Sebastian Huber
@ 2021-01-22 11:58 ` Sebastian Huber
0 siblings, 0 replies; 2+ messages in thread
From: Sebastian Huber @ 2021-01-22 11:58 UTC (permalink / raw)
To: gcc
On 22/01/2021 10:46, Sebastian Huber wrote:
> 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?
I think the STARTFILES_SPEC can be used as a workaround:
https://gcc.gnu.org/pipermail/gcc-patches/2021-January/564101.html
This avoids modifications in "gcc/gcc.c".
--
embedded brains GmbH
Herr Sebastian HUBER
Dornierstr. 4
82178 Puchheim
Germany
email: sebastian.huber@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/
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-01-22 11:58 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-22 9:46 How can operating systems add linker flags to the GCC specs? Sebastian Huber
2021-01-22 11:58 ` Sebastian Huber
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).