Cross-Referencer for Linux Executables

It's a short bash script, that uses the objdump utility. I've only tried it on executables derived from C/C++ code.

# From an executable, create a cross-reference of which functions reference each function or statically
# allocated variable.  Only parameter is name of executable.

create_sort_list ()
{
CALLER='???'
while read LINE
do
  if [[ "$LINE" = *: ]] ; then
    CALLER="$( echo "$LINE" | sed 's/:$//' )"
  else
    printf "${LINE}+${CALLER}\n"
  fi
done
}

create_output_list ()
{
LAST='???'
while read CALLED
do
  read CALLER
  if [[ $CALLED != $LAST ]] ; then
    printf "\n"
    printf "$CALLED referenced by:\n"
    LAST="$CALLED"
  fi
  printf " $CALLER\n"
done
}

objdump --disassemble --demangle $1 | fgrep '<' | fgrep -v '+' | \
sed 's/^[^<]*<//' | sed 's/>[^:>]*$//' | sed 's/>[^:>]*:$/:/' | \
create_sort_list | sort -u | tr '+' '\n' | create_output_list

There seems to be some sort of bug in the Linkedin article editor, but you can also see/copy this script from here: https://gist.github.com/wkaras/29ee4c397e0545b0eee4baa3eaa9a532 .

the script appears truncated at the sed line, which is a shame as it seemed to be building into something very useful.  Could be the platform I am reading from, or may actually have been truncated when you uploaded. Please upload the rest.

Like
Reply

To view or add a comment, sign in

More articles by Walter Karas

Explore content categories