cros_setup_toolchains: flip order for copying ELFs
We currently copy the programs, generate their wrappers, and then copy
their libs. This means the programs are temporarily broken, but it's
not a big deal as we don't plan on running any of this before we've
finished copying everything.
This breaks when the wrapper generation needs to probe some of the libs
(namely the ldso). Flip the order so we copy all the deps first, and
then we generate the wrapper.
BUG=chromium:1201270
TEST=`cros_setup_toolchains --create-packages` passes
Change-Id: I945b7e1879482ee0f4b085397a0022e0942729c1
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/chromite/+/2845231
Reviewed-by: Manoj Gupta <manojgupta@chromium.org>
Tested-by: Manoj Gupta <manojgupta@chromium.org>
diff --git a/scripts/cros_setup_toolchains.py b/scripts/cros_setup_toolchains.py
index 57ebbbb..1042ea5 100644
--- a/scripts/cros_setup_toolchains.py
+++ b/scripts/cros_setup_toolchains.py
@@ -1033,23 +1033,12 @@
e = lddtree.ParseELF(elf, root=root, ldpaths=ldpaths)
logging.debug('Parsed elf %s data: %s', elf, e)
interp = e['interp']
- # Do not create wrapper for libc. crbug.com/766827
- if interp and not glibc_re.search(elf):
- # Generate a wrapper if it is executable.
- interp = os.path.join('/lib', os.path.basename(interp))
- lddtree.GenerateLdsoWrapper(output_dir, path_rewrite_func(elf), interp,
- libpaths=e['rpath'] + e['runpath'])
- FixClangXXWrapper(output_dir, path_rewrite_func(elf))
-
- # Wrap any symlinks to the wrapper.
- if elf in sym_paths:
- link = sym_paths[elf]
- GeneratePathWrapper(output_dir, link, elf)
# TODO(crbug.com/917193): Drop this hack once libopcodes linkage is fixed.
if os.path.basename(elf).startswith('libopcodes-'):
continue
+ # Copy all the dependencies before we copy the program & generate wrappers.
for lib, lib_data in e['libs'].items():
src = path = lib_data['path']
if path is None:
@@ -1083,6 +1072,19 @@
logging.debug('Linking lib %s -> %s', root + src, dst)
os.link(root + src, dst)
+ # Do not create wrapper for libc. crbug.com/766827
+ if interp and not glibc_re.search(elf):
+ # Generate a wrapper if it is executable.
+ interp = os.path.join('/lib', os.path.basename(interp))
+ lddtree.GenerateLdsoWrapper(output_dir, path_rewrite_func(elf), interp,
+ libpaths=e['rpath'] + e['runpath'])
+ FixClangXXWrapper(output_dir, path_rewrite_func(elf))
+
+ # Wrap any symlinks to the wrapper.
+ if elf in sym_paths:
+ link = sym_paths[elf]
+ GeneratePathWrapper(output_dir, link, elf)
+
def _EnvdGetVar(envd, var):
"""Given a Gentoo env.d file, extract a var from it