prom_init_check.sh 2.0 KB

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