prom_init_check.sh 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. #!/bin/sh
  2. #
  3. # Copyright © 2008 IBM Corporation
  4. #
  5. # This program is free software; you can redistribute it and/or
  6. # modify it under the terms of the GNU General Public License
  7. # as published by the Free Software Foundation; either version
  8. # 2 of the License, or (at your option) any later version.
  9. # This script checks prom_init.o to see what external symbols it
  10. # is using, if it finds symbols not in the whitelist it returns
  11. # an error. The point of this is to discourage people from
  12. # intentionally or accidentally adding new code to prom_init.c
  13. # which has side effects on other parts of the kernel.
  14. # If you really need to reference something from prom_init.o add
  15. # it to the list below:
  16. WHITELIST="add_reloc_offset __bss_start __bss_stop copy_and_flush
  17. _end enter_prom memcpy memset reloc_offset __secondary_hold
  18. __secondary_hold_acknowledge __secondary_hold_spinloop __start
  19. strcmp strcpy strlcpy strlen strncmp strstr kstrtobool logo_linux_clut224
  20. reloc_got2 kernstart_addr memstart_addr linux_banner _stext
  21. __prom_init_toc_start __prom_init_toc_end btext_setup_display TOC."
  22. NM="$1"
  23. OBJ="$2"
  24. ERROR=0
  25. function check_section()
  26. {
  27. file=$1
  28. section=$2
  29. size=$(objdump -h -j $section $file 2>/dev/null | awk "\$2 == \"$section\" {print \$3}")
  30. size=${size:-0}
  31. if [ $size -ne 0 ]; then
  32. ERROR=1
  33. echo "Error: Section $section not empty in prom_init.c" >&2
  34. fi
  35. }
  36. for UNDEF in $($NM -u $OBJ | awk '{print $2}')
  37. do
  38. # On 64-bit nm gives us the function descriptors, which have
  39. # a leading . on the name, so strip it off here.
  40. UNDEF="${UNDEF#.}"
  41. if [ $KBUILD_VERBOSE ]; then
  42. if [ $KBUILD_VERBOSE -ne 0 ]; then
  43. echo "Checking prom_init.o symbol '$UNDEF'"
  44. fi
  45. fi
  46. OK=0
  47. for WHITE in $WHITELIST
  48. do
  49. if [ "$UNDEF" = "$WHITE" ]; then
  50. OK=1
  51. break
  52. fi
  53. done
  54. # ignore register save/restore funcitons
  55. case $UNDEF in
  56. _restgpr_*|_restgpr0_*|_rest32gpr_*)
  57. OK=1
  58. ;;
  59. _savegpr_*|_savegpr0_*|_save32gpr_*)
  60. OK=1
  61. ;;
  62. esac
  63. if [ $OK -eq 0 ]; then
  64. ERROR=1
  65. echo "Error: External symbol '$UNDEF' referenced" \
  66. "from prom_init.c" >&2
  67. fi
  68. done
  69. check_section $OBJ .data
  70. check_section $OBJ .bss
  71. check_section $OBJ .init.data
  72. exit $ERROR