Skip to content

Commit a531e6b

Browse files
AlexGhitigregkh
authored andcommitted
powerpc: Do not consider weak unresolved symbol relocations as bad
[ Upstream commit 43e76cd ] Commit 8580ac9 ("bpf: Process in-kernel BTF") introduced two weak symbols that may be unresolved at link time which result in an absolute relocation to 0. relocs_check.sh emits the following warning: "WARNING: 2 bad relocations c000000001a41478 R_PPC64_ADDR64 _binary__btf_vmlinux_bin_start c000000001a41480 R_PPC64_ADDR64 _binary__btf_vmlinux_bin_end" whereas those relocations are legitimate even for a relocatable kernel compiled with -pie option. relocs_check.sh already excluded some weak unresolved symbols explicitly: remove those hardcoded symbols and add some logic that parses the symbols using nm, retrieves all the weak unresolved symbols and excludes those from the list of the potential bad relocations. Reported-by: Stephen Rothwell <[email protected]> Signed-off-by: Alexandre Ghiti <[email protected]> Signed-off-by: Michael Ellerman <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Sasha Levin <[email protected]>
1 parent 528c36e commit a531e6b

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

arch/powerpc/Makefile.postlink

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ quiet_cmd_head_check = CHKHEAD $@
1717
quiet_cmd_relocs_check = CHKREL $@
1818
ifdef CONFIG_PPC_BOOK3S_64
1919
cmd_relocs_check = \
20-
$(CONFIG_SHELL) $(srctree)/arch/powerpc/tools/relocs_check.sh "$(OBJDUMP)" "$@" ; \
20+
$(CONFIG_SHELL) $(srctree)/arch/powerpc/tools/relocs_check.sh "$(OBJDUMP)" "$(NM)" "$@" ; \
2121
$(BASH) $(srctree)/arch/powerpc/tools/unrel_branch_check.sh "$(OBJDUMP)" "$@"
2222
else
2323
cmd_relocs_check = \
24-
$(CONFIG_SHELL) $(srctree)/arch/powerpc/tools/relocs_check.sh "$(OBJDUMP)" "$@"
24+
$(CONFIG_SHELL) $(srctree)/arch/powerpc/tools/relocs_check.sh "$(OBJDUMP)" "$(NM)" "$@"
2525
endif
2626

2727
# `@true` prevents complaint when there is nothing to be done

arch/powerpc/tools/relocs_check.sh

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,21 @@
1010
# based on relocs_check.pl
1111
# Copyright © 2009 IBM Corporation
1212

13-
if [ $# -lt 2 ]; then
14-
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
1515
exit 1
1616
fi
1717

18-
# 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.
1919
objdump="$1"
20-
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 }')
2128

2229
bad_relocs=$(
2330
$objdump -R "$vmlinux" |
@@ -26,8 +33,6 @@ $objdump -R "$vmlinux" |
2633
# These relocations are okay
2734
# On PPC64:
2835
# R_PPC64_RELATIVE, R_PPC64_NONE
29-
# R_PPC64_ADDR64 mach_<name>
30-
# R_PPC64_ADDR64 __crc_<name>
3136
# On PPC:
3237
# R_PPC_RELATIVE, R_PPC_ADDR16_HI,
3338
# R_PPC_ADDR16_HA,R_PPC_ADDR16_LO,
@@ -39,8 +44,7 @@ R_PPC_ADDR16_HI
3944
R_PPC_ADDR16_HA
4045
R_PPC_RELATIVE
4146
R_PPC_NONE' |
42-
grep -E -v '\<R_PPC64_ADDR64[[:space:]]+mach_' |
43-
grep -E -v '\<R_PPC64_ADDR64[[:space:]]+__crc_'
47+
([ "$undef_weak_symbols" ] && grep -F -w -v "$undef_weak_symbols" || cat)
4448
)
4549

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

0 commit comments

Comments
 (0)