blob: b183ab9c5107c9236930b3d3d9e1f2c7dd27b302 [file] [log] [blame]
Michael Ellerman5c02cd22008-04-24 12:08:22 +10001#!/bin/sh
Thomas Gleixner2874c5f2019-05-27 08:55:01 +02002# SPDX-License-Identifier: GPL-2.0-or-later
Michael Ellerman5c02cd22008-04-24 12:08:22 +10003#
4# Copyright © 2008 IBM Corporation
5#
Michael Ellerman5c02cd22008-04-24 12:08:22 +10006
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
Christophe Leroy26deb042019-04-26 16:23:26 +000016grep "^CONFIG_KASAN=y$" .config >/dev/null
17if [ $? -eq 0 ]
18then
19 MEM_FUNCS="__memcpy __memset"
20else
21 MEM_FUNCS="memcpy memset"
22fi
23
Michael Ellerman5c02cd22008-04-24 12:08:22 +100024WHITELIST="add_reloc_offset __bss_start __bss_stop copy_and_flush
Christophe Leroy26deb042019-04-26 16:23:26 +000025_end enter_prom $MEM_FUNCS reloc_offset __secondary_hold
Michael Ellerman5c02cd22008-04-24 12:08:22 +100026__secondary_hold_acknowledge __secondary_hold_spinloop __start
Christophe Leroyc21f5a92019-06-03 13:00:51 +000027logo_linux_clut224 btext_prepare_BAT
Benjamin Herrenschmidt27f44882011-09-19 18:27:58 +000028reloc_got2 kernstart_addr memstart_addr linux_banner _stext
Thiago Jung Bauermann05d9a952019-09-11 13:34:33 -030029__prom_init_toc_start __prom_init_toc_end btext_setup_display TOC.
30relocate"
Michael Ellerman5c02cd22008-04-24 12:08:22 +100031
32NM="$1"
33OBJ="$2"
34
35ERROR=0
36
Masahiro Yamada858805b2019-08-25 22:28:37 +090037check_section()
Benjamin Herrenschmidt2c51d972018-10-15 13:49:59 +110038{
39 file=$1
40 section=$2
41 size=$(objdump -h -j $section $file 2>/dev/null | awk "\$2 == \"$section\" {print \$3}")
42 size=${size:-0}
43 if [ $size -ne 0 ]; then
44 ERROR=1
45 echo "Error: Section $section not empty in prom_init.c" >&2
46 fi
47}
48
Michael Ellerman5c02cd22008-04-24 12:08:22 +100049for UNDEF in $($NM -u $OBJ | awk '{print $2}')
50do
51 # On 64-bit nm gives us the function descriptors, which have
52 # a leading . on the name, so strip it off here.
53 UNDEF="${UNDEF#.}"
54
55 if [ $KBUILD_VERBOSE ]; then
56 if [ $KBUILD_VERBOSE -ne 0 ]; then
57 echo "Checking prom_init.o symbol '$UNDEF'"
58 fi
59 fi
60
61 OK=0
62 for WHITE in $WHITELIST
63 do
64 if [ "$UNDEF" = "$WHITE" ]; then
65 OK=1
66 break
67 fi
68 done
69
Kumar Galada3de6d2008-06-13 07:20:58 +100070 # ignore register save/restore funcitons
Andreas Schwabfe921c82014-09-13 10:20:17 +020071 case $UNDEF in
72 _restgpr_*|_restgpr0_*|_rest32gpr_*)
Kumar Galada3de6d2008-06-13 07:20:58 +100073 OK=1
Andreas Schwabfe921c82014-09-13 10:20:17 +020074 ;;
75 _savegpr_*|_savegpr0_*|_save32gpr_*)
Stephen Rothwell5afd8782010-06-29 20:04:22 +000076 OK=1
Andreas Schwabfe921c82014-09-13 10:20:17 +020077 ;;
78 esac
Kumar Galada3de6d2008-06-13 07:20:58 +100079
Michael Ellerman5c02cd22008-04-24 12:08:22 +100080 if [ $OK -eq 0 ]; then
81 ERROR=1
82 echo "Error: External symbol '$UNDEF' referenced" \
83 "from prom_init.c" >&2
84 fi
85done
86
Benjamin Herrenschmidt2c51d972018-10-15 13:49:59 +110087check_section $OBJ .data
88check_section $OBJ .bss
89check_section $OBJ .init.data
90
Michael Ellerman5c02cd22008-04-24 12:08:22 +100091exit $ERROR