2 # SPDX-License-Identifier: GPL-2.0+
3 # Copyright © 2016,2020 IBM Corporation
5 # This script checks the unrelocated code of a vmlinux for "suspicious"
6 # branches to relocated code (head_64.S code).
8 # Have Kbuild supply the path to objdump and nm so we handle cross compilation.
13 kstart
=0xc000000000000000
15 end_intr
=0x$
($nm -p "$vmlinux" |
16 sed -E -n '/\s+[[:alpha:]]\s+__end_interrupts\s*$/{s///p;q}')
17 if [ "$end_intr" = "0x" ]; then
21 # we know that there is a correct branch to
22 # __start_initialization_multiplatform, so find its address
23 # so we can exclude it.
24 sim
=0x$
($nm -p "$vmlinux" |
25 sed -E -n '/\s+[[:alpha:]]\s+__start_initialization_multiplatform\s*$/{s///p;q}')
27 $objdump -D --no-show-raw-insn --start-address="$kstart" --stop-address="$end_intr" "$vmlinux" |
29 # match lines that start with a kernel address
31 # drop branches via ctr or lr
33 # cope with some differences between Clang and GNU objdumps
34 s/\<bt.?\s*[[:digit:]]+,/beq/
35 s/\<bf.?\s*[[:digit:]]+,/bne/
39 # format for the loop below
40 s/^(\S+)\s+(\S+)\s+(\S+)\s*(\S*).*$/\1:\2:\3:\4/
41 # strip out condition registers
47 while IFS
=: read -r from branch to sym
; do
53 if [ "$branch" = 'b' ]; then
54 if (( to
>= 0x2000000 )); then
55 to
=$
(( to
- 0x4000000 ))
57 elif (( to
>= 0x8000 )); then
58 to
=$
(( to
- 0x10000 ))
60 printf -v to
'0x%x' $
(( "0x$from" + to
))
62 *) printf 'Unkown branch format\n'
65 if [ "$to" = "$sim" ]; then
68 if (( to
> end_intr
)); then
70 printf '%s\n' 'WARNING: Unrelocated relative branches'
73 printf '%s %s-> %s %s\n' "$from" "$branch" "$to" "$sym"