relocs_check.sh 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #!/bin/sh
  2. # Copyright © 2015 IBM Corporation
  3. # This program is free software; you can redistribute it and/or
  4. # modify it under the terms of the GNU General Public License
  5. # as published by the Free Software Foundation; either version
  6. # 2 of the License, or (at your option) any later version.
  7. # This script checks the relocations of a vmlinux for "suspicious"
  8. # relocations.
  9. # based on relocs_check.pl
  10. # Copyright © 2009 IBM Corporation
  11. if [ $# -lt 2 ]; then
  12. echo "$0 [path to objdump] [path to vmlinux]" 1>&2
  13. exit 1
  14. fi
  15. # Have Kbuild supply the path to objdump so we handle cross compilation.
  16. objdump="$1"
  17. vmlinux="$2"
  18. bad_relocs=$(
  19. "$objdump" -R "$vmlinux" |
  20. # Only look at relocation lines.
  21. grep -E '\<R_' |
  22. # These relocations are okay
  23. # On PPC64:
  24. # R_PPC64_RELATIVE, R_PPC64_NONE
  25. # R_PPC64_ADDR64 mach_<name>
  26. # R_PPC64_ADDR64 __crc_<name>
  27. # On PPC:
  28. # R_PPC_RELATIVE, R_PPC_ADDR16_HI,
  29. # R_PPC_ADDR16_HA,R_PPC_ADDR16_LO,
  30. # R_PPC_NONE
  31. grep -F -w -v 'R_PPC64_RELATIVE
  32. R_PPC64_NONE
  33. R_PPC_ADDR16_LO
  34. R_PPC_ADDR16_HI
  35. R_PPC_ADDR16_HA
  36. R_PPC_RELATIVE
  37. R_PPC_NONE' |
  38. grep -E -v '\<R_PPC64_ADDR64[[:space:]]+mach_' |
  39. grep -E -v '\<R_PPC64_ADDR64[[:space:]]+__crc_'
  40. )
  41. if [ -z "$bad_relocs" ]; then
  42. exit 0
  43. fi
  44. num_bad=$(echo "$bad_relocs" | wc -l)
  45. echo "WARNING: $num_bad bad relocations"
  46. echo "$bad_relocs"
  47. # If we see this type of relocation it's an idication that
  48. # we /may/ be using an old version of binutils.
  49. if echo "$bad_relocs" | grep -q -F -w R_PPC64_UADDR64; then
  50. echo "WARNING: You need at least binutils >= 2.19 to build a CONFIG_RELOCATABLE kernel"
  51. fi