summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Deymo <deymo@chromium.org>2015-08-31 14:24:36 -0700
committerchrome-bot <chrome-bot@chromium.org>2015-09-02 11:26:46 -0700
commitab3b0483779d75fe74cf0a62c2dc3843d0eadf78 (patch)
tree1433646bf972a6899f5f8c907b3b494e68a295f6
parent40ab6512dae0cf3edf7d9d46de21e62ae885a85f (diff)
downloadchromite-ab3b0483779d75fe74cf0a62c2dc3843d0eadf78.tar.gz
lddtree: Move ELF files to its own subdir.
This patch adds a new --elf-subdir flag that makes the wrapper-script move the original ELF to the passed subdirectory instead of appending a .elf suffix. Appending .elf works in general, except for multicall binaries that use argv[0] to determine what program was called. BUG=chromium:526753 TEST=`./build_library/generate_au_zip.py` with the new flags places files in .elf/; Change-Id: Iee7c4b727e8de54919f396812d3e8b061f4091ad Reviewed-on: https://chromium-review.googlesource.com/296424 Commit-Ready: Alex Deymo <deymo@chromium.org> Tested-by: Alex Deymo <deymo@chromium.org> Reviewed-by: Alex Deymo <deymo@chromium.org>
-rw-r--r--third_party/lddtree.py29
1 files changed, 24 insertions, 5 deletions
diff --git a/third_party/lddtree.py b/third_party/lddtree.py
index 27924799f..9fffcbaa9 100644
--- a/third_party/lddtree.py
+++ b/third_party/lddtree.py
@@ -101,7 +101,7 @@ def dedupe(items):
return [seen.setdefault(x, x) for x in items if x not in seen]
-def GenerateLdsoWrapper(root, path, interp, libpaths=()):
+def GenerateLdsoWrapper(root, path, interp, libpaths=(), elfsubdir=None):
"""Generate a shell script wrapper which uses local ldso to run the ELF
Since we cannot rely on the host glibc (or other libraries), we need to
@@ -113,6 +113,9 @@ def GenerateLdsoWrapper(root, path, interp, libpaths=()):
path: The full path (inside |root|) to the program to wrap
interp: The ldso interpreter that we need to execute
libpaths: Extra lib paths to search for libraries
+ elfsubdir: The sub-directory where the original ELF file lives. If not
+ provided, a '.elf' suffix will be added to the original file
+ instead.
"""
basedir = os.path.dirname(path)
interp_dir, interp_name = os.path.split(interp)
@@ -123,6 +126,18 @@ def GenerateLdsoWrapper(root, path, interp, libpaths=()):
'libpaths': ':'.join(['${basedir}/' + os.path.relpath(p, basedir)
for p in libpaths]),
}
+
+ wrappath = root + path
+ if elfsubdir:
+ elf_wrap_dir = os.path.join(os.path.dirname(wrappath), elfsubdir)
+ makedirs(elf_wrap_dir)
+ elf_wrappath = os.path.join(elf_wrap_dir, os.path.basename(wrappath))
+ replacements['elf_path'] = '${basedir}/%s/%s' % (elfsubdir,
+ os.path.basename(wrappath))
+ else:
+ elf_wrappath = wrappath + '.elf'
+ replacements['elf_path'] = '${base}.elf'
+
wrapper = """#!/bin/sh
if ! base=$(realpath "$0" 2>/dev/null); then
case $0 in
@@ -135,11 +150,10 @@ exec \
"${basedir}/%(interp)s" \
--library-path "%(libpaths)s" \
--inhibit-rpath '' \
- "${base}.elf" \
+ "%(elf_path)s" \
"$@"
"""
- wrappath = root + path
- os.rename(wrappath, wrappath + '.elf')
+ os.rename(wrappath, elf_wrappath)
with open(wrappath, 'w') as f:
f.write(wrapper % replacements)
os.chmod(wrappath, 0o0755)
@@ -540,7 +554,8 @@ def _ActionCopy(options, elf):
interp = os.path.join(options.libdir, os.path.basename(elf['interp']))
else:
interp = _StripRoot(elf['interp'])
- GenerateLdsoWrapper(options.dest, subdst, interp, libpaths)
+ GenerateLdsoWrapper(options.dest, subdst, interp, libpaths,
+ options.elf_subdir)
# XXX: We should automatically import libgcc_s.so whenever libpthread.so
# is copied over (since we know it can be dlopen-ed by NPTL at runtime).
@@ -651,6 +666,10 @@ they need will be placed into /foo/lib/ only.""")
group.add_option('--generate-wrappers',
action='store_true', default=False,
help='Wrap executable ELFs with scripts for local ldso')
+ group.add_option('--elf-subdir',
+ default=None, type='string',
+ help='When wrapping executable ELFs, place the original file in this '
+ 'sub-directory. By default, it appends a .elf suffix instead.')
group.add_option('--copy-non-elfs',
action='store_true', default=False,
help='Copy over plain (non-ELF) files instead of warn+ignore')