#!/bin/sh # # Copyright © 2008 IBM Corporation # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version # 2 of the License, or (at your option) any later version. # This script checks prom_init.o to see what external symbols it # is using, if it finds symbols not in the whitelist it returns # an error. The point of this is to discourage people from # intentionally or accidentally adding new code to prom_init.c # which has side effects on other parts of the kernel. # If you really need to reference something from prom_init.o add # it to the list below: global WHITELIST := '"add_reloc_offset __bss_start __bss_stop copy_and_flush _end enter_prom memcpy memset reloc_offset __secondary_hold __secondary_hold_acknowledge __secondary_hold_spinloop __start strcmp strcpy strlcpy strlen strncmp strstr logo_linux_clut224 reloc_got2 kernstart_addr memstart_addr linux_banner _stext __prom_init_toc_start __prom_init_toc_end btext_setup_display TOC.'" global NM := $1 global OBJ := $2 global ERROR := '0' for UNDEF in [$[$NM -u $OBJ | awk '{print $2}]] { # On 64-bit nm gives us the function descriptors, which have # a leading . on the name, so strip it off here. global UNDEF := $(UNDEF#.) if test $KBUILD_VERBOSE { if test $KBUILD_VERBOSE -ne 0 { echo "Checking prom_init.o symbol '$UNDEF'" } } global OK := '0' for WHITE in [$WHITELIST] { if test $UNDEF = $WHITE { global OK := '1' break } } # ignore register save/restore funcitons matchstr $UNDEF { _restgpr_*|_restgpr0_*|_rest32gpr_* { global OK := '1' } _savegpr_*|_savegpr0_*|_save32gpr_* { global OK := '1' } } if test $OK -eq 0 { global ERROR := '1' echo "Error: External symbol '$UNDEF' referenced" \ "from prom_init.c" > !2 } } exit $ERROR (CommandList children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:WHITELIST) op: Equal rhs: { (DQ ("add_reloc_offset __bss_start __bss_stop copy_and_flush\n") ("_end enter_prom memcpy memset reloc_offset __secondary_hold\n") ("__secondary_hold_acknowledge __secondary_hold_spinloop __start\n") ("strcmp strcpy strlcpy strlen strncmp strstr logo_linux_clut224\n") ("reloc_got2 kernstart_addr memstart_addr linux_banner _stext\n") ("__prom_init_toc_start __prom_init_toc_end btext_setup_display TOC.") ) } spids: [48] ) ] spids: [48] ) (Assignment keyword: Assign_None pairs: [(assign_pair lhs:(LhsName name:NM) op:Equal rhs:{(DQ ($ VSub_Number "$1"))} spids:[59])] spids: [59] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:OBJ) op: Equal rhs: {(DQ ($ VSub_Number "$2"))} spids: [64] ) ] spids: [64] ) (Assignment keyword: Assign_None pairs: [(assign_pair lhs:(LhsName name:ERROR) op:Equal rhs:{(0)} spids:[70])] spids: [70] ) (ForEach iter_name: UNDEF iter_words: [ { (CommandSubPart command_list: (CommandList children: [ (Pipeline children: [ (C {($ VSub_Name "$NM")} {(-u)} {($ VSub_Name "$OBJ")}) (C {(awk)} {(SQ <"{print $2}">)}) ] negated: False ) ] ) left_token: spids: [80 94] ) } ] do_arg_iter: False body: (DoGroup children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:UNDEF) op: Equal rhs: { (DQ (BracedVarSub token: suffix_op: (StringUnary op_id:VOp1_Pound arg_word:{(.)}) spids: [109 113] ) ) } spids: [107] ) ] spids: [107] ) (If arms: [ (if_arm cond: [ (Sentence child: (C {(Lit_Other "[")} {($ VSub_Name "$KBUILD_VERBOSE")} {(Lit_Other "]")}) terminator: ) ] action: [ (If arms: [ (if_arm cond: [ (Sentence child: (C {(Lit_Other "[")} {($ VSub_Name "$KBUILD_VERBOSE")} {(-ne)} {(0)} {(Lit_Other "]")} ) terminator: ) ] action: [ (C {(echo)} {(DQ ("Checking prom_init.o symbol '") ($ VSub_Name "$UNDEF") ("'"))} ) ] spids: [-1 143] ) ] spids: [-1 155] ) ] spids: [-1 127] ) ] spids: [-1 158] ) (Assignment keyword: Assign_None pairs: [(assign_pair lhs:(LhsName name:OK) op:Equal rhs:{(0)} spids:[162])] spids: [162] ) (ForEach iter_name: WHITE iter_words: [{($ VSub_Name "$WHITELIST")}] do_arg_iter: False body: (DoGroup children: [ (If arms: [ (if_arm cond: [ (Sentence child: (C {(Lit_Other "[")} {(DQ ($ VSub_Name "$UNDEF"))} {(Lit_Other "=")} {(DQ ($ VSub_Name "$WHITE"))} {(Lit_Other "]")} ) terminator: ) ] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:OK) op: Equal rhs: {(1)} spids: [198] ) ] spids: [198] ) (ControlFlow token:) ] spids: [-1 195] ) ] spids: [-1 205] ) ] spids: [175 208] ) spids: [171 -1] ) (Case to_match: {($ VSub_Name "$UNDEF")} arms: [ (case_arm pat_list: [ {(_restgpr_) (Lit_Other "*")} {(_restgpr0_) (Lit_Other "*")} {(_rest32gpr_) (Lit_Other "*")} ] action: [ (Assignment keyword: Assign_None pairs: [(assign_pair lhs:(LhsName name:OK) op:Equal rhs:{(1)} spids:[234])] spids: [234] ) ] spids: [223 231 238 -1] ) (case_arm pat_list: [ {(_savegpr_) (Lit_Other "*")} {(_savegpr0_) (Lit_Other "*")} {(_save32gpr_) (Lit_Other "*")} ] action: [ (Assignment keyword: Assign_None pairs: [(assign_pair lhs:(LhsName name:OK) op:Equal rhs:{(1)} spids:[252])] spids: [252] ) ] spids: [241 249 256 -1] ) ] spids: [216 220 259] ) (If arms: [ (if_arm cond: [ (Sentence child: (C {(Lit_Other "[")} {($ VSub_Name "$OK")} {(-eq)} {(0)} {(Lit_Other "]")}) terminator: ) ] action: [ (Assignment keyword: Assign_None pairs: [(assign_pair lhs:(LhsName name:ERROR) op:Equal rhs:{(1)} spids:[279])] spids: [279] ) (SimpleCommand words: [ {(echo)} {(DQ ("Error: External symbol '") ($ VSub_Name "$UNDEF") ("' referenced"))} {(DQ ("from prom_init.c"))} ] redirects: [(Redir op_id:Redir_GreatAnd fd:-1 arg_word:{(2)} spids:[297])] ) ] spids: [-1 276] ) ] spids: [-1 301] ) ] spids: [96 303] ) spids: [79 -1] ) (C {(exit)} {($ VSub_Name "$ERROR")}) ] )