1#!/bin/sh
2# SPDX-License-Identifier: GPL-2.0-or-later
3
4# Copyright © 2015 IBM Corporation
5
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
13if [ $# -lt 2 ]; then
14	echo "$0 [path to objdump] [path to vmlinux]" 1>&2
15	exit 1
16fi
17
18# Have Kbuild supply the path to objdump so we handle cross compilation.
19objdump="$1"
20vmlinux="$2"
21
22bad_relocs=$(
23$objdump -R "$vmlinux" |
24	# Only look at relocation lines.
25	grep -E '\<R_' |
26	# These relocations are okay
27	# On PPC64:
28	#	R_PPC64_RELATIVE, R_PPC64_NONE
29	#	R_PPC64_ADDR64 mach_<name>
30	#	R_PPC64_ADDR64 __crc_<name>
31	# On PPC:
32	#	R_PPC_RELATIVE, R_PPC_ADDR16_HI,
33	#	R_PPC_ADDR16_HA,R_PPC_ADDR16_LO,
34	#	R_PPC_NONE
35	grep -F -w -v 'R_PPC64_RELATIVE
36R_PPC64_NONE
37R_PPC_ADDR16_LO
38R_PPC_ADDR16_HI
39R_PPC_ADDR16_HA
40R_PPC_RELATIVE
41R_PPC_NONE' |
42	grep -E -v '\<R_PPC64_ADDR64[[:space:]]+mach_' |
43	grep -E -v '\<R_PPC64_ADDR64[[:space:]]+__crc_'
44)
45
46if [ -z "$bad_relocs" ]; then
47	exit 0
48fi
49
50num_bad=$(echo "$bad_relocs" | wc -l)
51echo "WARNING: $num_bad bad relocations"
52echo "$bad_relocs"
53
54# If we see this type of relocation it's an idication that
55# we /may/ be using an old version of binutils.
56if echo "$bad_relocs" | grep -q -F -w R_PPC64_UADDR64; then
57	echo "WARNING: You need at least binutils >= 2.19 to build a CONFIG_RELOCATABLE kernel"
58fi
59