Skip to content

Commit b059f80

Browse files
nickdesaulniersKAGA-KOKO
authored andcommitted
x86/purgatory: Use CFLAGS_REMOVE rather than reset KBUILD_CFLAGS
KBUILD_CFLAGS is very carefully built up in the top level Makefile, particularly when cross compiling or using different build tools. Resetting KBUILD_CFLAGS via := assignment is an antipattern. The comment above the reset mentions that -pg is problematic. Other Makefiles use `CFLAGS_REMOVE_file.o = $(CC_FLAGS_FTRACE)` when CONFIG_FUNCTION_TRACER is set. Prefer that pattern to wiping out all of the important KBUILD_CFLAGS then manually having to re-add them. Seems also that __stack_chk_fail references are generated when using CONFIG_STACKPROTECTOR or CONFIG_STACKPROTECTOR_STRONG. Fixes: 8fc5b4d ("purgatory: core purgatory functionality") Reported-by: Vaibhav Rustagi <[email protected]> Suggested-by: Peter Zijlstra <[email protected]> Suggested-by: Thomas Gleixner <[email protected]> Signed-off-by: Nick Desaulniers <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]> Tested-by: Vaibhav Rustagi <[email protected]> Cc: [email protected] Link: https://lkml.kernel.org/r/[email protected]
1 parent 4ce9731 commit b059f80

File tree

1 file changed

+28
-5
lines changed

1 file changed

+28
-5
lines changed

arch/x86/purgatory/Makefile

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,34 @@ KCOV_INSTRUMENT := n
2020

2121
# Default KBUILD_CFLAGS can have -pg option set when FTRACE is enabled. That
2222
# in turn leaves some undefined symbols like __fentry__ in purgatory and not
23-
# sure how to relocate those. Like kexec-tools, use custom flags.
24-
25-
KBUILD_CFLAGS := -fno-strict-aliasing -Wall -Wstrict-prototypes -fno-zero-initialized-in-bss -fno-builtin -ffreestanding -c -Os -mcmodel=large
26-
KBUILD_CFLAGS += -m$(BITS)
27-
KBUILD_CFLAGS += $(call cc-option,-fno-PIE)
23+
# sure how to relocate those.
24+
ifdef CONFIG_FUNCTION_TRACER
25+
CFLAGS_REMOVE_sha256.o += $(CC_FLAGS_FTRACE)
26+
CFLAGS_REMOVE_purgatory.o += $(CC_FLAGS_FTRACE)
27+
CFLAGS_REMOVE_string.o += $(CC_FLAGS_FTRACE)
28+
CFLAGS_REMOVE_kexec-purgatory.o += $(CC_FLAGS_FTRACE)
29+
endif
30+
31+
ifdef CONFIG_STACKPROTECTOR
32+
CFLAGS_REMOVE_sha256.o += -fstack-protector
33+
CFLAGS_REMOVE_purgatory.o += -fstack-protector
34+
CFLAGS_REMOVE_string.o += -fstack-protector
35+
CFLAGS_REMOVE_kexec-purgatory.o += -fstack-protector
36+
endif
37+
38+
ifdef CONFIG_STACKPROTECTOR_STRONG
39+
CFLAGS_REMOVE_sha256.o += -fstack-protector-strong
40+
CFLAGS_REMOVE_purgatory.o += -fstack-protector-strong
41+
CFLAGS_REMOVE_string.o += -fstack-protector-strong
42+
CFLAGS_REMOVE_kexec-purgatory.o += -fstack-protector-strong
43+
endif
44+
45+
ifdef CONFIG_RETPOLINE
46+
CFLAGS_REMOVE_sha256.o += $(RETPOLINE_CFLAGS)
47+
CFLAGS_REMOVE_purgatory.o += $(RETPOLINE_CFLAGS)
48+
CFLAGS_REMOVE_string.o += $(RETPOLINE_CFLAGS)
49+
CFLAGS_REMOVE_kexec-purgatory.o += $(RETPOLINE_CFLAGS)
50+
endif
2851

2952
$(obj)/purgatory.ro: $(PURGATORY_OBJS) FORCE
3053
$(call if_changed,ld)

0 commit comments

Comments
 (0)