prom_init_check.sh 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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 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. for UNDEF in $($NM -u $OBJ | awk '{print $2}')
  26. do
  27. # On 64-bit nm gives us the function descriptors, which have
  28. # a leading . on the name, so strip it off here.
  29. UNDEF="${UNDEF#.}"
  30. if [ $KBUILD_VERBOSE ]; then
  31. if [ $KBUILD_VERBOSE -ne 0 ]; then
  32. echo "Checking prom_init.o symbol '$UNDEF'"
  33. fi
  34. fi
  35. OK=0
  36. for WHITE in $WHITELIST
  37. do
  38. if [ "$UNDEF" = "$WHITE" ]; then
  39. OK=1
  40. break
  41. fi
  42. done
  43. # ignore register save/restore funcitons
  44. if [ "${UNDEF:0:9}" = "_restgpr_" ]; then
  45. OK=1
  46. fi
  47. if [ "${UNDEF:0:10}" = "_restgpr0_" ]; then
  48. OK=1
  49. fi
  50. if [ "${UNDEF:0:11}" = "_rest32gpr_" ]; then
  51. OK=1
  52. fi
  53. if [ "${UNDEF:0:9}" = "_savegpr_" ]; then
  54. OK=1
  55. fi
  56. if [ "${UNDEF:0:10}" = "_savegpr0_" ]; then
  57. OK=1
  58. fi
  59. if [ "${UNDEF:0:11}" = "_save32gpr_" ]; then
  60. OK=1
  61. fi
  62. if [ $OK -eq 0 ]; then
  63. ERROR=1
  64. echo "Error: External symbol '$UNDEF' referenced" \
  65. "from prom_init.c" >&2
  66. fi
  67. done
  68. exit $ERROR