- 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
This commit is contained in:
Bryan Drewery 2015-04-21 03:29:03 +00:00
parent 60b38ce2b5
commit 3554283a7b
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=281811

View File

@ -1,26 +1,6 @@
#!/bin/sh
# $FreeBSD$
ret=0
CHECK_UNRESOLVED=1
while getopts "U" flag; do
case "${flag}" in
U) CHECK_UNRESOLVED=0 ;;
esac
done
shift $((OPTIND-1))
mime=$(file -L --mime-type $1)
case $mime in
*application/x-executable);;
*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' ' ')
ldd_libs=$(ldd $(realpath $1) | awk '{print $1 ":" $3}')
libkey() {
libkey="lib_symbols_$1"
patterns=[.+,-]
@ -38,6 +18,27 @@ libkey() {
return 0
}
ret=0
CHECK_UNRESOLVED=1
while getopts "U" flag; do
case "${flag}" in
U) CHECK_UNRESOLVED=0 ;;
esac
done
shift $((OPTIND-1))
mime=$(file -L --mime-type $1)
isbin=0
case $mime in
*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 --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}')
# Check for useful libs
list_libs=
resolved_symbols=
@ -50,11 +51,11 @@ for lib in $(readelf -d $1 | awk '$2 ~ /\(?NEEDED\)?/ { sub(/\[/,"",$NF); sub(/\
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 ~ /\(?NEEDED\)?/ { sub(/\[/,"",$NF); sub(/\
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