Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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 <alex@ghiti.fr>
Reviewed-by: Anup Patel <anup@brainfault.org>
Acked-by: Michael Ellerman <mpe@ellerman.id.au> (powerpc)
Link: https://lore.kernel.org/r/20230329045329.64565-5-alexghiti@rivosinc.com
Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>

authored by

Alexandre Ghiti and committed by
Palmer Dabbelt
47981b5c 39b33072

+22 -16
+2 -16
arch/powerpc/tools/relocs_check.sh
··· 15 15 exit 1 16 16 fi 17 17 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 - 29 18 bad_relocs=$( 30 - $objdump -R "$vmlinux" | 31 - # Only look at relocation lines. 32 - grep -E '\<R_' | 19 + ${srctree}/scripts/relocs_check.sh "$@" | 33 20 # These relocations are okay 34 21 # On PPC64: 35 22 # R_PPC64_RELATIVE, R_PPC64_NONE ··· 31 44 R_PPC_ADDR16_HI 32 45 R_PPC_ADDR16_HA 33 46 R_PPC_RELATIVE 34 - R_PPC_NONE' | 35 - ([ "$undef_weak_symbols" ] && grep -F -w -v "$undef_weak_symbols" || cat) 47 + R_PPC_NONE' 36 48 ) 37 49 38 50 if [ -z "$bad_relocs" ]; then
+20
scripts/relocs_check.sh
··· 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)