cros_setup_toolchains.py: remove gold linker support

After upgrading from binutils 2.27 -> 2.35.1 the gold linker
is disabled, so its setup logic can be removed and the sanity
checks modified to only look for ld/ld.bfd and assert when
gold is enabled.

BUG=chromium:1163741
TEST=Local x64/arm build with binutils --without-gold and
also with the new binutils --with-gold=dwp option in 2.35.1.

Cq-Depend: chromium:2635222, chromium:2626657, chromium:2626659
Change-Id: I4f53dfc2c0800b3509bfae42d03492142add3eb8
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/chromite/+/2627397
Tested-by: Manoj Gupta <manojgupta@chromium.org>
Reviewed-by: Mike Frysinger <vapier@chromium.org>
Reviewed-by: Manoj Gupta <manojgupta@chromium.org>
Commit-Queue: Manoj Gupta <manojgupta@chromium.org>
diff --git a/scripts/cros_setup_toolchains.py b/scripts/cros_setup_toolchains.py
index 71d9d57..71523c3 100644
--- a/scripts/cros_setup_toolchains.py
+++ b/scripts/cros_setup_toolchains.py
@@ -118,19 +118,6 @@
     'ex_llvm-libunwind' : ['--ex-pkg', 'sys-libs/llvm-libunwind'],
 }
 
-# Overrides for {gcc,binutils}-config, pick a package with particular suffix.
-CONFIG_TARGET_SUFFIXES = {
-    'binutils' : {
-        'aarch64-cros-linux-gnu' : '-gold',
-        'armv6j-cros-linux-gnueabi': '-gold',
-        'armv7a-cros-linux-gnueabi': '-gold',
-        'armv7a-cros-linux-gnueabihf': '-gold',
-        'i686-pc-linux-gnu' : '-gold',
-        'x86_64-cros-linux-gnu' : '-gold',
-    },
-}
-
-
 class Crossdev(object):
   """Class for interacting with crossdev and caching its output."""
 
@@ -624,12 +611,11 @@
     logging.info('Nothing to clean!')
 
 
-def SelectActiveToolchains(targets, suffixes, root='/'):
+def SelectActiveToolchains(targets, root='/'):
   """Runs gcc-config and binutils-config to select the desired.
 
   Args:
     targets: The targets to select
-    suffixes: Optional target-specific hacks
     root: The root where we want to select toolchain versions.
   """
   for package in ['gcc', 'binutils']:
@@ -654,11 +640,6 @@
       # And finally, attach target to it.
       desired = '%s-%s' % (target, desired)
 
-      # Target specific hacks
-      if package in suffixes:
-        if target in suffixes[package]:
-          desired += suffixes[package][target]
-
       extra_env = {'CHOST': target}
       if root != '/':
         extra_env['ROOT'] = root
@@ -755,7 +736,7 @@
 
   # Now update all packages.
   if UpdateTargets(targets, usepkg, root=root) or crossdev_targets or reconfig:
-    SelectActiveToolchains(targets, CONFIG_TARGET_SUFFIXES, root=root)
+    SelectActiveToolchains(targets, root=root)
 
   if deleteold:
     CleanTargets(targets, root=root)
@@ -1125,40 +1106,18 @@
   """Do what binutils-config would have done"""
   binpath = os.path.join('/bin', target + '-')
 
-  # Locate the bin dir holding the gold linker.
+  # Locate the bin dir holding the linker and perform some sanity checks
   binutils_bin_path = os.path.join(output_dir, 'usr', toolchain.GetHostTuple(),
                                    target, 'binutils-bin')
-  globpath = os.path.join(binutils_bin_path, '*-gold')
+  globpath = os.path.join(binutils_bin_path, '*')
   srcpath = glob.glob(globpath)
-  if not srcpath:
-    # Maybe this target doesn't support gold.
-    globpath = os.path.join(binutils_bin_path, '*')
-    srcpath = glob.glob(globpath)
-    assert len(srcpath) == 1, ('%s: matched more than one path (but not *-gold)'
-                               % globpath)
-    srcpath = srcpath[0]
-    ld_path = os.path.join(srcpath, 'ld')
-    assert os.path.exists(ld_path), '%s: linker is missing!' % ld_path
-    ld_path = os.path.join(srcpath, 'ld.bfd')
-    assert os.path.exists(ld_path), '%s: linker is missing!' % ld_path
-    ld_path = os.path.join(srcpath, 'ld.gold')
-    assert not os.path.exists(ld_path), ('%s: exists, but gold dir does not!'
-                                         % ld_path)
-
-    # Nope, no gold support to be found.
-    gold_supported = False
-    logging.warning('%s: binutils lacks support for the gold linker', target)
-  else:
-    assert len(srcpath) == 1, '%s: did not match exactly 1 path' % globpath
-    srcpath = srcpath[0]
-
-    # Package the binutils-bin directory without the '-gold' suffix
-    # if gold is not enabled as the default linker for this target.
-    gold_supported = CONFIG_TARGET_SUFFIXES['binutils'].get(target) == '-gold'
-    if not gold_supported:
-      srcpath = srcpath[:-len('-gold')]
-      ld_path = os.path.join(srcpath, 'ld')
-      assert os.path.exists(ld_path), '%s: linker is missing!' % ld_path
+  assert len(srcpath) == 1, ('%s: matched more than one path. Is Gold enabled?'
+                             % globpath)
+  srcpath = srcpath[0]
+  ld_path = os.path.join(srcpath, 'ld')
+  assert os.path.exists(ld_path), '%s: linker is missing!' % ld_path
+  ld_path = os.path.join(srcpath, 'ld.bfd')
+  assert os.path.exists(ld_path), '%s: linker is missing!' % ld_path
 
   srcpath = srcpath[len(output_dir):]
   gccpath = os.path.join('/usr', 'libexec', 'gcc')
@@ -1172,14 +1131,6 @@
 
   libpath = os.path.join('/usr', toolchain.GetHostTuple(), target, 'lib')
   envd = os.path.join(output_dir, 'etc', 'env.d', 'binutils', '*')
-  if gold_supported:
-    envd += '-gold'
-  else:
-    # If gold is not enabled as the default linker and 2 env.d
-    # files exist, pick the one without the '-gold' suffix.
-    envds = sorted(glob.glob(envd))
-    if len(envds) == 2 and envds[1] == envds[0] + '-gold':
-      envd = envds[0]
   srcpath = _EnvdGetVar(envd, 'LIBPATH')
   os.symlink(os.path.relpath(srcpath, os.path.dirname(libpath)),
              output_dir + libpath)