[PATCH 0/7] powerpc: unrel_branch_check.sh: make it suck less

STALE2164d

9 messages, 2 authors, 2020-09-09 · open the first message on its own page

[PATCH 0/7] powerpc: unrel_branch_check.sh: make it suck less

From: Stephen Rothwell <hidden>
Date: 2020-08-11 14:11:25

Michael Ellerman: "who wants to make
arch/powerpc/tools/unrel_branch_check.sh suck less"

This series is based off the current powerpc/next branch and keeps the
same functionaity as the original except that it suppresses some error
messages for early failures that still cause this script to succeed
(as it always did).

I did this as a series so that people can see the (mostly obvious)
transofrmations at each step.   As a single patch, it basically replaces
the whole file.

Hopefully this fulfills your definition of "sucks less" :-)

 arch/powerpc/tools/unrel_branch_check.sh | 88 ++++++++++++++++----------------
 1 file changed, 43 insertions(+), 45 deletions(-)

Cc: Nicholas Piggin <npiggin@gmail.com>
-- 
Cheers,
Stephen Rothwell

[PATCH 1/7] powerpc: unrel_branch_check.sh: fix shellcheck complaints

From: Stephen Rothwell <hidden>
Date: 2020-08-11 14:15:24

No functional change

Cc: Nicholas Piggin <npiggin@gmail.com>
Signed-off-by: Stephen Rothwell <redacted>
---
 arch/powerpc/tools/unrel_branch_check.sh | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/arch/powerpc/tools/unrel_branch_check.sh b/arch/powerpc/tools/unrel_branch_check.sh
index 6e6a30aea3ed..4c1e04ba5081 100755
--- a/arch/powerpc/tools/unrel_branch_check.sh
+++ b/arch/powerpc/tools/unrel_branch_check.sh
@@ -1,3 +1,4 @@
+#!/bin/bash
 # Copyright © 2016 IBM Corporation
 #
 # This program is free software; you can redistribute it and/or
