[PATCH v4 10/13] x86/purgatory: Compile purgatory with -D__NO_FORTIFY
From: Thomas Huth
Date: Wed Sep 16 2026 - 06:09:06 EST
A subsequent patch will add #include <linux/string.h> to <crypto/sha2.h>
to use memzero_explicit() there. This will introduce a conflict with the
purgatory code: purgatory.c includes both, the <crypto/sha2.h> 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 <linux/string.h>, 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 code in the purgatory with
-D__NO_FORTIFY, so <linux/string.h> can properly be included from
headers like <crypto/sha2.h> in the purgatory, too.
Signed-off-by: Thomas Huth <thuth@xxxxxxxxxx>
---
arch/x86/purgatory/Makefile | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/arch/x86/purgatory/Makefile b/arch/x86/purgatory/Makefile
index 5ce1d42630000..cde8463b4d841 100644
--- a/arch/x86/purgatory/Makefile
+++ b/arch/x86/purgatory/Makefile
@@ -11,7 +11,7 @@ $(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
+CFLAGS_sha256.o := -D__DISABLE_EXPORTS
# When profile-guided optimization is enabled, llvm emits two different
# overlapping text sections, which is not supported by kexec. Remove profile
@@ -37,6 +37,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__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
--
2.55.0