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

Contents of /pax-utils/symtree.sh

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (hide annotations) (download) (as text)
Tue Dec 1 10:20:23 2009 UTC (8 years, 1 month ago) by vapier
Branch: MAIN
File MIME type: text/x-sh
first cut at displaying a tree of which libraries satisfy which undefined symbols

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

  ViewVC Help
Powered by ViewVC 1.1.20