.. | .. |
---|
1 | 1 | #!/bin/sh |
---|
| 2 | +# SPDX-License-Identifier: GPL-2.0-or-later |
---|
2 | 3 | |
---|
3 | 4 | # Copyright © 2015 IBM Corporation |
---|
4 | 5 | |
---|
5 | | -# This program is free software; you can redistribute it and/or |
---|
6 | | -# modify it under the terms of the GNU General Public License |
---|
7 | | -# as published by the Free Software Foundation; either version |
---|
8 | | -# 2 of the License, or (at your option) any later version. |
---|
9 | 6 | |
---|
10 | 7 | # This script checks the relocations of a vmlinux for "suspicious" |
---|
11 | 8 | # relocations. |
---|
.. | .. |
---|
13 | 10 | # based on relocs_check.pl |
---|
14 | 11 | # Copyright © 2009 IBM Corporation |
---|
15 | 12 | |
---|
16 | | -if [ $# -lt 2 ]; then |
---|
17 | | - echo "$0 [path to objdump] [path to vmlinux]" 1>&2 |
---|
| 13 | +if [ $# -lt 3 ]; then |
---|
| 14 | + echo "$0 [path to objdump] [path to nm] [path to vmlinux]" 1>&2 |
---|
18 | 15 | exit 1 |
---|
19 | 16 | fi |
---|
20 | 17 | |
---|
21 | | -# Have Kbuild supply the path to objdump so we handle cross compilation. |
---|
| 18 | +# Have Kbuild supply the path to objdump and nm so we handle cross compilation. |
---|
22 | 19 | objdump="$1" |
---|
23 | | -vmlinux="$2" |
---|
| 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 }') |
---|
24 | 28 | |
---|
25 | 29 | bad_relocs=$( |
---|
26 | 30 | $objdump -R "$vmlinux" | |
---|
.. | .. |
---|
29 | 33 | # These relocations are okay |
---|
30 | 34 | # On PPC64: |
---|
31 | 35 | # R_PPC64_RELATIVE, R_PPC64_NONE |
---|
32 | | - # R_PPC64_ADDR64 mach_<name> |
---|
33 | | - # R_PPC64_ADDR64 __crc_<name> |
---|
34 | 36 | # On PPC: |
---|
35 | 37 | # R_PPC_RELATIVE, R_PPC_ADDR16_HI, |
---|
36 | 38 | # R_PPC_ADDR16_HA,R_PPC_ADDR16_LO, |
---|
.. | .. |
---|
42 | 44 | R_PPC_ADDR16_HA |
---|
43 | 45 | R_PPC_RELATIVE |
---|
44 | 46 | R_PPC_NONE' | |
---|
45 | | - grep -E -v '\<R_PPC64_ADDR64[[:space:]]+mach_' | |
---|
46 | | - grep -E -v '\<R_PPC64_ADDR64[[:space:]]+__crc_' |
---|
| 47 | + ([ "$undef_weak_symbols" ] && grep -F -w -v "$undef_weak_symbols" || cat) |
---|
47 | 48 | ) |
---|
48 | 49 | |
---|
49 | 50 | if [ -z "$bad_relocs" ]; then |
---|