From: Sebastian Huber <sebastian.huber@embedded-brains.de>
To: gcc@gcc.gnu.org
Subject: How can operating systems add linker flags to the GCC specs?
Date: Fri, 22 Jan 2021 10:46:50 +0100 [thread overview]
Message-ID: <fa058e66-956f-5309-fc18-44f3029d9051@embedded-brains.de> (raw)
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/
next reply other threads:[~2021-01-22 9:46 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-01-22 9:46 Sebastian Huber [this message]
2021-01-22 11:58 ` Sebastian Huber
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=fa058e66-956f-5309-fc18-44f3029d9051@embedded-brains.de \
--to=sebastian.huber@embedded-brains.de \
--cc=gcc@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).