@@ -26,7 +27,7 @@ awk '{print $1}'
 
 BRANCHES=$(
 $objdump -R "$vmlinux" -D --start-address=0xc000000000000000           \
-		--stop-address=${end_intr} |
+		--stop-address="$end_intr" |
 grep -e "^c[0-9a-f]*:[[:space:]]*\([0-9a-f][0-9a-f][[:space:]]\)\{4\}[[:space:]]*b" |
 grep -v '\<__start_initialization_multiplatform>' |
 grep -v -e 'b.\?.\?ctr' |
@@ -40,12 +41,12 @@ awk '{ print $1 ":" $6 ":0x" $7 ":" $8 " "}'
 
 for tuple in $BRANCHES
 do
-	from=`echo $tuple | cut -d':' -f1`
-	branch=`echo $tuple | cut -d':' -f2`
-	to=`echo $tuple | cut -d':' -f3 | sed 's/cr[0-7],//'`
-	sym=`echo $tuple | cut -d':' -f4`
+	from=$(echo "$tuple" | cut -d':' -f1)
+	branch=$(echo "$tuple" | cut -d':' -f2)
+	to=$(echo "$tuple" | cut -d':' -f3 | sed 's/cr[0-7],//')
+	sym=$(echo "$tuple" | cut -d':' -f4)
 
-	if (( $to > $end_intr ))
+	if (( to > end_intr ))
 	then
 		if [ -z "$bad_branches" ]; then
 			echo "WARNING: Unrelocated relative branches"
-- 
2.28.0

[PATCH 2/7] powerpc: unrel_branch_check.sh: simplify and combine some executions

From: Stephen Rothwell <hidden>
Date: 2020-08-11 14:18:43

Also some minor style changes.

There should still be no change in behaviour.

Cc: Nicholas Piggin <npiggin@gmail.com>
Signed-off-by: Stephen Rothwell <redacted>
---
 arch/powerpc/tools/unrel_branch_check.sh | 25 +++++++++++-------------
 1 file changed, 11 insertions(+), 14 deletions(-)
diff --git a/arch/powerpc/tools/unrel_branch_check.sh b/arch/powerpc/tools/unrel_branch_check.sh
index 4c1e04ba5081..d735e3875b5e 100755
--- a/arch/powerpc/tools/unrel_branch_check.sh
+++ b/arch/powerpc/tools/unrel_branch_check.sh
@@ -17,37 +17,34 @@ objdump="$1"
 vmlinux="$2"
 
 #__end_interrupts should be located within the first 64K
+kstart=0xc000000000000000
+printf -v kend '0x%x' $(( kstart + 0x10000 ))
 
 end_intr=0x$(
-$objdump -R "$vmlinux" -d --start-address=0xc000000000000000           \
-		 --stop-address=0xc000000000010000 |
-grep '\<__end_interrupts>:' |
-awk '{print $1}'
+$objdump -R -d --start-address="$kstart" --stop-address="$kend" "$vmlinux" |
+awk '$2 == "<__end_interrupts>:" { print $1 }'
 )
 
 BRANCHES=$(
-$objdump -R "$vmlinux" -D --start-address=0xc000000000000000           \
-		--stop-address="$end_intr" |
+$objdump -R -D --start-address="$kstart" --stop-address="$end_intr" "$vmlinux" |
 grep -e "^c[0-9a-f]*:[[:space:]]*\([0-9a-f][0-9a-f][[:space:]]\)\{4\}[[:space:]]*b" |
-grep -v '\<__start_initialization_multiplatform>' |
-grep -v -e 'b.\?.\?ctr' |
-grep -v -e 'b.\?.\?lr' |
-sed -e 's/\bbt.\?[[:space:]]*[[:digit:]][[:digit:]]*,/beq/' \
+sed -e '/\<__start_initialization_multiplatform>/d' \
+	-e '/b.\?.\?ctr/d' \
+	-e '/b.\?.\?lr/d' \
+	-e 's/\bbt.\?[[:space:]]*[[:digit:]][[:digit:]]*,/beq/' \
 	-e 's/\bbf.\?[[:space:]]*[[:digit:]][[:digit:]]*,/bne/' \
 	-e 's/[[:space:]]0x/ /' \
 	-e 's/://' |
 awk '{ print $1 ":" $6 ":0x" $7 ":" $8 " "}'
 )
 
-for tuple in $BRANCHES
-do
+for tuple in $BRANCHES; do
 	from=$(echo "$tuple" | cut -d':' -f1)
 	branch=$(echo "$tuple" | cut -d':' -f2)
 	to=$(echo "$tuple" | cut -d':' -f3 | sed 's/cr[0-7],//')
 	sym=$(echo "$tuple" | cut -d':' -f4)
 
-	if (( to > end_intr ))
-	then
+	if (( to > end_intr )); then
 		if [ -z "$bad_branches" ]; then
 			echo "WARNING: Unrelocated relative branches"
 			bad_branches="yes"
-- 
2.28.0

[PATCH 3/7] powerpc: unrel_branch_check.sh: simplify objdump's asm output

From: Stephen Rothwell <hidden>
Date: 2020-08-11 14:22:13

We don't use the raw hex instruction dump, so elide it and adjust the
following expressions.

Also use \s instead of [[:space:]] everywhere.

Cc: Nicholas Piggin <npiggin@gmail.com>
Signed-off-by: Stephen Rothwell <redacted>
---
 arch/powerpc/tools/unrel_branch_check.sh | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/arch/powerpc/tools/unrel_branch_check.sh b/arch/powerpc/tools/unrel_branch_check.sh
index d735e3875b5e..7e936e2cf70d 100755
--- a/arch/powerpc/tools/unrel_branch_check.sh
+++ b/arch/powerpc/tools/unrel_branch_check.sh
@@ -26,16 +26,16 @@ awk '$2 == "<__end_interrupts>:" { print $1 }'
 )
 
 BRANCHES=$(
-$objdump -R -D --start-address="$kstart" --stop-address="$end_intr" "$vmlinux" |
-grep -e "^c[0-9a-f]*:[[:space:]]*\([0-9a-f][0-9a-f][[:space:]]\)\{4\}[[:space:]]*b" |
+$objdump -R -D --no-show-raw-insn --start-address="$kstart" --stop-address="$end_intr" "$vmlinux" |
+grep -e "^c[0-9a-f]*:\s*b" |
 sed -e '/\<__start_initialization_multiplatform>/d' \
 	-e '/b.\?.\?ctr/d' \
 	-e '/b.\?.\?lr/d' \
-	-e 's/\bbt.\?[[:space:]]*[[:digit:]][[:digit:]]*,/beq/' \
-	-e 's/\bbf.\?[[:space:]]*[[:digit:]][[:digit:]]*,/bne/' \
-	-e 's/[[:space:]]0x/ /' \
+	-e 's/\bbt.\?\s*[[:digit:]][[:digit:]]*,/beq/' \
+	-e 's/\bbf.\?\s*[[:digit:]][[:digit:]]*,/bne/' \
+	-e 's/\s0x/ /' \
 	-e 's/://' |
-awk '{ print $1 ":" $6 ":0x" $7 ":" $8 " "}'
+awk '{ print $1 ":" $2 ":0x" $3 ":" $4 " "}'
 )
 
 for tuple in $BRANCHES; do
