1# SPDX-License-Identifier: GPL-2.0 2 3purgatory-y := purgatory.o sha256.o entry.o string.o ctype.o memcpy.o memset.o 4ifeq ($(CONFIG_KASAN_GENERIC)$(CONFIG_KASAN_SW_TAGS),) 5purgatory-y += strcmp.o strlen.o strncmp.o 6endif 7 8targets += $(purgatory-y) 9PURGATORY_OBJS = $(addprefix $(obj)/,$(purgatory-y)) 10 11$(obj)/string.o: $(srctree)/lib/string.c FORCE 12 $(call if_changed_rule,cc_o_c) 13 14$(obj)/ctype.o: $(srctree)/lib/ctype.c FORCE 15 $(call if_changed_rule,cc_o_c) 16 17$(obj)/memcpy.o: $(srctree)/arch/riscv/lib/memcpy.S FORCE 18 $(call if_changed_rule,as_o_S) 19 20$(obj)/memset.o: $(srctree)/arch/riscv/lib/memset.S FORCE 21 $(call if_changed_rule,as_o_S) 22 23$(obj)/strcmp.o: $(srctree)/arch/riscv/lib/strcmp.S FORCE 24 $(call if_changed_rule,as_o_S) 25 26$(obj)/strlen.o: $(srctree)/arch/riscv/lib/strlen.S FORCE 27 $(call if_changed_rule,as_o_S) 28 29$(obj)/strncmp.o: $(srctree)/arch/riscv/lib/strncmp.S FORCE 30 $(call if_changed_rule,as_o_S) 31 32$(obj)/sha256.o: $(srctree)/lib/crypto/sha256.c FORCE 33 $(call if_changed_rule,cc_o_c) 34 35CFLAGS_sha256.o := -D__DISABLE_EXPORTS -D__NO_FORTIFY 36CFLAGS_string.o := -D__DISABLE_EXPORTS 37CFLAGS_ctype.o := -D__DISABLE_EXPORTS 38 39# When profile-guided optimization is enabled, llvm emits two different 40# overlapping text sections, which is not supported by kexec. Remove profile 41# optimization flags. 42KBUILD_CFLAGS := $(filter-out -fprofile-sample-use=% -fprofile-use=%,$(KBUILD_CFLAGS)) 43 44# When linking purgatory.ro with -r unresolved symbols are not checked, 45# also link a purgatory.chk binary without -r to check for unresolved symbols. 46PURGATORY_LDFLAGS := -e purgatory_start -z nodefaultlib 47LDFLAGS_purgatory.ro := -r $(PURGATORY_LDFLAGS) 48LDFLAGS_purgatory.chk := $(PURGATORY_LDFLAGS) 49targets += purgatory.ro purgatory.chk 50 51# These are adjustments to the compiler flags used for objects that 52# make up the standalone purgatory.ro 53 54PURGATORY_CFLAGS_REMOVE := -mcmodel=kernel 55PURGATORY_CFLAGS := -mcmodel=medany -ffreestanding -fno-zero-initialized-in-bss 56PURGATORY_CFLAGS += $(DISABLE_STACKLEAK_PLUGIN) -DDISABLE_BRANCH_PROFILING 57PURGATORY_CFLAGS += -fno-stack-protector -g0 58 59# Default KBUILD_CFLAGS can have -pg option set when FTRACE is enabled. That 60# in turn leaves some undefined symbols like __fentry__ in purgatory and not 61# sure how to relocate those. 62ifdef CONFIG_FUNCTION_TRACER 63PURGATORY_CFLAGS_REMOVE += $(CC_FLAGS_FTRACE) 64endif 65 66ifdef CONFIG_STACKPROTECTOR 67PURGATORY_CFLAGS_REMOVE += -fstack-protector 68endif 69 70ifdef CONFIG_STACKPROTECTOR_STRONG 71PURGATORY_CFLAGS_REMOVE += -fstack-protector-strong 72endif 73 74ifdef CONFIG_CFI_CLANG 75PURGATORY_CFLAGS_REMOVE += $(CC_FLAGS_CFI) 76endif 77 78ifdef CONFIG_RELOCATABLE 79PURGATORY_CFLAGS_REMOVE += -fPIE 80endif 81 82ifdef CONFIG_SHADOW_CALL_STACK 83PURGATORY_CFLAGS_REMOVE += $(CC_FLAGS_SCS) 84endif 85 86CFLAGS_REMOVE_purgatory.o += $(PURGATORY_CFLAGS_REMOVE) 87CFLAGS_purgatory.o += $(PURGATORY_CFLAGS) 88 89CFLAGS_REMOVE_sha256.o += $(PURGATORY_CFLAGS_REMOVE) 90CFLAGS_sha256.o += $(PURGATORY_CFLAGS) 91 92CFLAGS_REMOVE_string.o += $(PURGATORY_CFLAGS_REMOVE) 93CFLAGS_string.o += $(PURGATORY_CFLAGS) 94 95CFLAGS_REMOVE_ctype.o += $(PURGATORY_CFLAGS_REMOVE) 96CFLAGS_ctype.o += $(PURGATORY_CFLAGS) 97 98asflags-remove-y += $(foreach x, -g -gdwarf-4 -gdwarf-5, $(x) -Wa,$(x)) 99 100$(obj)/purgatory.ro: $(PURGATORY_OBJS) FORCE 101 $(call if_changed,ld) 102 103$(obj)/purgatory.chk: $(obj)/purgatory.ro FORCE 104 $(call if_changed,ld) 105 106$(obj)/kexec-purgatory.o: $(obj)/purgatory.ro $(obj)/purgatory.chk 107 108obj-y += kexec-purgatory.o 109