Back to home page

OSCL-LXR

 
 

    


0001 #!/bin/sh
0002 # SPDX-License-Identifier: GPL-2.0-or-later
0003 
0004 # Copyright © 2015 IBM Corporation
0005 
0006 
0007 # This script checks the relocations of a vmlinux for "suspicious"
0008 # relocations.
0009 
0010 # based on relocs_check.pl
0011 # Copyright © 2009 IBM Corporation
0012 
0013 if [ $# -lt 3 ]; then
0014         echo "$0 [path to objdump] [path to nm] [path to vmlinux]" 1>&2
0015         exit 1
0016 fi
0017 
0018 # Have Kbuild supply the path to objdump and nm so we handle cross compilation.
0019 objdump="$1"
0020 nm="$2"
0021 vmlinux="$3"
0022 
0023 # Remove from the bad relocations those that match an undefined weak symbol
0024 # which will result in an absolute relocation to 0.
0025 # Weak unresolved symbols are of that form in nm output:
0026 # "                  w _binary__btf_vmlinux_bin_end"
0027 undef_weak_symbols=$($nm "$vmlinux" | awk '$1 ~ /w/ { print $2 }')
0028 
0029 bad_relocs=$(
0030 $objdump -R "$vmlinux" |
0031         # Only look at relocation lines.
0032         grep -E '\<R_' |
0033         # These relocations are okay
0034         # On PPC64:
0035         #       R_PPC64_RELATIVE, R_PPC64_NONE
0036         # On PPC:
0037         #       R_PPC_RELATIVE, R_PPC_ADDR16_HI,
0038         #       R_PPC_ADDR16_HA,R_PPC_ADDR16_LO,
0039         #       R_PPC_NONE
0040         grep -F -w -v 'R_PPC64_RELATIVE
0041 R_PPC64_NONE
0042 R_PPC64_UADDR64
0043 R_PPC_ADDR16_LO
0044 R_PPC_ADDR16_HI
0045 R_PPC_ADDR16_HA
0046 R_PPC_RELATIVE
0047 R_PPC_NONE' |
0048         ([ "$undef_weak_symbols" ] && grep -F -w -v "$undef_weak_symbols" || cat)
0049 )
0050 
0051 if [ -z "$bad_relocs" ]; then
0052         exit 0
0053 fi
0054 
0055 num_bad=$(echo "$bad_relocs" | wc -l)
0056 echo "WARNING: $num_bad bad relocations"
0057 echo "$bad_relocs"