From e5fc5477391326a84217da8b35899ed6547552f0 Mon Sep 17 00:00:00 2001 From: Thomas Huth Date: Mon, 28 Sep 2026 10:30:53 +0200 Subject: [PATCH] x86/purgatory: Compile purgatory with -D__NO_FORTIFY and -D__DISABLE_EXPORTS MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A subsequent patch will add #include to to use memzero_explicit() there. This will introduce a conflict with the purgatory code: purgatory.c includes both, the header and the arch/x86/boot/string.h header. The latter provides its own prototypes for a lot of string functions which clash with the fortified macros from , causing the compiler to emit errors like this: In file included from .../linux/include/linux/string.h:383, from .../linux/include/crypto/sha2.h:10, from .../linux/arch/x86/purgatory/purgatory.c:14: .../linux/include/linux/fortify-string.h:576:63: error: expected identifier or ‘(’ before ‘{’ token 576 | p_size_field, q_size_field, op) ({ \ | ^ .../linux/include/linux/fortify-string.h:644:27: note: in expansion of macro ‘__fortify_memcpy_chk’ 644 | #define memmove(p, q, s) __fortify_memcpy_chk(p, q, s, \ | ^~~~~~~~~~~~~~~~~~~~ .../linux/arch/x86/purgatory/../boot/string.h:11:7: note: in expansion of macro ‘memmove’ 11 | void *memmove(void *dst, const void *src, size_t len); | ^~~~~~~ .../linux/include/linux/fortify-string.h:208:9: error: expected identifier or ‘(’ before ‘__builtin_choose_expr’ 208 | __builtin_choose_expr(__is_constexpr(__builtin_strlen(p)), \ | ^~~~~~~~~~~~~~~~~~~~~ ./linux/arch/x86/purgatory/../boot/string.h:23:15: note: in expansion of macro ‘strlen’ 23 | extern size_t strlen(const char *s); | ^~~~~~ To avoid the problem, let's compile the whole code in the purgatory with -D__NO_FORTIFY, so can properly be included from headers like in the purgatory, too. When compiling/linking with the LLVM tools, and CONFIG_CFI=y, there is an additional problem during linking: ld.lld: error: undefined symbol: __memset >>> referenced by string.c >>> arch/x86/purgatory/purgatory.ro:(__UNIQUE_ID_addressable___memset_5) ld.lld: error: undefined symbol: __memmove >>> referenced by string.c >>> arch/x86/purgatory/purgatory.ro:(__UNIQUE_ID_addressable___memmove_6) This can be fixed by moving the -D__DISABLE_EXPORTS to the general CFLAGS of the purgatory, too. Signed-off-by: Thomas Huth Link: https://patch.msgid.link/20260928083055.104266-2-thuth@redhat.com Signed-off-by: Eric Biggers --- arch/x86/purgatory/Makefile | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/arch/x86/purgatory/Makefile b/arch/x86/purgatory/Makefile index 5ce1d4263000..fad91ea28fe7 100644 --- a/arch/x86/purgatory/Makefile +++ b/arch/x86/purgatory/Makefile @@ -11,8 +11,6 @@ $(obj)/string.o: $(srctree)/arch/x86/boot/compressed/string.c FORCE $(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 - # When profile-guided optimization is enabled, llvm emits two different # overlapping text sections, which is not supported by kexec. Remove profile # optimization flags. @@ -37,6 +35,7 @@ PURGATORY_CFLAGS := -mcmodel=small -ffreestanding -fno-zero-initialized-in-bss - PURGATORY_CFLAGS += -fpic -fvisibility=hidden PURGATORY_CFLAGS += $(DISABLE_KSTACK_ERASE) -DDISABLE_BRANCH_PROFILING PURGATORY_CFLAGS += -fno-stack-protector +PURGATORY_CFLAGS += -D__DISABLE_EXPORTS -D__NO_FORTIFY # Default KBUILD_CFLAGS can have -pg option set when FTRACE is enabled. That # in turn leaves some undefined symbols like __fentry__ in purgatory and not