~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/arch/powerpc/tools/unrel_branch_check.sh

Version: ~ [ linux-6.12-rc7 ] ~ [ linux-6.11.7 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.60 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.116 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.171 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.229 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.285 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.323 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.12 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 #!/bin/bash
  2 # SPDX-License-Identifier: GPL-2.0+
  3 # Copyright © 2016,2020 IBM Corporation
  4 #
  5 # This script checks the unrelocated code of a vmlinux for "suspicious"
  6 # branches to relocated code (head_64.S code).
  7 
  8 # Have Kbuild supply the path to objdump and nm so we handle cross compilation.
  9 objdump="$1"
 10 nm="$2"
 11 vmlinux="$3"
 12 
 13 kstart=0xc000000000000000
 14 
 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
 18         exit 0
 19 fi
 20 
 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" |
 28 sed -E -n '
 29 # match lines that start with a kernel address
 30 /^c[0-9a-f]*:\s*b/ {
 31         # drop branches via ctr or lr
 32         /\<b.?.?(ct|l)r/d
 33         # cope with some differences between Clang and GNU objdumps
 34         s/\<bt.?\s*[[:digit:]]+,/beq/
 35         s/\<bf.?\s*[[:digit:]]+,/bne/
 36         # tidy up
 37         s/\s0x/ /
 38         s/://
 39         # format for the loop below
 40         s/^(\S+)\s+(\S+)\s+(\S+)\s*(\S*).*$/\1:\2:\3:\4/
 41         # strip out condition registers
 42         s/:cr[0-7],/:/
 43         p
 44 }' | {
 45 
 46 all_good=true
 47 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
 68         if (( to > end_intr )); then
 69                 if $all_good; then
 70                         printf '%s\n' 'WARNING: Unrelocated relative branches'
 71                         all_good=false
 72                 fi
 73                 printf '%s %s-> %s %s\n' "$from" "$branch" "$to" "$sym"
 74         fi
 75 done
 76 
 77 $all_good
 78 
 79 }

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php