Stephen Rothwell | a71aa05 | 2015-03-18 16:46:16 +1100 | [diff] [blame] | 1 | #!/bin/sh |
Thomas Gleixner | 2874c5f | 2019-05-27 08:55:01 +0200 | [diff] [blame] | 2 | # SPDX-License-Identifier: GPL-2.0-or-later |
Stephen Rothwell | a71aa05 | 2015-03-18 16:46:16 +1100 | [diff] [blame] | 3 | |
| 4 | # Copyright © 2015 IBM Corporation |
| 5 | |
Stephen Rothwell | a71aa05 | 2015-03-18 16:46:16 +1100 | [diff] [blame] | 6 | |
| 7 | # This script checks the relocations of a vmlinux for "suspicious" |
| 8 | # relocations. |
| 9 | |
| 10 | # based on relocs_check.pl |
| 11 | # Copyright © 2009 IBM Corporation |
| 12 | |
Alexandre Ghiti | 43e76cd | 2020-01-18 12:03:35 -0500 | [diff] [blame] | 13 | if [ $# -lt 3 ]; then |
| 14 | echo "$0 [path to objdump] [path to nm] [path to vmlinux]" 1>&2 |
Stephen Rothwell | a71aa05 | 2015-03-18 16:46:16 +1100 | [diff] [blame] | 15 | exit 1 |
| 16 | fi |
| 17 | |
Alexandre Ghiti | 43e76cd | 2020-01-18 12:03:35 -0500 | [diff] [blame] | 18 | # Have Kbuild supply the path to objdump and nm so we handle cross compilation. |
Stephen Rothwell | a71aa05 | 2015-03-18 16:46:16 +1100 | [diff] [blame] | 19 | objdump="$1" |
Alexandre Ghiti | 43e76cd | 2020-01-18 12:03:35 -0500 | [diff] [blame] | 20 | nm="$2" |
| 21 | vmlinux="$3" |
| 22 | |
| 23 | # Remove from the bad relocations those that match an undefined weak symbol |
| 24 | # which will result in an absolute relocation to 0. |
| 25 | # Weak unresolved symbols are of that form in nm output: |
| 26 | # " w _binary__btf_vmlinux_bin_end" |
| 27 | undef_weak_symbols=$($nm "$vmlinux" | awk '$1 ~ /w/ { print $2 }') |
Stephen Rothwell | a71aa05 | 2015-03-18 16:46:16 +1100 | [diff] [blame] | 28 | |
| 29 | bad_relocs=$( |
Michael Ellerman | e44ff9e | 2019-10-24 11:47:30 +1100 | [diff] [blame] | 30 | $objdump -R "$vmlinux" | |
Stephen Rothwell | a71aa05 | 2015-03-18 16:46:16 +1100 | [diff] [blame] | 31 | # Only look at relocation lines. |
| 32 | grep -E '\<R_' | |
| 33 | # These relocations are okay |
| 34 | # On PPC64: |
| 35 | # R_PPC64_RELATIVE, R_PPC64_NONE |
Stephen Rothwell | a71aa05 | 2015-03-18 16:46:16 +1100 | [diff] [blame] | 36 | # On PPC: |
| 37 | # R_PPC_RELATIVE, R_PPC_ADDR16_HI, |
| 38 | # R_PPC_ADDR16_HA,R_PPC_ADDR16_LO, |
| 39 | # R_PPC_NONE |
| 40 | grep -F -w -v 'R_PPC64_RELATIVE |
| 41 | R_PPC64_NONE |
| 42 | R_PPC_ADDR16_LO |
| 43 | R_PPC_ADDR16_HI |
| 44 | R_PPC_ADDR16_HA |
| 45 | R_PPC_RELATIVE |
| 46 | R_PPC_NONE' | |
Alexandre Ghiti | 43e76cd | 2020-01-18 12:03:35 -0500 | [diff] [blame] | 47 | ([ "$undef_weak_symbols" ] && grep -F -w -v "$undef_weak_symbols" || cat) |
Stephen Rothwell | a71aa05 | 2015-03-18 16:46:16 +1100 | [diff] [blame] | 48 | ) |
| 49 | |
| 50 | if [ -z "$bad_relocs" ]; then |
| 51 | exit 0 |
| 52 | fi |
| 53 | |
| 54 | num_bad=$(echo "$bad_relocs" | wc -l) |
| 55 | echo "WARNING: $num_bad bad relocations" |
| 56 | echo "$bad_relocs" |
| 57 | |
| 58 | # If we see this type of relocation it's an idication that |
| 59 | # we /may/ be using an old version of binutils. |
| 60 | if echo "$bad_relocs" | grep -q -F -w R_PPC64_UADDR64; then |
| 61 | echo "WARNING: You need at least binutils >= 2.19 to build a CONFIG_RELOCATABLE kernel" |
| 62 | fi |