1b2441318SGreg Kroah-Hartman# SPDX-License-Identifier: GPL-2.0 2c0dd6716SJosh Poimboeuf 38fc5b4d4SVivek Goyalpurgatory-y := purgatory.o stack.o setup-x86_$(BITS).o sha256.o entry64.o string.o 48fc5b4d4SVivek Goyal 58fc5b4d4SVivek Goyaltargets += $(purgatory-y) 68fc5b4d4SVivek GoyalPURGATORY_OBJS = $(addprefix $(obj)/,$(purgatory-y)) 78fc5b4d4SVivek Goyal 84ce97317SNick Desaulniers$(obj)/string.o: $(srctree)/arch/x86/boot/compressed/string.c FORCE 94ce97317SNick Desaulniers $(call if_changed_rule,cc_o_c) 104ce97317SNick Desaulniers 11ad767ee8SHans de Goede$(obj)/sha256.o: $(srctree)/lib/crypto/sha256.c FORCE 12df6f2801SPhilipp Rudo $(call if_changed_rule,cc_o_c) 13df6f2801SPhilipp Rudo 1491218d7dSKees CookCFLAGS_sha256.o := -D__DISABLE_EXPORTS -D__NO_FORTIFY 1501d3aee8SHans de Goede 1697b6b9cbSRicardo Ribalda# When profile-guided optimization is enabled, llvm emits two different 1797b6b9cbSRicardo Ribalda# overlapping text sections, which is not supported by kexec. Remove profile 1897b6b9cbSRicardo Ribalda# optimization flags. 1997b6b9cbSRicardo RibaldaKBUILD_CFLAGS := $(filter-out -fprofile-sample-use=% -fprofile-use=%,$(KBUILD_CFLAGS)) 2097b6b9cbSRicardo Ribalda 2175b2f7e4SSong Liu# When LTO is enabled, llvm emits many text sections, which is not supported 2275b2f7e4SSong Liu# by kexec. Remove -flto=* flags. 2375b2f7e4SSong LiuKBUILD_CFLAGS := $(filter-out $(CC_FLAGS_LTO),$(KBUILD_CFLAGS)) 2475b2f7e4SSong Liu 25e4160b2eSHans de Goede# When linking purgatory.ro with -r unresolved symbols are not checked, 26e4160b2eSHans de Goede# also link a purgatory.chk binary without -r to check for unresolved symbols. 279102fa34SMasahiro YamadaPURGATORY_LDFLAGS := -e purgatory_start -z nodefaultlib 28e4160b2eSHans de GoedeLDFLAGS_purgatory.ro := -r $(PURGATORY_LDFLAGS) 29e4160b2eSHans de GoedeLDFLAGS_purgatory.chk := $(PURGATORY_LDFLAGS) 30e4160b2eSHans de Goedetargets += purgatory.ro purgatory.chk 318fc5b4d4SVivek Goyal 32e16c2983SSteve Wahl# These are adjustments to the compiler flags used for objects that 33e16c2983SSteve Wahl# make up the standalone purgatory.ro 34e16c2983SSteve Wahl 35e16c2983SSteve WahlPURGATORY_CFLAGS_REMOVE := -mcmodel=kernel 36*cba786afSArd BiesheuvelPURGATORY_CFLAGS := -mcmodel=small -ffreestanding -fno-zero-initialized-in-bss -g0 37*cba786afSArd BiesheuvelPURGATORY_CFLAGS += -fpic -fvisibility=hidden 38e2ac07c0SHans de GoedePURGATORY_CFLAGS += $(DISABLE_STACKLEAK_PLUGIN) -DDISABLE_BRANCH_PROFILING 39893ab004SMasahiro YamadaPURGATORY_CFLAGS += -fno-stack-protector 40e16c2983SSteve Wahl 418fc5b4d4SVivek Goyal# Default KBUILD_CFLAGS can have -pg option set when FTRACE is enabled. That 428fc5b4d4SVivek Goyal# in turn leaves some undefined symbols like __fentry__ in purgatory and not 43b059f801SNick Desaulniers# sure how to relocate those. 44b059f801SNick Desaulniersifdef CONFIG_FUNCTION_TRACER 45e16c2983SSteve WahlPURGATORY_CFLAGS_REMOVE += $(CC_FLAGS_FTRACE) 46b059f801SNick Desaulniersendif 478fc5b4d4SVivek Goyal 48b059f801SNick Desaulniersifdef CONFIG_STACKPROTECTOR 49e16c2983SSteve WahlPURGATORY_CFLAGS_REMOVE += -fstack-protector 50b059f801SNick Desaulniersendif 51b059f801SNick Desaulniers 52b059f801SNick Desaulniersifdef CONFIG_STACKPROTECTOR_STRONG 53e16c2983SSteve WahlPURGATORY_CFLAGS_REMOVE += -fstack-protector-strong 54b059f801SNick Desaulniersendif 55b059f801SNick Desaulniers 56aefb2f2eSBreno Leitaoifdef CONFIG_MITIGATION_RETPOLINE 57e16c2983SSteve WahlPURGATORY_CFLAGS_REMOVE += $(RETPOLINE_CFLAGS) 58b059f801SNick Desaulniersendif 598fc5b4d4SVivek Goyal 60a4b7a12cSSami Tolvanenifdef CONFIG_CFI_CLANG 61a4b7a12cSSami TolvanenPURGATORY_CFLAGS_REMOVE += $(CC_FLAGS_CFI) 62a4b7a12cSSami Tolvanenendif 63a4b7a12cSSami Tolvanen 64e16c2983SSteve WahlCFLAGS_REMOVE_purgatory.o += $(PURGATORY_CFLAGS_REMOVE) 65e16c2983SSteve WahlCFLAGS_purgatory.o += $(PURGATORY_CFLAGS) 66e16c2983SSteve Wahl 67e16c2983SSteve WahlCFLAGS_REMOVE_sha256.o += $(PURGATORY_CFLAGS_REMOVE) 68e16c2983SSteve WahlCFLAGS_sha256.o += $(PURGATORY_CFLAGS) 69e16c2983SSteve Wahl 70e16c2983SSteve WahlCFLAGS_REMOVE_string.o += $(PURGATORY_CFLAGS_REMOVE) 71e16c2983SSteve WahlCFLAGS_string.o += $(PURGATORY_CFLAGS) 72e16c2983SSteve Wahl 73d83806c4SAlyssa Rossasflags-remove-y += $(foreach x, -g -gdwarf-4 -gdwarf-5, $(x) -Wa,$(x)) 7452416ffcSPingfan Liu 758fc5b4d4SVivek Goyal$(obj)/purgatory.ro: $(PURGATORY_OBJS) FORCE 768fc5b4d4SVivek Goyal $(call if_changed,ld) 778fc5b4d4SVivek Goyal 78e4160b2eSHans de Goede$(obj)/purgatory.chk: $(obj)/purgatory.ro FORCE 79e4160b2eSHans de Goede $(call if_changed,ld) 80e4160b2eSHans de Goede 812d17bd24SMasahiro Yamada$(obj)/kexec-purgatory.o: $(obj)/purgatory.ro $(obj)/purgatory.chk 828fc5b4d4SVivek Goyal 8361922d3fSMasahiro Yamadaobj-y += kexec-purgatory.o 84