scripts/generate_reclient_inputs: Add ld.so* files to inputs

Add /etc/ld.so.* files to toolchain inputs. Otherwise,
reclient RBE can not fing libgcc_s.so which is in a
gcc install directory and not in /usr/lib64.

Also simplify some clang deps logic by starting deps
search using clang binary itself.

BUG=b:201570160
TEST=generate_reclient_inputs
TEST=checked /usr/bin/remote_toolchain_inputs contents

Change-Id: Ie7f63208c9041d15ade55982d5bb8196599d115d
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/chromite/+/3437303
Reviewed-by: Mike Frysinger <vapier@chromium.org>
Commit-Queue: Manoj Gupta <manojgupta@chromium.org>
Tested-by: Manoj Gupta <manojgupta@chromium.org>
Auto-Submit: Manoj Gupta <manojgupta@chromium.org>
diff --git a/scripts/generate_reclient_inputs.py b/scripts/generate_reclient_inputs.py
index 4e285cb..a477c47 100644
--- a/scripts/generate_reclient_inputs.py
+++ b/scripts/generate_reclient_inputs.py
@@ -42,7 +42,7 @@
 def _CollectElfDeps(elfpath: Path) -> Set[Path]:
   """Returns the set of dependent files for the elf file."""
   libs = set()
-  to_process = []
+  to_process = [elfpath]
   elf = lddtree.ParseELF(elfpath, ldpaths=lddtree.LoadLdpaths())
   for _, lib_data in elf['libs'].items():
     if lib_data['path']:
@@ -68,18 +68,20 @@
 
   # Clang is typically a symlink, collect actual files.
   paths.add(clang_path)
-  clang_file = clang_path
-  while clang_file.is_symlink():
-    clang_file = _GetSymLinkPath(clang_file.parent, os.readlink(clang_file))
-    paths.add(clang_file)
 
-  # Add clang resource directory and gcc config directory.
+  # Add clang resources, gcc config and glibc loader files.
   cmd = [str(clang_path), '--print-resource-dir']
   resource_dir = cros_build_lib.run(
       cmd, capture_output=True, encoding='utf-8',
       print_cmd=False).stdout.splitlines()[0]
   paths.add(Path(resource_dir) / 'share')
-  paths.add(Path('/etc/env.d/gcc'))
+  paths.update(
+      Path(x) for x in (
+          '/etc/env.d/gcc',
+          '/etc/ld.so.cache',
+          '/etc/ld.so.conf',
+          '/etc/ld.so.conf.d',
+      ))
 
   # Write the files relative to clang binary location.
   osutils.WriteFile(