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