#!/bin/sh
#
# determine the size change of symbols from two ELF files
#
# write symbol sizes to a file sorted by name
if [ -e nam1 -o -e nam2 -o -e nams ]  ; then
	echo delete nam1/nam2/nams before using this script
	exit 1
fi
readelf -W -s $1 | awk '//{printf("%s %i\n",$8,$3)}' | sort > nam1
readelf -W -s $2 | awk '//{printf("%s %i\n",$8,$3)}' | sort > nam2
#powerpc-rtems-nm --size-sort -td $1 | awk '//{printf("%s %i\n",$3,$1)}' | sort > nam1
#powerpc-rtems-nm --size-sort -td $2 | awk '//{printf("%s %i\n",$3,$1)}' | sort > nam2
# find symbols only present in the old file
join -v 1 nam1 nam2 | awk '//{printf("%s O %i 0\n",$1,$2)}' > nams
# find symbols present in both files 
join      nam1 nam2 | awk '//{printf("%s C %i %i\n",$1,$2,$3)}' >> nams
# find symbols only present in the new file
join -v 2 nam1 nam2 | awk '//{printf("%s N 0 %i\n",$1,$2)}' >> nams
# statistics
awk 'BEGIN{suma=sumb=sumd=0}//{di=$4-$3; if ( di != 0 ) printf("%s %s %i\n",$1,$2,di); suma+=$3; sumb+=$4; sumd+=di}END{print "Sums:"," - ", suma, sumb, sumd}' nams | sort -n -k3
