From owner-svn-src-all@freebsd.org Tue Jan 19 22:42:17 2016 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 9FF0DA8744B; Tue, 19 Jan 2016 22:42:17 +0000 (UTC) (envelope-from bdrewery@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 4E32C1E80; Tue, 19 Jan 2016 22:42:17 +0000 (UTC) (envelope-from bdrewery@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id u0JMgGjY065420; Tue, 19 Jan 2016 22:42:16 GMT (envelope-from bdrewery@FreeBSD.org) Received: (from bdrewery@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u0JMgGGX065419; Tue, 19 Jan 2016 22:42:16 GMT (envelope-from bdrewery@FreeBSD.org) Message-Id: <201601192242.u0JMgGGX065419@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: bdrewery set sender to bdrewery@FreeBSD.org using -f From: Bryan Drewery Date: Tue, 19 Jan 2016 22:42:16 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r294357 - head/tools/build X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 19 Jan 2016 22:42:17 -0000 Author: bdrewery Date: Tue Jan 19 22:42:16 2016 New Revision: 294357 URL: https://svnweb.freebsd.org/changeset/base/294357 Log: 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 Modified: head/tools/build/check-links.sh Modified: head/tools/build/check-links.sh ============================================================================== --- head/tools/build/check-links.sh Tue Jan 19 22:42:13 2016 (r294356) +++ head/tools/build/check-links.sh Tue Jan 19 22:42:16 2016 (r294357) @@ -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=