xref: /openbmc/linux/scripts/relocs_check.sh (revision 47981b5c)
1*47981b5cSAlexandre Ghiti#!/bin/sh
2*47981b5cSAlexandre Ghiti# SPDX-License-Identifier: GPL-2.0-or-later
3*47981b5cSAlexandre Ghiti
4*47981b5cSAlexandre Ghiti# Get a list of all the relocations, remove from it the relocations
5*47981b5cSAlexandre Ghiti# that are known to be legitimate and return this list to arch specific
6*47981b5cSAlexandre Ghiti# script that will look for suspicious relocations.
7*47981b5cSAlexandre Ghiti
8*47981b5cSAlexandre Ghitiobjdump="$1"
9*47981b5cSAlexandre Ghitinm="$2"
10*47981b5cSAlexandre Ghitivmlinux="$3"
11*47981b5cSAlexandre Ghiti
12*47981b5cSAlexandre Ghiti# Remove from the possible bad relocations those that match an undefined
13*47981b5cSAlexandre Ghiti# weak symbol which will result in an absolute relocation to 0.
14*47981b5cSAlexandre Ghiti# Weak unresolved symbols are of that form in nm output:
15*47981b5cSAlexandre Ghiti# "                  w _binary__btf_vmlinux_bin_end"
16*47981b5cSAlexandre Ghitiundef_weak_symbols=$($nm "$vmlinux" | awk '$1 ~ /w/ { print $2 }')
17*47981b5cSAlexandre Ghiti
18*47981b5cSAlexandre Ghiti$objdump -R "$vmlinux" |
19*47981b5cSAlexandre Ghiti	grep -E '\<R_' |
20*47981b5cSAlexandre Ghiti	([ "$undef_weak_symbols" ] && grep -F -w -v "$undef_weak_symbols" || cat)
21