unrel_branch_check.sh 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. # Copyright © 2016 IBM Corporation
  2. #
  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. #
  8. # This script checks the relocations of a vmlinux for "suspicious"
  9. # branches from unrelocated code (head_64.S code).
  10. # Turn this on if you want more debug output:
  11. # set -x
  12. # Have Kbuild supply the path to objdump so we handle cross compilation.
  13. objdump="$1"
  14. vmlinux="$2"
  15. #__end_interrupts should be located within the first 64K
  16. end_intr=0x$(
  17. $objdump -R "$vmlinux" -d --start-address=0xc000000000000000 \
  18. --stop-address=0xc000000000010000 |
  19. grep '\<__end_interrupts>:' |
  20. awk '{print $1}'
  21. )
  22. BRANCHES=$(
  23. $objdump -R "$vmlinux" -D --start-address=0xc000000000000000 \
  24. --stop-address=${end_intr} |
  25. grep -e "^c[0-9a-f]*:[[:space:]]*\([0-9a-f][0-9a-f][[:space:]]\)\{4\}[[:space:]]*b" |
  26. grep -v '\<__start_initialization_multiplatform>' |
  27. grep -v -e 'b.\?.\?ctr' |
  28. grep -v -e 'b.\?.\?lr' |
  29. sed 's/://' |
  30. awk '{ print $1 ":" $6 ":0x" $7 ":" $8 " "}'
  31. )
  32. for tuple in $BRANCHES
  33. do
  34. from=`echo $tuple | cut -d':' -f1`
  35. branch=`echo $tuple | cut -d':' -f2`
  36. to=`echo $tuple | cut -d':' -f3 | sed 's/cr[0-7],//'`
  37. sym=`echo $tuple | cut -d':' -f4`
  38. if (( $to > $end_intr ))
  39. then
  40. if [ -z "$bad_branches" ]; then
  41. echo "WARNING: Unrelocated relative branches"
  42. bad_branches="yes"
  43. fi
  44. echo "$from $branch-> $to $sym"
  45. fi
  46. done
  47. if [ -z "$bad_branches" ]; then
  48. exit 0
  49. fi