[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

script to find libs for undefined non-weak in libs



Steve,
    Here is the set of three scripts I have been using (all
three scripts should be placed inside of /usr/local/bin). The
findsymbols script is a slightly modified script I obtained
from Marco d'Itri. I use these scripts as follows. After
prelinking my machine, I review messages from prelink looking for
warnings like...

prelink: Warning: /usr/lib/libcupsimage.so.2 has undefined non-weak
symbols

...which tells me that /usr/lib/libcupsimage.so.2 likely is missing
some linkage. To figure out what symbols are undefined non-weak
and which putative libraries could be providing them I run...

findliblist /usr/lib/libcupsimage.so.2

The findliblist script calls the symbollist script passing the
library name for which we are looking for undefined non-weak symbols.
In symbollist, for each undefined symbol in that library, we
call the script findsymbols passing that symbol as an argument.
The findsymbols script looks in the designated paths for all
libraries where this symbol is defined (i.e. non-weak). These
library names are passed back to the original script where they
are sorted and uniqued. Again the resulting list has to be
sensibly analyzed as often multiple shared libs will define the
same symbol names. However that step is pretty straight-forward.
Let me know if I am unclear here or these scripts don't work for
you. For example, in current debian sid if you run...

findliblist /usr/lib/libcupsimage.so.2

you will get back...

Finding putative libraries that provide
the undefined weak symbols in... /usr/lib/libcupsimage.so.2
Please be patient...
/usr/lib/libcups.so.2

which is correct since the undefined symbol, cupsTempFd, returned
by 'ldd -r /usr/lib/libcupsimage.so.2' is clearly present as a 
non-weak symbol in /usr/lib/libcups.so.2...

 nm -D --defined-only /usr/lib/libcups.so.2 | grep cupsTempFd
0fba4eb8 T cupsTempFd

                                  Jack
#!/bin/sh -e
echo "Finding putative libraries that provide"
echo "the undefined weak symbols in..." $1
echo "Please be patient..."
/usr/local/bin/symbollist $1 2>&1 | sort -u
#!/bin/sh -e
 
LIBDIRS="/lib /usr/lib /usr/X11R6/lib"
 
FILES=$(find $LIBDIRS -maxdepth 1 -type f -name '*.so*' | sort \
        | xargs grep --files-with-matches $1)
 
for file in $FILES; do
        if nm --dynamic --defined-only "$file" | grep -q " [^U] ${1}$"; then
                echo $file | tail -n 1
        fi
done
 
exit 0
 
A absolute
B BSS (uninitialized data section)
C common (uninitialized data)
D initialized data section
G initialized data section for small objects
N debugging symbol
R read only data section
S uninitialized data section for small objects
T text (code)
U undefined
V weak object
W weak symbol that has not been specifically tagged as a weak object symbol

#!/bin/sh -e
for sym in $(ldd -r $1 2>&1 | awk '/undefined/ {print $3}')
do
   /usr/local/bin/findsymbols $sym 
done

Reply to: