relocs_check.sh 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. # On PPC:
  27. # R_PPC_RELATIVE, R_PPC_ADDR16_HI,
  28. # R_PPC_ADDR16_HA,R_PPC_ADDR16_LO,
  29. # R_PPC_NONE
  30. grep -F -w -v 'R_PPC64_RELATIVE
  31. R_PPC64_NONE
  32. R_PPC_ADDR16_LO
  33. R_PPC_ADDR16_HI
  34. R_PPC_ADDR16_HA
  35. R_PPC_RELATIVE
  36. R_PPC_NONE' |
  37. grep -E -v '\<R_PPC64_ADDR64[[:space:]]+mach_'
  38. )
  39. if [ -z "$bad_relocs" ]; then
  40. exit 0
  41. fi
  42. num_bad=$(echo "$bad_relocs" | wc -l)
  43. echo "WARNING: $num_bad bad relocations"
  44. echo "$bad_relocs"
  45. # If we see this type of relocation it's an idication that
  46. # we /may/ be using an old version of binutils.
  47. if echo "$bad_relocs" | grep -q -F -w R_PPC64_UADDR64; then
  48. echo "WARNING: You need at least binutils >= 2.19 to build a CONFIG_RELOCATABLE kernel"
  49. fi