Skip to content

Commit 6b1992b

Browse files
sfrothwellmpe
authored andcommitted
powerpc: unrel_branch_check.sh: enable the use of llvm-objdump v9, 10 or 11
Currently, using llvm-objtool, this script just silently succeeds without actually do the intended checking. So this updates it to work properly. Firstly, llvm-objdump does not add target symbol names to the end of branches in its asm output, so we have to drop the branch to __start_initialization_multiplatform using its address. Secondly, v9 and 10 specify branch targets as .+<offset>, so we convert those to actual addresses. Thirdly, v10 and 11 error out on a vmlinux if given the -R option complaining that it is "not a dynamic object". The -R does not make any difference to the asm output, so remove it. Lastly, v11 produces asm that is very similar to Gnu objtool (at least as far as branches are concerned), so no further changes are necessary to make it work. Signed-off-by: Stephen Rothwell <sfr@canb.auug.org.au> Signed-off-by: Michael Ellerman <mpe@ellerman.id.au> Link: https://lore.kernel.org/r/20200812081036.7969-3-sfr@canb.auug.org.au
1 parent b71dca9 commit 6b1992b

1 file changed

Lines changed: 29 additions & 5 deletions

File tree

‎arch/powerpc/tools/unrel_branch_check.sh‎

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,16 @@ if [ "$end_intr" = "0x" ]; then
1818
exit 0
1919
fi
2020

21-
$objdump -R -D --no-show-raw-insn --start-address="$kstart" --stop-address="$end_intr" "$vmlinux" |
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}')
26+
27+
$objdump -D --no-show-raw-insn --start-address="$kstart" --stop-address="$end_intr" "$vmlinux" |
2228
sed -E -n '
2329
# match lines that start with a kernel address
2430
/^c[0-9a-f]*:\s*b/ {
25-
# drop a target that we do not care about
26-
/\<__start_initialization_multiplatform>/d
2731
# drop branches via ctr or lr
2832
/\<b.?.?(ct|l)r/d
2933
# cope with some differences between Clang and GNU objdumps
@@ -33,14 +37,34 @@ sed -E -n '
3337
s/\s0x/ /
3438
s/://
3539
# format for the loop below
36-
s/^(\S+)\s+(\S+)\s+(\S+)\s*(\S*).*$/\1:\2:0x\3:\4/
40+
s/^(\S+)\s+(\S+)\s+(\S+)\s*(\S*).*$/\1:\2:\3:\4/
3741
# strip out condition registers
38-
s/:0xcr[0-7],/:0x/
42+
s/:cr[0-7],/:/
3943
p
4044
}' | {
4145

4246
all_good=true
4347
while IFS=: read -r from branch to sym; do
48+
case "$to" in
49+
c*) to="0x$to"
50+
;;
51+
.+*)
52+
to=${to#.+}
53+
if [ "$branch" = 'b' ]; then
54+
if (( to >= 0x2000000 )); then
55+
to=$(( to - 0x4000000 ))
56+
fi
57+
elif (( to >= 0x8000 )); then
58+
to=$(( to - 0x10000 ))
59+
fi
60+
printf -v to '0x%x' $(( "0x$from" + to ))
61+
;;
62+
*) printf 'Unkown branch format\n'
63+
;;
64+
esac
65+
if [ "$to" = "$sim" ]; then
66+
continue
67+
fi
4468
if (( to > end_intr )); then
4569
if $all_good; then
4670
printf '%s\n' 'WARNING: Unrelocated relative branches'

0 commit comments

Comments
 (0)