-- 
2.28.0

[PATCH 4/7] powerpc: unrel_branch_check.sh: convert grep | sed | awk to just sed

From: Stephen Rothwell <hidden>
Date: 2020-08-11 14:25:09

Also start using sed -E and make all the separate expressions into a
single one with comments.  Pull the stripping of condition registers
back into the sed command.

Cc: Nicholas Piggin <npiggin@gmail.com>
Signed-off-by: Stephen Rothwell <redacted>
---
 arch/powerpc/tools/unrel_branch_check.sh | 30 ++++++++++++++++--------
 1 file changed, 20 insertions(+), 10 deletions(-)
diff --git a/arch/powerpc/tools/unrel_branch_check.sh b/arch/powerpc/tools/unrel_branch_check.sh
index 7e936e2cf70d..dc82289b2252 100755
--- a/arch/powerpc/tools/unrel_branch_check.sh
+++ b/arch/powerpc/tools/unrel_branch_check.sh
@@ -27,21 +27,31 @@ awk '$2 == "<__end_interrupts>:" { print $1 }'
 
 BRANCHES=$(
 $objdump -R -D --no-show-raw-insn --start-address="$kstart" --stop-address="$end_intr" "$vmlinux" |
-grep -e "^c[0-9a-f]*:\s*b" |
-sed -e '/\<__start_initialization_multiplatform>/d' \
-	-e '/b.\?.\?ctr/d' \
-	-e '/b.\?.\?lr/d' \
-	-e 's/\bbt.\?\s*[[:digit:]][[:digit:]]*,/beq/' \
-	-e 's/\bbf.\?\s*[[:digit:]][[:digit:]]*,/bne/' \
-	-e 's/\s0x/ /' \
-	-e 's/://' |
-awk '{ print $1 ":" $2 ":0x" $3 ":" $4 " "}'
+sed -E -n '
+# match lines that start with a kernel address
+/^c[0-9a-f]*:\s*b/ {
+	# drop a target that we do not care about
+	/\<__start_initialization_multiplatform>/d
+	# drop branches via ctr or lr
+	/\<b.?.?(ct|l)r/d
+	# cope with some differences between Clang and GNU objdumps
+	s/\<bt.?\s*[[:digit:]]+,/beq/
+	s/\<bf.?\s*[[:digit:]]+,/bne/
+	# tidy up
+	s/\s0x/ /
+	s/://
+	# format for the loop below
+	s/^(\S+)\s+(\S+)\s+(\S+)\s*(\S*).*$/\1:\2:0x\3:\4/
+	# strip out condition registers
+	s/:0xcr[0-7],/:0x/
+	p
+}'
 )
 
 for tuple in $BRANCHES; do
 	from=$(echo "$tuple" | cut -d':' -f1)
 	branch=$(echo "$tuple" | cut -d':' -f2)
