Gabe Black has submitted this change. ( https://gem5-review.googlesource.com/c/public/gem5/+/49003 )

Change subject: scons: Add a --linker option.
......................................................................

scons: Add a --linker option.

There is currently a "--gold-linker" option, which tells SCons to use
the gold linker. This puts the gold linker in a special position where
it has its own command line option, and makes it impossible to
explicitly select any other linker.

This change adds a --linker option which can be set to "bfd" (the
default gnu linker), "gold" (the gnu gold linker), or "lld" which is the
clang linker. If none is specified, SCons will let the compiler fall
back to whatever its default is.

The --gold-linker option is modified so that it just sets the --linker
option for you. Because of how SCons handles adding command line
options, there isn't a good way to complain if both it and --linker is
used, nor is there a good way to warn that the user is using a
deprecated command line option. A warning is in the help text for that
option now, though.

If the gold linker is selected, this change also sets the --threads
option, and sets the --thread-count option. This tells the gold linker
to run multi-threaded to speed up linking. Apparently the gold linker
must have been built with an option that enables threading for these
options to have any effect. If threads and LTO are both enabled, the
gold linker segfaults. To avoid that problem, we don't add --threads if
LTO has been enabled.

This change also enables a new configuration, where lld, the clang
linker, can be used with gcc. Unfortunately the format of LTO
information gcc/g++ generates is not compatible with lld, and so if you
set the linker to lld and enable LTO, you'll probably get errors like
not being able to find the symbol "main".

This change also allows you to select the default gnu linker ("bfd")
when using clang, although it's not clear why you would want to do that.

Change-Id: Ib37030431527f5d0bc626e9594b2e1142df889be
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/49003
Reviewed-by: Daniel Carvalho <[email protected]>
Reviewed-by: Giacomo Travaglini <[email protected]>
Tested-by: kokoro <[email protected]>
Maintainer: Gabe Black <[email protected]>
---
M SConstruct
1 file changed, 66 insertions(+), 3 deletions(-)

Approvals:
  Giacomo Travaglini: Looks good to me, approved
  Daniel Carvalho: Looks good to me, but someone else must approve
  Gabe Black: Looks good to me, approved
  kokoro: Regressions pass




diff --git a/SConstruct b/SConstruct
index ceeb1ba..60493ae 100755
--- a/SConstruct
+++ b/SConstruct
@@ -98,6 +98,8 @@
 #
 ########################################################################

+linker_options = ('bfd', 'gold', 'lld')
+
 AddOption('--no-colors', dest='use_colors', action='store_false',
           help="Don't add color to abbreviated scons output")
 AddOption('--with-cxx-config', action='store_true',
@@ -106,7 +108,10 @@
           help='Override which build_opts file to use for defaults')
 AddOption('--ignore-style', action='store_true',
           help='Disable style checking hooks')
-AddOption('--gold-linker', action='store_true', help='Use the gold linker')
+AddOption('--linker', action='store', default=None, choices=linker_options,
+          help=f'Select which linker to use ({", ".join(linker_options)})')
+AddOption('--gold-linker', action='store_const', const='gold', dest='linker',
+          help='Use the gold linker. Deprecated: Use --linker=gold')
 AddOption('--no-compress-debug', action='store_true',
           help="Don't compress debug info in build files")
 AddOption('--with-lto', action='store_true',
@@ -345,8 +350,18 @@

     with gem5_scons.Configure(main) as conf:
         conf.CheckLinkFlag('-Wl,--as-needed')
-    if GetOption('gold_linker'):
-        main.Append(LINKFLAGS='-fuse-ld=gold')
+
+    linker = GetOption('linker')
+    if linker:
+        with gem5_scons.Configure(main) as conf:
+            if not conf.CheckLinkFlag(f'-fuse-ld={linker}'):
+                error(f'Linker "{linker}" is not supported')
+            if linker == 'gold' and not GetOption('with_lto'):
+                # Tell the gold linker to use threads. The gold linker
+                # segfaults if both threads and LTO are enabled.
+                conf.CheckLinkFlag('-Wl,--threads')
+                conf.CheckLinkFlag(
+                        '-Wl,--thread-count=%d' % GetOption('num_jobs'))

 else:
     error('\n'.join((

--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/49003
To unsubscribe, or for help writing mail filters, visit https://gem5-review.googlesource.com/settings

Gerrit-Project: public/gem5
Gerrit-Branch: develop
Gerrit-Change-Id: Ib37030431527f5d0bc626e9594b2e1142df889be
Gerrit-Change-Number: 49003
Gerrit-PatchSet: 5
Gerrit-Owner: Gabe Black <[email protected]>
Gerrit-Reviewer: Bobby Bruce <[email protected]>
Gerrit-Reviewer: Daniel Carvalho <[email protected]>
Gerrit-Reviewer: Gabe Black <[email protected]>
Gerrit-Reviewer: Giacomo Travaglini <[email protected]>
Gerrit-Reviewer: Nikos Nikoleris <[email protected]>
Gerrit-Reviewer: kokoro <[email protected]>
Gerrit-CC: Alex Richardson <[email protected]>
Gerrit-CC: Earl Ou <[email protected]>
Gerrit-CC: Jason Lowe-Power <[email protected]>
Gerrit-MessageType: merged
_______________________________________________
gem5-dev mailing list -- [email protected]
To unsubscribe send an email to [email protected]
%(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s

Reply via email to