summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorbdrewery <bdrewery@FreeBSD.org>2016-01-19 22:42:16 +0000
committerbdrewery <bdrewery@FreeBSD.org>2016-01-19 22:42:16 +0000
commit3bda4bd41de2eb4d2c9880b4b393ca4261d0d7e5 (patch)
tree135e8cfd1d5a95525f4cf89641cd1c328e41eb91 /tools
parente7715d79c632b98e3509010271599ff6c1c786de (diff)
downloadFreeBSD-src-3bda4bd41de2eb4d2c9880b4b393ca4261d0d7e5.zip
FreeBSD-src-3bda4bd41de2eb4d2c9880b4b393ca4261d0d7e5.tar.gz
Allow specifying an alternative LD_LIBRARY_PATH for the ldd(1) lookup.
This is needed to be able to run check-links.sh against a "sysrooted" binary while ensuring that the ldd(1) call done on the host uses the host libc. It is not possible to set LD_LIBRARY_PATH before calling check-links.sh as then the "sysrooted" libc would be incorrectly used. A LD_PRELOAD=libc.so is used to ldd(1) as it needs to use the host libc to run. ldd(1) is a simple wrapper around execve(2) and dlopen(2) with env LD_TRACE_LOADED_OBJECTS set. Due to the dlopen(2) restriction on shared library tracing ldd(1) is still required for this lookup. Sponsored by: EMC / Isilon Storage Division
Diffstat (limited to 'tools')
-rwxr-xr-xtools/build/check-links.sh15
1 files changed, 12 insertions, 3 deletions
diff --git a/tools/build/check-links.sh b/tools/build/check-links.sh
index 937f61c..06aa8d3 100755
--- a/tools/build/check-links.sh
+++ b/tools/build/check-links.sh
@@ -20,7 +20,8 @@ libkey() {
usage() {
cat <<-EOF
- usage: $0 [-Uv] file
+ usage: $0 [-Uv] [-L LD_LIBRARY_PATH] file
+ -L: Specify an alternative LD_LIBRARY_PATH for the library resolution.
-U: Skip looking for unresolved symbols.
-v: Show which library each symbol is resolved to.
EOF
@@ -30,8 +31,9 @@ usage() {
ret=0
CHECK_UNRESOLVED=1
VERBOSE_RESOLVED=0
-while getopts "Uv" flag; do
+while getopts "L:Uv" flag; do
case "${flag}" in
+ L) LIB_PATH="${OPTARG}" ;;
U) CHECK_UNRESOLVED=0 ;;
v) VERBOSE_RESOLVED=1 ;;
*) usage ;;
@@ -55,7 +57,14 @@ esac
# Gather all symbols from the target
unresolved_symbols=$(nm -u -D --format=posix "$1" | awk '$2 == "U" {print $1}' | tr '\n' ' ')
[ ${isbin} -eq 1 ] && bss_symbols=$(nm -D --format=posix "$1" | awk '$2 == "B" && $4 != "" {print $1}' | tr '\n' ' ')
-ldd_libs=$(ldd $(realpath $1) | awk '{print $1 ":" $3}')
+if [ -n "${LIB_PATH}" ]; then
+ for libc in /lib/libc.so.*; do
+ LDD_ENV="LD_PRELOAD=${libc}"
+ done
+ LDD_ENV="${LDD_ENV} LD_LIBRARY_PATH=${LIB_PATH}"
+fi
+
+ldd_libs=$(env ${LDD_ENV} ldd $(realpath $1) | awk '{print $1 ":" $3}')
# Check for useful libs
list_libs=
OpenPOWER on IntegriCloud