Gabe Black has uploaded this change for review. ( 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. I think this has had stability problems in
the past, and so may not be something we actually want to use.

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
---
M SConstruct
1 file changed, 18 insertions(+), 3 deletions(-)



diff --git a/SConstruct b/SConstruct
index 617c7b4..f787bdc 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',
@@ -246,6 +251,7 @@
     ('EXTRAS', 'Add extra directories to the compilation', '')
     )

+
 # Update main environment with values from ARGUMENTS & global_vars_file
 global_vars.Update(main)
 Help('''
@@ -327,8 +333,17 @@

     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':
+                # Tell the gold linker to use threads.
+                conf.CheckLinkFlag('-Wl,--threads')
+                conf.CheckLinkFlag(
+                        '-Wl,--thread-count=%d' % GetOption('num_jobs'))

     # Treat warnings as errors but white list some warnings that we
     # want to allow (e.g., deprecation warnings).

--
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: 1
Gerrit-Owner: Gabe Black <[email protected]>
Gerrit-MessageType: newchange
_______________________________________________
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