-	to=$(echo "$tuple" | cut -d':' -f3 | sed 's/cr[0-7],//')
+	to=$(echo "$tuple" | cut -d':' -f3)
 	sym=$(echo "$tuple" | cut -d':' -f4)
 
 	if (( to > end_intr )); then
-- 
2.28.0

[PATCH 5/7] powerpc: unrel_branch_check.sh: simplify and tidy up the final loop

From: Stephen Rothwell <hidden>
Date: 2020-08-11 14:28:22

Cc: Nicholas Piggin <npiggin@gmail.com>
Signed-off-by: Stephen Rothwell <redacted>
---
 arch/powerpc/tools/unrel_branch_check.sh | 26 +++++++++---------------
 1 file changed, 10 insertions(+), 16 deletions(-)
diff --git a/arch/powerpc/tools/unrel_branch_check.sh b/arch/powerpc/tools/unrel_branch_check.sh
index dc82289b2252..54ebd05615d4 100755
--- a/arch/powerpc/tools/unrel_branch_check.sh
+++ b/arch/powerpc/tools/unrel_branch_check.sh
@@ -25,7 +25,6 @@ $objdump -R -d --start-address="$kstart" --stop-address="$kend" "$vmlinux" |
 awk '$2 == "<__end_interrupts>:" { print $1 }'
 )
 
-BRANCHES=$(
 $objdump -R -D --no-show-raw-insn --start-address="$kstart" --stop-address="$end_intr" "$vmlinux" |
 sed -E -n '
 # match lines that start with a kernel address
@@ -45,24 +44,19 @@ sed -E -n '
 	# strip out condition registers
 	s/:0xcr[0-7],/:0x/
 	p
-}'
-)
-
-for tuple in $BRANCHES; do
-	from=$(echo "$tuple" | cut -d':' -f1)
-	branch=$(echo "$tuple" | cut -d':' -f2)
-	to=$(echo "$tuple" | cut -d':' -f3)
-	sym=$(echo "$tuple" | cut -d':' -f4)
+}' | {
 
+all_good=true
+while IFS=: read -r from branch to sym; do
 	if (( to > end_intr )); then
-		if [ -z "$bad_branches" ]; then
-			echo "WARNING: Unrelocated relative branches"
-			bad_branches="yes"
+		if $all_good; then
+			printf '%s\n' 'WARNING: Unrelocated relative branches'
+			all_good=false
 		fi
-		echo "$from $branch-> $to $sym"
+		printf '%s %s-> %s %s\n' "$from" "$branch" "$to" "$sym"
 	fi
 done
 
-if [ -z "$bad_branches" ]; then
-	exit 0
-fi
+$all_good
+
+}
-- 
2.28.0

[PATCH 6/7] powerpc: unrel_branch_check.sh: fix up the file header

From: Stephen Rothwell <hidden>
Date: 2020-08-11 14:32:48

Cc: Nicholas Piggin <npiggin@gmail.com>
Signed-off-by: Stephen Rothwell <redacted>
---
 arch/powerpc/tools/unrel_branch_check.sh | 15 ++++-----------
 1 file changed, 4 insertions(+), 11 deletions(-)
diff --git a/arch/powerpc/tools/unrel_branch_check.sh b/arch/powerpc/tools/unrel_branch_check.sh
index 54ebd05615d4..4489f16a443c 100755
--- a/arch/powerpc/tools/unrel_branch_check.sh
+++ b/arch/powerpc/tools/unrel_branch_check.sh
@@ -1,16 +1,9 @@
 #!/bin/bash
