mirror of
https://git.hardenedbsd.org/hardenedbsd/HardenedBSD.git
synced 2024-11-15 23:05:49 +01:00
Add a quick and dirty script to check validity of links in elf files
This commit is contained in:
parent
1f194d8ae1
commit
6276797fcd
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=274199
37
tools/build/check-links.sh
Executable file
37
tools/build/check-links.sh
Executable file
@ -0,0 +1,37 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
# $FreeBSD$
|
||||||
|
|
||||||
|
mime=$(file --mime-type $1)
|
||||||
|
case $mime in
|
||||||
|
*application/x-executable);;
|
||||||
|
*application/x-sharedlib);;
|
||||||
|
*) echo "Not an elf file" >&2 ; exit 1;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
# Check for useful libs
|
||||||
|
list_libs=""
|
||||||
|
for lib in $(readelf -d $1 | awk '$2 == "(NEEDED)" { sub(/\[/,"",$NF); sub(/\]/,"",$NF); print $NF }'); do
|
||||||
|
echo -n "checking if $lib is needed: "
|
||||||
|
libpath=$(ldd $1 | awk -v lib=$lib '$1 == lib { print $3 }')
|
||||||
|
list_libs="$list_libs $libpath"
|
||||||
|
foundone=0
|
||||||
|
for fct in $(nm -D $libpath | awk '$2 == "T" || $2 == "W" || $2 == "B" { print $3 }'); do
|
||||||
|
nm -D $1 | awk -v s=$fct '$1 == "U" && $2 == s { found=1 ; exit } END { if (found != 1) { exit 1 } }' && foundone=1 && break
|
||||||
|
done
|
||||||
|
if [ $foundone -eq 1 ]; then
|
||||||
|
echo "yes"
|
||||||
|
else
|
||||||
|
echo "no"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
for sym in $(nm -D $1 | awk '$1 == "U" { print $2 }'); do
|
||||||
|
found=0
|
||||||
|
for l in ${list_libs} ; do
|
||||||
|
nm -D $l | awk -v s=$sym '($2 == "T" || $2 == "W" || $2 == "B") && $3 == s { found=1 ; exit } END { if (found != 1) { exit 1 } }' && found=1 && break
|
||||||
|
done
|
||||||
|
if [ $found -eq 0 ]; then
|
||||||
|
echo "Unresolved symbol $sym"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
Loading…
Reference in New Issue
Block a user