nm-diff.sh

application/x-sh

Filename: nm-diff.sh
Type: application/x-sh
Part: 0
Message: Re: Large C files
#!/bin/sh
# nm-diff.sh
# This script is intended to reveal errors silently introduced by the removal of apparently superfluous 
# header files, particularly by automated tools like pgrminclude.
#
# Rather imperfectly, it works by examing the symbol table of both object files, and diffing them. This
# can be expected to pick up some bugs that might otherwise go unnoticed, due to the code still compiling
# despite the absence of the header intended to be included, unpredictably altering the behaviour of the
# program. However, since a header file can radically alter the semantics of any .c file it is
# included in, this is far from guaranteed.

# It assumes that the nm utility from Gnu Binutils is in $PATH
# Tested on Linux x86_64/ELF

: ${1?"Usage: $0 : ${1?"Usage: $0 "new_object_file.o old_object_file.o}";exit 1}
FIRST_FILE="/tmp/`echo $1`.symbol_table"
SECOND_FILE="/tmp/`echo $2`.symbol_table"
nm $1 > `echo $FIRST_FILE`
nm $2 > `echo $SECOND_FILE`
DIFF_TABLE="/tmp/`echo $1`_`echo $2`.tab_diff"
echo "Symbol table differences: "
diff $FIRST_FILE $SECOND_FILE > `echo $DIFF_TABLE`
if [[ ! -s $DIFF_TABLE ]] ; then
	echo "Symbol tables match, so your changes may not have introduced bugs"
	exit 0
else
	cat $DIFF_TABLE
	echo "WARNING: Symbol tables don't match!"
	exit 1
fi