-# Copyright © 2016 IBM Corporation
+# SPDX-License-Identifier: GPL-2.0+
+# Copyright © 2016,2020 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 the relocations of a vmlinux for "suspicious"
-# branches from unrelocated code (head_64.S code).
-
-# Turn this on if you want more debug output:
-# set -x
+# This script checks the unrelocated code of a vmlinux for "suspicious"
+# branches to relocated code (head_64.S code).
 
 # Have Kbuild supply the path to objdump so we handle cross compilation.
 objdump="$1"
-- 
2.28.0

[PATCH 7/7] powerpc: unrel_branch_check.sh: exit silently for early errors

From: Stephen Rothwell <hidden>
Date: 2020-08-11 14:35:59

If we can't find the address of __end_interrupts, then we still exit
successfully as that is the current behaviour.

Cc: Nicholas Piggin <npiggin@gmail.com>
Signed-off-by: Stephen Rothwell <redacted>
---
 arch/powerpc/tools/unrel_branch_check.sh | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/arch/powerpc/tools/unrel_branch_check.sh b/arch/powerpc/tools/unrel_branch_check.sh
index 4489f16a443c..70da90270c78 100755
--- a/arch/powerpc/tools/unrel_branch_check.sh
+++ b/arch/powerpc/tools/unrel_branch_check.sh
@@ -14,9 +14,12 @@ kstart=0xc000000000000000
 printf -v kend '0x%x' $(( kstart + 0x10000 ))
 
 end_intr=0x$(
-$objdump -R -d --start-address="$kstart" --stop-address="$kend" "$vmlinux" |
+$objdump -R -d --start-address="$kstart" --stop-address="$kend" "$vmlinux" 2>/dev/null |
 awk '$2 == "<__end_interrupts>:" { print $1 }'
 )
+if [ "$end_intr" = "0x" ]; then
+	exit 0
+fi
 
 $objdump -R -D --no-show-raw-insn --start-address="$kstart" --stop-address="$end_intr" "$vmlinux" |
 sed -E -n '
-- 
2.28.0

Re: [PATCH 0/7] powerpc: unrel_branch_check.sh: make it suck less

From: Michael Ellerman <hidden>
Date: 2020-09-09 15:08:55

On Wed, 12 Aug 2020 00:04:27 +1000, Stephen Rothwell wrote:
Michael Ellerman: "who wants to make
arch/powerpc/tools/unrel_branch_check.sh suck less"

This series is based off the current powerpc/next branch and keeps the
same functionaity as the original except that it suppresses some error
messages for early failures that still cause this script to succeed
(as it always did).

[...]
Applied to powerpc/next.

[1/7] powerpc: unrel_branch_check.sh: fix shellcheck complaints
      https://git.kernel.org/powerpc/c/d9de6b0da85c9f51734f7648f6e860b89f94c801
[2/7] powerpc: unrel_branch_check.sh: simplify and combine some executions
      https://git.kernel.org/powerpc/c/20ff8ec182160df86571a8af5773ff1e52837d73
[3/7] powerpc: unrel_branch_check.sh: simplify objdump's asm output
      https://git.kernel.org/powerpc/c/4e71106c343c625c0bf72a65b244e35e7d2cd037
[4/7] powerpc: unrel_branch_check.sh: convert grep | sed | awk to just sed
      https://git.kernel.org/powerpc/c/3d97abbc9f6fe90973551f3e3eef47ffef863114
[5/7] powerpc: unrel_branch_check.sh: simplify and tidy up the final loop
      https://git.kernel.org/powerpc/c/b84eaab6ede6477484edc043456cf7d7cfc7f8b3
[6/7] powerpc: unrel_branch_check.sh: fix up the file header
      https://git.kernel.org/powerpc/c/3745ae63b405b09c86718f95d96c4b2d2827b087
[7/7] powerpc: unrel_branch_check.sh: exit silently for early errors
      https://git.kernel.org/powerpc/c/af13a2244d59c4d63a25abd8257cbaef9d9ffebc

cheers
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help