/[gentoo-projects]/pax-utils/symtree.sh
Gentoo

Contents of /pax-utils/symtree.sh

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.4 - (show annotations) (download) (as text)
Sun Apr 7 20:57:17 2013 UTC (15 months, 3 weeks ago) by vapier
Branch: MAIN
CVS Tags: HEAD
Changes since 1.3: +6 -4 lines
File MIME type: text/x-sh
symtree: make it work with either lddtree implementation

1 #!/bin/bash
2
3 argv0=${0##*/}
4
5 usage() {
6 cat <<-EOF
7 Display libraries that satisfy undefined symbols, as a tree
8
9 Usage: ${argv0} [options] <ELF file[s]>
10
11 Options:
12 -x Run with debugging
13 -h Show this help output
14 EOF
15 exit ${1:-0}
16 }
17
18 sym_list() {
19 # with large strings, bash is much slower than sed
20 local type=$1; shift
21 echo "%${type}%$@" | sed "s:,:,%${type}%:g"
22 }
23 find_elf() {
24 echo "$2" | awk -F/ -v lib="$1" '$NF == lib {print}'
25 }
26 show_elf() {
27 local elf=$1
28 local rlib lib libs
29 local resolved=$(realpath "${elf}")
30 local resolved_libs=$(lddtree -l "${resolved}")
31
32 printf "%s\n" "${resolved}"
33
34 libs=$(scanelf -qF '#F%n' "${resolved}")
35
36 local u uu d dd
37 u=$(scanelf -q -F'%s#F' -s'%u%' "${elf}")
38 for lib in ${libs//,/ } ; do
39 lib=${lib##*/}
40 rlib=$(find_elf "${lib}" "${resolved_libs}")
41
42 d=$(scanelf -qF'%s#F' -s`sym_list d "${u}"` "${rlib}")
43 if [[ -n ${d} ]] ; then
44 dd=${dd:+${dd},}${d}
45 printf "%4s%s => %s\n" "" "${lib}" "${d}"
46 else
47 printf "%4s%s => %s\n" "" "${lib}" "!?! useless link !?!"
48 fi
49 done
50
51 uu=
52 for u in `echo "${u}" | sed 's:,: :g'` ; do
53 [[ ,${dd}, != *,${u},* ]] && uu=${uu:+${uu},}${u}
54 done
55 if [[ -n ${uu} ]] ; then
56 u=${uu}
57 dd=$(scanelf -qF'%s#F' -s`sym_list w "${u}"` "${resolved}")
58 if [[ -n ${dd} ]] ; then
59 printf "%4s%s => %s\n" "" "WEAK" "${dd}"
60 uu=
61 for u in `echo "${u}" | sed 's:,: :g'` ; do
62 [[ ,${dd}, != *,${u},* ]] && uu=${uu:+${uu},}${u}
63 done
64 fi
65 if [[ -n ${uu} ]] ; then
66 printf "%4s%s => %s\n" "" "UNRESOLVED" "${uu}"
67 fi
68 fi
69 }
70
71 SET_X=false
72
73 while getopts hx OPT ; do
74 case ${OPT} in
75 x) SET_X=true;;
76 h) usage;;
77 *) usage 1;;
78 esac
79 done
80 shift $((OPTIND - 1))
81 [[ -z $1 ]] && usage 1
82
83 ${SET_X} && set -x
84
85 ret=0
86 for elf in "$@" ; do
87 if [[ ! -e ${elf} ]] ; then
88 error "${elf}: file does not exist"
89 elif [[ ! -r ${elf} ]] ; then
90 error "${elf}: file is not readable"
91 elif [[ -d ${elf} ]] ; then
92 error "${elf}: is a directory"
93 else
94 [[ ${elf} != */* ]] && elf="./${elf}"
95 show_elf "${elf}" 0 ""
96 fi
97 done
98 exit ${ret}

  ViewVC Help
Powered by ViewVC 1.1.20