From owner-svn-src-all@FreeBSD.ORG Tue Apr 21 03:29:04 2015 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id A89259AC; Tue, 21 Apr 2015 03:29:04 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::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 9653B227; Tue, 21 Apr 2015 03:29:04 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.9/8.14.9) with ESMTP id t3L3T4Vc046245; Tue, 21 Apr 2015 03:29:04 GMT (envelope-from bdrewery@FreeBSD.org) Received: (from bdrewery@localhost) by svn.freebsd.org (8.14.9/8.14.9/Submit) id t3L3T49n046244; Tue, 21 Apr 2015 03:29:04 GMT (envelope-from bdrewery@FreeBSD.org) Message-Id: <201504210329.t3L3T49n046244@svn.freebsd.org> X-Authentication-Warning: svn.freebsd.org: bdrewery set sender to bdrewery@FreeBSD.org using -f From: Bryan Drewery Date: Tue, 21 Apr 2015 03:29:04 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r281811 - 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, 21 Apr 2015 03:29:04 -0000 Author: bdrewery Date: Tue Apr 21 03:29:03 2015 New Revision: 281811 URL: https://svnweb.freebsd.org/changeset/base/281811 Log: - For executables search for matching (B) global uninitialized BSS symbols from linked libraries. Only do this for BSS symbols that have a size which avoids __bss_start. Without this some libraries would be considered unneeded even though they were providing a B symbol. - Add in the symbols from crt1.o to cover a handful of common unresolved symbols. - Consider (C) common data symbols as provided by libraries/crt1. - Move libkey() function to more appropriate place. 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 Apr 21 03:06:58 2015 (r281810) +++ head/tools/build/check-links.sh Tue Apr 21 03:29:03 2015 (r281811) @@ -1,6 +1,23 @@ #!/bin/sh # $FreeBSD$ +libkey() { + libkey="lib_symbols_$1" + patterns=[.+,-] + replacement=_ + while :; do + case " ${libkey} " in + *${patterns}*) + libkey="${libkey%%${patterns}*}${replacement}${libkey#*${patterns}}" + ;; + *) + break + ;; + esac + done + return 0 +} + ret=0 CHECK_UNRESOLVED=1 while getopts "U" flag; do @@ -11,33 +28,17 @@ done shift $((OPTIND-1)) mime=$(file -L --mime-type $1) +isbin=0 case $mime in -*application/x-executable);; +*application/x-executable) isbin=1 ;; *application/x-sharedlib);; *) echo "Not an elf file" >&2 ; exit 1;; esac # Gather all symbols from the target -unresolved_symbols=$(nm -D -u --format=posix "$1" | awk '$2 == "U" {print $1}' | tr '\n' ' ') +unresolved_symbols=$(nm -D --format=posix "$1" | awk -v isbin=${isbin} '$2 == "U" || ($2 == "B" && $4 != "" && isbin == 1) {print $1}' | tr '\n' ' ') ldd_libs=$(ldd $(realpath $1) | awk '{print $1 ":" $3}') -libkey() { - libkey="lib_symbols_$1" - patterns=[.+,-] - replacement=_ - while :; do - case " ${libkey} " in - *${patterns}*) - libkey="${libkey%%${patterns}*}${replacement}${libkey#*${patterns}}" - ;; - *) - break - ;; - esac - done - return 0 -} - # Check for useful libs list_libs= resolved_symbols= @@ -50,11 +51,11 @@ for lib in $(readelf -d $1 | awk '$2 ~ / done list_libs="$list_libs $lib" foundone= - lib_symbols="$(nm -D --defined-only --format=posix "${libpath}" | awk '$2 ~ /R|D|T|W|B|V/ {print $1}' | tr '\n' ' ')" + lib_symbols="$(nm -D --defined-only --format=posix "${libpath}" | awk '$2 ~ /C|R|D|T|W|B|V/ {print $1}' | tr '\n' ' ')" if [ ${CHECK_UNRESOLVED} -eq 1 ]; then # Save the global symbols for this lib libkey "${lib}" - setvar "${libkey}" "${lib_symbols}" + setvar "${libkey}" "${lib_symbols}" fi for fct in ${lib_symbols}; do case " ${unresolved_symbols} " in @@ -70,6 +71,14 @@ for lib in $(readelf -d $1 | awk '$2 ~ / done if [ ${CHECK_UNRESOLVED} -eq 1 ]; then + # Add in crt1 symbols + list_libs="${list_libs} crt1.o" + lib_symbols="$(nm --defined-only --format=posix "/usr/lib/crt1.o" | awk '$2 ~ /C|R|D|T|W|B|V/ {print $1}' | tr '\n' ' ')" + # Save the global symbols for this lib + libkey "crt1.o" + setvar "${libkey}" "${lib_symbols}" + + # No search libs for all symbols and report missing ones. for sym in ${unresolved_symbols}; do found=0 for lib in ${list_libs}; do