mkdiff_obj 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #!/bin/sh
  2. usage() {
  3. echo "Usage: ${0##*/} DIR1 DIR2"
  4. echo
  5. echo "Compares all object files recursivelty found in DIR1 and DIR2."
  6. echo "Prints diff of their disassembly."
  7. echo
  8. exit $1
  9. }
  10. filter() {
  11. # sed removes " address: " prefixes which mess up diff
  12. sed $'s/^\\(\t*\\)[ ]*[0-9a-f][0-9a-f]*:[ \t]*/\\1/' \
  13. | sed 's/__GI_//g'
  14. }
  15. test -d "$1" || usage 1
  16. test -d "$2" || usage 1
  17. {
  18. (
  19. cd "$1" || exit 1
  20. find -name '*.o' # -o -name '*.os' # -o -name '*.so'
  21. )
  22. (
  23. cd "$2" || exit 1
  24. find -name '*.o' # -o -name '*.os' # -o -name '*.so'
  25. )
  26. } | sed 's:^\./::' | sort | uniq | \
  27. (
  28. while IFS='' read -r oname; do
  29. if ! test -f "$1/$oname"; then
  30. echo "Only $2/$oname"
  31. continue
  32. fi
  33. if ! test -f "$2/$oname"; then
  34. echo "Only $1/$oname"
  35. continue
  36. fi
  37. diff -q -- "$1/$oname" "$2/$oname" >/dev/null && continue
  38. (cd "$1" && { size "$oname"; objdump -dr "$oname" | filter; } >"$oname.disasm")
  39. (cd "$2" && { size "$oname"; objdump -dr "$oname" | filter; } >"$oname.disasm")
  40. diff -u -- "$1/$oname.disasm" "$2/$oname.disasm"
  41. done
  42. )