Skip to content

Instantly share code, notes, and snippets.

@sthen
Created April 13, 2020 09:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sthen/8b26176989e181dc5f3bc47834affdce to your computer and use it in GitHub Desktop.
Save sthen/8b26176989e181dc5f3bc47834affdce to your computer and use it in GitHub Desktop.
#!/bin/ksh
# diffsyms='for i in `make print-plist | perl -n -e "print if s/\@lib //" | sed s,^,/usr/local/, `; do check_sym.ports $i; done'
get_lib_name()
{
sed -n 's/^[ ]*LIB[ ]*=[ ]*\([^ ]*\).*/\1/p' "$@"
}
pick_highest()
{
old=
omaj=-1
omin=0
for i
do
[[ -f $i ]] || continue
maj=${i%.*}; maj=${maj##*.}
min=${i##*.}
if [[ $maj -gt $omaj || ( $maj -eq $omaj && $min -gt $omin ) ]]
then
old=$i
omaj=$maj
omin=$min
fi
done
[[ $old != "" ]]
}
if [[ $1 = ?(*/)lib*.so* ]]
then
old=$1
lib=${old##*/}
lib=${lib%%.so.*}
if [[ ! -f $old ]]
then
old=$(ls -rt ${old%lib*.so.*}${lib}.so.* | tail -1)
fi
if [[ ! -f $old ]]
then
echo "$old doesn't exist" >&2
exit 1
fi
else
echo "usage: $0 libfilename.so.xx" >&2
exit 1
fi
readelf -sW $old > /tmp/s1
readelf -rW $old > /tmp/r1
# Dig info out of the just built library
newver=$(make show=LIB${lib#lib}_VERSION)
obj=$(make show=WRKINST)$(make show=PREFIX)/lib
new=${obj}/${lib}.so.${newver}
echo $1 | grep eopenssl11/ > /dev/null && new=`echo $new|sed s,lib/,lib/eopenssl11/,g`
echo $1 | grep eopenssl/ > /dev/null && new=`echo $new|sed s,lib/,lib/eopenssl/,g`
readelf -sW $new > /tmp/s2
readelf -rW $new > /tmp/r2
jump_slots() {
awk '/JU*MP_SL/{print $5}' /tmp/r$1 | sort -o /tmp/j$1
}
dynamic_sym() {
# truncate the output files, to guarantee the exist
>/tmp/U$1 >/tmp/DS$1 >/tmp/DW$1 >/tmp/D$1
awk -v s=$1 '/^Symbol table ..symtab/{exit}
! /^ *[1-9]/ {next}
$7 == "UND" {print $8 | ("sort -o /tmp/U" s); next }
$5 == "GLOBAL" {print $8 | ("sort -o /tmp/DS" s) }
$5 == "WEAK" {print $8 | ("sort -o /tmp/DW" s) }
$4 != "SECTION"{print $8 | ("sort -o /tmp/D" s) }
{print $4, $5, $6, $8}' /tmp/s$1 | sort -o /tmp/d$1
# awk -v s=$1 '$2 == "GLOBAL" {print $4 | ("sort -o /tmp/DS" s) }
# $2 == "WEAK" {print $4 | ("sort -o /tmp/DW" s) }
# $1 != "SECTION"{print $4}' /tmp/d$1 | sort -o /tmp/D$1
}
static_sym() {
awk '/^Symbol table ..symtab/{s=1}
/LOCAL/{next}
s&&/^ *[1-9]/{print $4, $5, $6, $8}' /tmp/s$1 | sort -o /tmp/S$1
}
output_if_not_empty() {
leader=$1
shift
if "$@" | grep -q .
then
echo "$leader"
"$@" | sed 's:^: :'
echo
fi
}
for i in 1 2
do
jump_slots $i
dynamic_sym $i
static_sym $i
comm -23 /tmp/j$i /tmp/U$i >/tmp/J$i
done
echo "$old --> $new"
if cmp -s /tmp/d[12]
then
printf "No dynamic export changes\n"
else
printf "Dynamic export changes:\n"
output_if_not_empty "added:" comm -13 /tmp/D[12]
output_if_not_empty "removed:" comm -23 /tmp/D[12]
output_if_not_empty "weakened:" comm -12 /tmp/DS1 /tmp/DW2
output_if_not_empty "strengthened:" comm -12 /tmp/DW1 /tmp/DS2
fi
if ! cmp -s /tmp/U[12]
then
printf "External reference changes:\n"
output_if_not_empty "added:" comm -13 /tmp/U[12]
output_if_not_empty "removed:" comm -23 /tmp/U[12]
fi
if false; then
printf "\nReloc counts:\nbefore:\n"
grep ^R /tmp/r1
printf "\nafter:\n"
grep ^R /tmp/r2
fi
output_if_not_empty "PLT added:" comm -13 /tmp/J1 /tmp/J2
output_if_not_empty "PLT removed:" comm -23 /tmp/J1 /tmp/J2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment