relocs_check.sh 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #!/bin/sh
  2. # SPDX-License-Identifier: GPL-2.0-or-later
  3. # Copyright © 2015 IBM Corporation
  4. # This script checks the relocations of a vmlinux for "suspicious"
  5. # relocations.
  6. # based on relocs_check.pl
  7. # Copyright © 2009 IBM Corporation
  8. if [ $# -lt 3 ]; then
  9. echo "$0 [path to objdump] [path to nm] [path to vmlinux]" 1>&2
  10. exit 1
  11. fi
  12. # Have Kbuild supply the path to objdump and nm so we handle cross compilation.
  13. objdump="$1"
  14. nm="$2"
  15. vmlinux="$3"
  16. # Remove from the bad relocations those that match an undefined weak symbol
  17. # which will result in an absolute relocation to 0.
  18. # Weak unresolved symbols are of that form in nm output:
  19. # " w _binary__btf_vmlinux_bin_end"
  20. undef_weak_symbols=$($nm "$vmlinux" | awk '$1 ~ /w/ { print $2 }')
  21. bad_relocs=$(
  22. $objdump -R "$vmlinux" |
  23. # Only look at relocation lines.
  24. grep -E '\<R_' |
  25. # These relocations are okay
  26. # On PPC64:
  27. # R_PPC64_RELATIVE, R_PPC64_NONE
  28. # On PPC:
  29. # R_PPC_RELATIVE, R_PPC_ADDR16_HI,
  30. # R_PPC_ADDR16_HA,R_PPC_ADDR16_LO,
  31. # R_PPC_NONE
  32. grep -F -w -v 'R_PPC64_RELATIVE
  33. R_PPC64_NONE
  34. R_PPC64_UADDR64
  35. R_PPC_ADDR16_LO
  36. R_PPC_ADDR16_HI
  37. R_PPC_ADDR16_HA
  38. R_PPC_RELATIVE
  39. R_PPC_NONE' |
  40. ([ "$undef_weak_symbols" ] && grep -F -w -v "$undef_weak_symbols" || cat)
  41. )
  42. if [ -z "$bad_relocs" ]; then
  43. exit 0
  44. fi
  45. num_bad=$(echo "$bad_relocs" | wc -l)
  46. echo "WARNING: $num_bad bad relocations"
  47. echo "$bad_relocs"