Gentoo Archives: gentoo-commits

From: "Mike Frysinger (vapier)" <vapier@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] gentoo-projects commit in pax-utils: symtree.sh
Date: Tue, 01 Dec 2009 10:20:25
Message-Id: E1NFPqJ-0000M3-Ne@stork.gentoo.org
1 vapier 09/12/01 10:20:23
2
3 Added: symtree.sh
4 Log:
5 first cut at displaying a tree of which libraries satisfy which undefined symbols
6
7 Revision Changes Path
8 1.1 pax-utils/symtree.sh
9
10 file : http://sources.gentoo.org/viewcvs.py/gentoo-projects/pax-utils/symtree.sh?rev=1.1&view=markup
11 plain: http://sources.gentoo.org/viewcvs.py/gentoo-projects/pax-utils/symtree.sh?rev=1.1&content-type=text/plain
12
13 Index: symtree.sh
14 ===================================================================
15 #!/bin/bash
16
17 source lddtree /../..source.lddtree || exit 1
18
19 argv0=${0##*/}
20
21 usage() {
22 cat <<-EOF
23 Display libraries that satisfy undefined symbols, as a tree
24
25 Usage: ${argv0} [options] <ELF file[s]>
26
27 Options:
28 -x Run with debugging
29 -h Show this help output
30 EOF
31 exit ${1:-0}
32 }
33
34 sym_list() {
35 # with large strings, bash is much slower than sed
36 local type=$1; shift
37 echo "%%~"`echo ",$@" | sed "s:,:,%${type}%:g"`
38 }
39 show_elf() {
40 local elf=$1
41 local rlib lib libs
42 local resolved=$(find_elf "${elf}")
43
44 printf "%s\n" "${resolved}"
45
46 libs=$(scanelf -qF '#F%n' "${resolved}")
47
48 local u uu d dd
49 u=$(scanelf -q -F'#s#F' -s'%u%' "${elf}")
50 for lib in ${libs//,/ } ; do
51 lib=${lib##*/}
52 rlib=$(find_elf "${lib}" "${resolved}")
53
54 d=$(scanelf -qF'%s#F' -s`sym_list d "${u}"` "${rlib}")
55 if [[ -n ${d} ]] ; then
56 dd=${dd:+${dd},}${d}
57 printf "%4s%s => %s\n" "" "${lib}" "${d}"
58 else
59 printf "%4s%s => %s\n" "" "${lib}" "!?! useless link !?!"
60 fi
61 done
62
63 uu=
64 for u in `echo "${u}" | sed 's:,: :g'` ; do
65 [[ ,${dd}, != *,${u},* ]] && uu=${uu:+${uu},}${u}
66 done
67 if [[ -n ${uu} ]] ; then
68 u=${uu}
69 dd=$(scanelf -qF'%s#F' -s`sym_list w "${u}"` "${resolved}")
70 if [[ -n ${dd} ]] ; then
71 printf "%4s%s => %s\n" "" "WEAK" "${dd}"
72 uu=
73 for u in `echo "${u}" | sed 's:,: :g'` ; do
74 [[ ,${dd}, != *,${u},* ]] && uu=${uu:+${uu},}${u}
75 done
76 fi
77 if [[ -n ${uu} ]] ; then
78 printf "%4s%s => %s\n" "" "UNRESOLVED" "${uu}"
79 fi
80 fi
81 }
82
83 SET_X=false
84
85 ([[ $1 == "" ]] || [[ $1 == --help ]]) && usage 1
86 opts="hx"
87 getopt -Q -- "${opts}" "$@" || exit 1
88 eval set -- $(getopt -- "${opts}" "$@")
89 while [[ -n $1 ]] ; do
90 case $1 in
91 -x) SET_X=true;;
92 -h) usage;;
93 --) shift; break;;
94 -*) usage 1;;
95 esac
96 shift
97 done
98
99 ${SET_X} && set -x
100
101 ret=0
102 for elf in "$@" ; do
103 if [[ ! -e ${elf} ]] ; then
104 error "${elf}: file does not exist"
105 elif [[ ! -r ${elf} ]] ; then
106 error "${elf}: file is not readable"
107 elif [[ -d ${elf} ]] ; then
108 error "${elf}: is a directory"
109 else
110 [[ ${elf} != */* ]] && elf="./${elf}"
111 show_elf "${elf}" 0 ""
112 fi
113 done
114 exit ${ret}