Back to home page

OSCL-LXR

 
 

    


0001 #!/bin/sh
0002 # SPDX-License-Identifier: GPL-2.0-or-later
0003 #
0004 # Copyright © 2008 IBM Corporation
0005 #
0006 
0007 # This script checks prom_init.o to see what external symbols it
0008 # is using, if it finds symbols not in the whitelist it returns
0009 # an error. The point of this is to discourage people from
0010 # intentionally or accidentally adding new code to prom_init.c
0011 # which has side effects on other parts of the kernel.
0012 
0013 # If you really need to reference something from prom_init.o add
0014 # it to the list below:
0015 
0016 grep "^CONFIG_KASAN=y$" ${KCONFIG_CONFIG} >/dev/null
0017 if [ $? -eq 0 ]
0018 then
0019         MEM_FUNCS="__memcpy __memset"
0020 else
0021         MEM_FUNCS="memcpy memset"
0022 fi
0023 
0024 WHITELIST="add_reloc_offset __bss_start __bss_stop copy_and_flush
0025 _end enter_prom $MEM_FUNCS reloc_offset __secondary_hold
0026 __secondary_hold_acknowledge __secondary_hold_spinloop __start
0027 logo_linux_clut224 btext_prepare_BAT
0028 reloc_got2 kernstart_addr memstart_addr linux_banner _stext
0029 __prom_init_toc_start __prom_init_toc_end btext_setup_display TOC.
0030 relocate"
0031 
0032 NM="$1"
0033 OBJ="$2"
0034 
0035 ERROR=0
0036 
0037 check_section()
0038 {
0039     file=$1
0040     section=$2
0041     size=$(objdump -h -j $section $file 2>/dev/null | awk "\$2 == \"$section\" {print \$3}")
0042     size=${size:-0}
0043     if [ $size -ne 0 ]; then
0044         ERROR=1
0045         echo "Error: Section $section not empty in prom_init.c" >&2
0046     fi
0047 }
0048 
0049 for UNDEF in $($NM -u $OBJ | awk '{print $2}')
0050 do
0051         # On 64-bit nm gives us the function descriptors, which have
0052         # a leading . on the name, so strip it off here.
0053         UNDEF="${UNDEF#.}"
0054 
0055         if [ $KBUILD_VERBOSE ]; then
0056                 if [ $KBUILD_VERBOSE -ne 0 ]; then
0057                         echo "Checking prom_init.o symbol '$UNDEF'"
0058                 fi
0059         fi
0060 
0061         OK=0
0062         for WHITE in $WHITELIST
0063         do
0064                 if [ "$UNDEF" = "$WHITE" ]; then
0065                         OK=1
0066                         break
0067                 fi
0068         done
0069 
0070         # ignore register save/restore funcitons
0071         case $UNDEF in
0072         _restgpr_*|_restgpr0_*|_rest32gpr_*)
0073                 OK=1
0074                 ;;
0075         _savegpr_*|_savegpr0_*|_save32gpr_*)
0076                 OK=1
0077                 ;;
0078         esac
0079 
0080         if [ $OK -eq 0 ]; then
0081                 ERROR=1
0082                 echo "Error: External symbol '$UNDEF' referenced" \
0083                      "from prom_init.c" >&2
0084         fi
0085 done
0086 
0087 check_section $OBJ .data
0088 check_section $OBJ .bss
0089 check_section $OBJ .init.data
0090 
0091 exit $ERROR