Skip to content

Commit 47981b5

Browse files
AlexGhitipalmer-dabbelt
authored andcommitted
powerpc: Move script to check relocations at compile time in scripts/
Relocating kernel at runtime is done very early in the boot process, so it is not convenient to check for relocations there and react in case a relocation was not expected. Powerpc architecture has a script that allows to check at compile time for such unexpected relocations: extract the common logic to scripts/ so that other architectures can take advantage of it. Signed-off-by: Alexandre Ghiti <[email protected]> Reviewed-by: Anup Patel <[email protected]> Acked-by: Michael Ellerman <[email protected]> (powerpc) Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Palmer Dabbelt <[email protected]>
1 parent 39b3307 commit 47981b5

File tree

2 files changed

+22
-16
lines changed

2 files changed

+22
-16
lines changed

arch/powerpc/tools/relocs_check.sh

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,8 @@ if [ $# -lt 3 ]; then
1515
exit 1
1616
fi
1717

18-
# Have Kbuild supply the path to objdump and nm so we handle cross compilation.
19-
objdump="$1"
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 }')
28-
2918
bad_relocs=$(
30-
$objdump -R "$vmlinux" |
31-
# Only look at relocation lines.
32-
grep -E '\<R_' |
19+
${srctree}/scripts/relocs_check.sh "$@" |
3320
# These relocations are okay
3421
# On PPC64:
3522
# R_PPC64_RELATIVE, R_PPC64_NONE
@@ -44,8 +31,7 @@ R_PPC_ADDR16_LO
4431
R_PPC_ADDR16_HI
4532
R_PPC_ADDR16_HA
4633
R_PPC_RELATIVE
47-
R_PPC_NONE' |
48-
([ "$undef_weak_symbols" ] && grep -F -w -v "$undef_weak_symbols" || cat)
34+
R_PPC_NONE'
4935
)
5036

5137
if [ -z "$bad_relocs" ]; then

scripts/relocs_check.sh

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

0 commit comments

Comments
 (0)