Skip to content

Commit 4ea8065

Browse files
npigginmpe
authored andcommitted
powerpc/64s: Tool to flag direct branches from unrelocated interrupt vectors
Direct banches from code below __end_interrupts to code above __end_interrupts when built with CONFIG_RELOCATABLE are disallowed because they will break when the kernel is not located at 0. Sample output: WARNING: Unrelocated relative branches c000000000000118 bl-> 0xc000000000038fb8 <pnv_restore_hyp_resource> c00000000000013c b-> 0xc0000000001068a4 <kvm_start_guest> c000000000000148 b-> 0xc00000000003919c <pnv_wakeup_loss> c00000000000014c b-> 0xc00000000003923c <pnv_wakeup_noloss> c0000000000005a4 b-> 0xc000000000106ffc <kvmppc_interrupt_hv> c000000000001af0 b-> 0xc000000000106ffc <kvmppc_interrupt_hv> c000000000001b24 b-> 0xc000000000106ffc <kvmppc_interrupt_hv> c000000000001b58 b-> 0xc000000000106ffc <kvmppc_interrupt_hv> Signed-off-by: Balbir Singh <[email protected]> Signed-off-by: Nicholas Piggin <[email protected]> Signed-off-by: Michael Ellerman <[email protected]>
1 parent efe0160 commit 4ea8065

File tree

2 files changed

+65
-1
lines changed

2 files changed

+65
-1
lines changed

arch/powerpc/Makefile.postlink

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,14 @@ __archpost:
1111
include scripts/Kbuild.include
1212

1313
quiet_cmd_relocs_check = CHKREL $@
14-
cmd_relocs_check = $(CONFIG_SHELL) $(srctree)/arch/powerpc/tools/relocs_check.sh "$(OBJDUMP)" "$@"
14+
ifdef CONFIG_PPC_BOOK3S_64
15+
cmd_relocs_check = \
16+
$(CONFIG_SHELL) $(srctree)/arch/powerpc/tools/relocs_check.sh "$(OBJDUMP)" "$@" ; \
17+
$(CONFIG_SHELL) $(srctree)/arch/powerpc/tools/unrel_branch_check.sh "$(OBJDUMP)" "$@"
18+
else
19+
cmd_relocs_check = \
20+
$(CONFIG_SHELL) $(srctree)/arch/powerpc/tools/relocs_check.sh "$(OBJDUMP)" "$@"
21+
endif
1522

1623
# `@true` prevents complaint when there is nothing to be done
1724

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# Copyright © 2016 IBM Corporation
2+
#
3+
# This program is free software; you can redistribute it and/or
4+
# modify it under the terms of the GNU General Public License
5+
# as published by the Free Software Foundation; either version
6+
# 2 of the License, or (at your option) any later version.
7+
#
8+
# This script checks the relocations of a vmlinux for "suspicious"
9+
# branches from unrelocated code (head_64.S code).
10+
11+
# Turn this on if you want more debug output:
12+
# set -x
13+
14+
# Have Kbuild supply the path to objdump so we handle cross compilation.
15+
objdump="$1"
16+
vmlinux="$2"
17+
18+
#__end_interrupts should be located within the first 64K
19+
20+
end_intr=0x$(
21+
"$objdump" -R "$vmlinux" -d --start-address=0xc000000000000000 \
22+
--stop-address=0xc000000000010000 |
23+
grep '\<__end_interrupts>:' |
24+
awk '{print $1}'
25+
)
26+
27+
BRANCHES=$(
28+
"$objdump" -R "$vmlinux" -D --start-address=0xc000000000000000 \
29+
--stop-address=${end_intr} |
30+
grep -e "^c[0-9a-f]*:[[:space:]]*\([0-9a-f][0-9a-f][[:space:]]\)\{4\}[[:space:]]*b" |
31+
grep -v '\<__start_initialization_multiplatform>' |
32+
grep -v -e 'b.\?.\?ctr' |
33+
grep -v -e 'b.\?.\?lr' |
34+
sed 's/://' |
35+
awk '{ print $1 ":" $6 ":0x" $7 ":" $8 " "}'
36+
)
37+
38+
for tuple in $BRANCHES
39+
do
40+
from=`echo $tuple | cut -d':' -f1`
41+
branch=`echo $tuple | cut -d':' -f2`
42+
to=`echo $tuple | cut -d':' -f3 | sed 's/cr[0-7],//'`
43+
sym=`echo $tuple | cut -d':' -f4`
44+
45+
if (( $to > $end_intr ))
46+
then
47+
if [ -z "$bad_branches" ]; then
48+
echo "WARNING: Unrelocated relative branches"
49+
bad_branches="yes"
50+
fi
51+
echo "$from $branch-> $to $sym"
52+
fi
53+
done
54+
55+
if [ -z "$bad_branches" ]; then
56+
exit 0
57+
fi

0 commit comments

Comments
 (0)