[PATCH v1 3/3] riscv/purgatory: do not link with string.o

From: Petr Tesarik
Date: Tue Jul 25 2023 - 04:49:26 EST


From: Petr Tesarik <petr.tesarik.ext@xxxxxxxxxx>

Linking with this object file it makes kexec_file_load(2) fail with:

kexec_image: Unknown rela relocation: 20
kexec_image: Error loading purgatory ret=-8

This is R_RISCV_GOT_HI20, generated by the linker to handle references to
the global variable _ctype from strcasecmp() and strncasecmp().

Rather than implementing GOT for the purgatory, remove the object file,
because it is not needed by the purgatory code.

Fixes: 838b3e28488f ("RISC-V: Load purgatory in kexec_file")
Signed-off-by: Petr Tesarik <petr.tesarik.ext@xxxxxxxxxx>
Cc: Li Zhengyu <lizhengyu3@xxxxxxxxxx>
Cc: stable@xxxxxxxxxxxxxxx
---
arch/riscv/purgatory/Makefile | 9 +--------
1 file changed, 1 insertion(+), 8 deletions(-)

diff --git a/arch/riscv/purgatory/Makefile b/arch/riscv/purgatory/Makefile
index dc20e166983e..497bb72b6ba8 100644
--- a/arch/riscv/purgatory/Makefile
+++ b/arch/riscv/purgatory/Makefile
@@ -1,15 +1,12 @@
# SPDX-License-Identifier: GPL-2.0
OBJECT_FILES_NON_STANDARD := y

-purgatory-y := purgatory.o sha256.o entry.o string.o ctype.o memcpy.o memset.o
+purgatory-y := purgatory.o sha256.o entry.o ctype.o memcpy.o memset.o
purgatory-y += strcmp.o strlen.o strncmp.o

targets += $(purgatory-y)
PURGATORY_OBJS = $(addprefix $(obj)/,$(purgatory-y))

-$(obj)/string.o: $(srctree)/lib/string.c FORCE
- $(call if_changed_rule,cc_o_c)
-
$(obj)/ctype.o: $(srctree)/lib/ctype.c FORCE
$(call if_changed_rule,cc_o_c)

@@ -32,7 +29,6 @@ $(obj)/sha256.o: $(srctree)/lib/crypto/sha256.c FORCE
$(call if_changed_rule,cc_o_c)

CFLAGS_sha256.o := -D__DISABLE_EXPORTS -D__NO_FORTIFY
-CFLAGS_string.o := -D__DISABLE_EXPORTS
CFLAGS_ctype.o := -D__DISABLE_EXPORTS

# When profile-guided optimization is enabled, llvm emits two different
@@ -83,9 +79,6 @@ CFLAGS_purgatory.o += $(PURGATORY_CFLAGS)
CFLAGS_REMOVE_sha256.o += $(PURGATORY_CFLAGS_REMOVE)
CFLAGS_sha256.o += $(PURGATORY_CFLAGS)

-CFLAGS_REMOVE_string.o += $(PURGATORY_CFLAGS_REMOVE)
-CFLAGS_string.o += $(PURGATORY_CFLAGS)
-
CFLAGS_REMOVE_ctype.o += $(PURGATORY_CFLAGS_REMOVE)
CFLAGS_ctype.o += $(PURGATORY_CFLAGS)

--
2.25.1