head_check.sh 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. # Copyright © 2016 IBM Corporation
  2. # This program is free software; you can redistribute it and/or
  3. # modify it under the terms of the GNU General Public License
  4. # as published by the Free Software Foundation; either version
  5. # 2 of the License, or (at your option) any later version.
  6. # This script checks the head of a vmlinux for linker stubs that
  7. # break our placement of fixed-location code for 64-bit.
  8. # based on relocs_check.pl
  9. # Copyright © 2009 IBM Corporation
  10. # NOTE!
  11. #
  12. # If the build dies here, it's likely code in head_64.S/exception-64*.S or
  13. # nearby, is branching to labels it can't reach directly, which results in the
  14. # linker inserting branch stubs. This can move code around in ways that break
  15. # the fixed section calculations (head-64.h). To debug this, disassemble the
  16. # vmlinux and look for branch stubs (long_branch, plt_branch, etc.) in the
  17. # fixed section region (0 - 0x8000ish). Check what code is calling those stubs,
  18. # and perhaps change so a direct branch can reach.
  19. #
  20. # A ".linker_stub_catch" section is used to catch some stubs generated by
  21. # early .text code, which tend to get placed at the start of the section.
  22. # If there are too many such stubs, they can overflow this section. Expanding
  23. # it may help (or reducing the number of stub branches).
  24. #
  25. # Linker stubs use the TOC pointer, so even if fixed section code could
  26. # tolerate them being inserted into head code, they can't be allowed in low
  27. # level entry code (boot, interrupt vectors, etc) until r2 is set up. This
  28. # could cause the kernel to die in early boot.
  29. # Allow for verbose output
  30. if [ "$V" = "1" ]; then
  31. set -x
  32. fi
  33. if [ $# -lt 2 ]; then
  34. echo "$0 [path to nm] [path to vmlinux]" 1>&2
  35. exit 1
  36. fi
  37. # Have Kbuild supply the path to nm so we handle cross compilation.
  38. nm="$1"
  39. vmlinux="$2"
  40. # gcc-4.6-era toolchain make _stext an A (absolute) symbol rather than T
  41. $nm "$vmlinux" | grep -e " [TA] _stext$" -e " t start_first_256B$" -e " a text_start$" -e " t start_text$" > .tmp_symbols.txt
  42. vma=$(grep -e " [TA] _stext$" .tmp_symbols.txt | cut -d' ' -f1)
  43. expected_start_head_addr="$vma"
  44. start_head_addr=$(grep " t start_first_256B$" .tmp_symbols.txt | cut -d' ' -f1)
  45. if [ "$start_head_addr" != "$expected_start_head_addr" ]; then
  46. echo "ERROR: head code starts at $start_head_addr, should be $expected_start_head_addr" 1>&2
  47. echo "ERROR: try to enable LD_HEAD_STUB_CATCH config option" 1>&2
  48. echo "ERROR: see comments in arch/powerpc/tools/head_check.sh" 1>&2
  49. exit 1
  50. fi
  51. top_vma=$(echo "$vma" | cut -d'0' -f1)
  52. expected_start_text_addr=$(grep " a text_start$" .tmp_symbols.txt | cut -d' ' -f1 | sed "s/^0/$top_vma/")
  53. start_text_addr=$(grep " t start_text$" .tmp_symbols.txt | cut -d' ' -f1)
  54. if [ "$start_text_addr" != "$expected_start_text_addr" ]; then
  55. echo "ERROR: start_text address is $start_text_addr, should be $expected_start_text_addr" 1>&2
  56. echo "ERROR: try to enable LD_HEAD_STUB_CATCH config option" 1>&2
  57. echo "ERROR: see comments in arch/powerpc/tools/head_check.sh" 1>&2
  58. exit 1
  59. fi
  60. rm -f .tmp_symbols.txt