aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorge Burgess IV <gbiv@google.com>2020-09-22 08:09:47 -0700
committerMike Frysinger <vapier@gentoo.org>2023-12-22 00:31:31 -0500
commitaadadb863a89af460726163703278b14750591ae (patch)
tree100c0a58df516245a1d97d8314600030d8111dbf
parentlddtree: use readlink -f for absolute links (diff)
downloadpax-utils-aadadb863a89af460726163703278b14750591ae.tar.gz
pax-utils-aadadb863a89af460726163703278b14750591ae.tar.bz2
pax-utils-aadadb863a89af460726163703278b14750591ae.zip
lddtree: add LD_ARGV0_REL
Some binaries use `/proc/self/exe` to get a link to the currently-executing binary. Unfortunately, when `ld.so` is invoked directly, `/proc/self/exe` alawys points to `ld.so`. `LD_ARGV0` can only be used to determine the current executable in programs which haven't changed their working directory from their starting one, so that's difficult to generally use. To solve this, this embeds the path of the current binary _relative to ld.so_ in an env var. Bug: https://crbug.com/1003841 Bug: https://issuetracker.google.com/187793259 Signed-off-by: George Burgess <gbiv@chromium.org> Signed-off-by: Mike Frysinger <vapier@chromium.org> Signed-off-by: Mike Frysinger <vapier@gentoo.org>
-rwxr-xr-xlddtree.py6
1 files changed, 6 insertions, 0 deletions
diff --git a/lddtree.py b/lddtree.py
index 8184e8f..b26afcf 100755
--- a/lddtree.py
+++ b/lddtree.py
@@ -176,6 +176,7 @@ def GenerateLdsoWrapper(
replacements = {
"interp": os.path.join(os.path.relpath(interp_dir, basedir), interp_name),
+ "interp_rel": os.path.relpath(path, interp_dir),
"libpaths": ":".join(
"${basedir}/" + os.path.relpath(p, basedir) for p in libpaths
),
@@ -186,6 +187,10 @@ def GenerateLdsoWrapper(
# Keep path relativeness of argv0 (in ${base}.elf). This allows tools to
# remove absolute paths from build outputs and enables directory independent
# cache sharing in distributed build systems.
+ #
+ # NB: LD_ARGV0_REL below is unrelated & non-standard. It's to let tools see
+ # the original path if they need it and when they know they'll be wrapped up
+ # by this script.
wrapper = """#!/bin/sh
if base=$(readlink "$0" 2>/dev/null); then
# If $0 is an abspath symlink, fully resolve the target.
@@ -200,6 +205,7 @@ else
esac
fi
basedir=${base%%/*}
+LD_ARGV0_REL="%(interp_rel)s" \\
exec \\
"${basedir}/%(interp)s" \\
%(argv0_arg)s \\