1b2441318SGreg Kroah-Hartman# SPDX-License-Identifier: GPL-2.0 2c0dd6716SJosh PoimboeufOBJECT_FILES_NON_STANDARD := y 3c0dd6716SJosh Poimboeuf 48fc5b4d4SVivek Goyalpurgatory-y := purgatory.o stack.o setup-x86_$(BITS).o sha256.o entry64.o string.o 58fc5b4d4SVivek Goyal 68fc5b4d4SVivek Goyaltargets += $(purgatory-y) 78fc5b4d4SVivek GoyalPURGATORY_OBJS = $(addprefix $(obj)/,$(purgatory-y)) 88fc5b4d4SVivek Goyal 94ce97317SNick Desaulniers$(obj)/string.o: $(srctree)/arch/x86/boot/compressed/string.c FORCE 104ce97317SNick Desaulniers $(call if_changed_rule,cc_o_c) 114ce97317SNick Desaulniers 12ad767ee8SHans de Goede$(obj)/sha256.o: $(srctree)/lib/crypto/sha256.c FORCE 13df6f2801SPhilipp Rudo $(call if_changed_rule,cc_o_c) 14df6f2801SPhilipp Rudo 1591218d7dSKees CookCFLAGS_sha256.o := -D__DISABLE_EXPORTS -D__NO_FORTIFY 1601d3aee8SHans de Goede 1797b6b9cbSRicardo Ribalda# When profile-guided optimization is enabled, llvm emits two different 1897b6b9cbSRicardo Ribalda# overlapping text sections, which is not supported by kexec. Remove profile 1997b6b9cbSRicardo Ribalda# optimization flags. 2097b6b9cbSRicardo RibaldaKBUILD_CFLAGS := $(filter-out -fprofile-sample-use=% -fprofile-use=%,$(KBUILD_CFLAGS)) 2197b6b9cbSRicardo Ribalda 2275b2f7e4SSong Liu# When LTO is enabled, llvm emits many text sections, which is not supported 2375b2f7e4SSong Liu# by kexec. Remove -flto=* flags. 2475b2f7e4SSong LiuKBUILD_CFLAGS := $(filter-out $(CC_FLAGS_LTO),$(KBUILD_CFLAGS)) 2575b2f7e4SSong Liu 26e4160b2eSHans de Goede# When linking purgatory.ro with -r unresolved symbols are not checked, 27e4160b2eSHans de Goede# also link a purgatory.chk binary without -r to check for unresolved symbols. 289102fa34SMasahiro YamadaPURGATORY_LDFLAGS := -e purgatory_start -z nodefaultlib 29e4160b2eSHans de GoedeLDFLAGS_purgatory.ro := -r $(PURGATORY_LDFLAGS) 30e4160b2eSHans de GoedeLDFLAGS_purgatory.chk := $(PURGATORY_LDFLAGS) 31e4160b2eSHans de Goedetargets += purgatory.ro purgatory.chk 328fc5b4d4SVivek Goyal 33e2ac07c0SHans de Goede# Sanitizer, etc. runtimes are unavailable and cannot be linked here. 34e2ac07c0SHans de GoedeGCOV_PROFILE := n 3513a6798eSMike GalbraithKASAN_SANITIZE := n 36e2ac07c0SHans de GoedeUBSAN_SANITIZE := n 3740d04110SMarco ElverKCSAN_SANITIZE := n 3842855f58SAlexander PotapenkoKMSAN_SANITIZE := n 39543c37cbSEmese RevfyKCOV_INSTRUMENT := n 40543c37cbSEmese Revfy 41e16c2983SSteve Wahl# These are adjustments to the compiler flags used for objects that 42e16c2983SSteve Wahl# make up the standalone purgatory.ro 43e16c2983SSteve Wahl 44e16c2983SSteve WahlPURGATORY_CFLAGS_REMOVE := -mcmodel=kernel 4552416ffcSPingfan LiuPURGATORY_CFLAGS := -mcmodel=large -ffreestanding -fno-zero-initialized-in-bss -g0 46e2ac07c0SHans de GoedePURGATORY_CFLAGS += $(DISABLE_STACKLEAK_PLUGIN) -DDISABLE_BRANCH_PROFILING 47893ab004SMasahiro YamadaPURGATORY_CFLAGS += -fno-stack-protector 48e16c2983SSteve Wahl 498fc5b4d4SVivek Goyal# Default KBUILD_CFLAGS can have -pg option set when FTRACE is enabled. That 508fc5b4d4SVivek Goyal# in turn leaves some undefined symbols like __fentry__ in purgatory and not 51b059f801SNick Desaulniers# sure how to relocate those. 52b059f801SNick Desaulniersifdef CONFIG_FUNCTION_TRACER 53e16c2983SSteve WahlPURGATORY_CFLAGS_REMOVE += $(CC_FLAGS_FTRACE) 54b059f801SNick Desaulniersendif 558fc5b4d4SVivek Goyal 56b059f801SNick Desaulniersifdef CONFIG_STACKPROTECTOR 57e16c2983SSteve WahlPURGATORY_CFLAGS_REMOVE += -fstack-protector 58b059f801SNick Desaulniersendif 59b059f801SNick Desaulniers 60b059f801SNick Desaulniersifdef CONFIG_STACKPROTECTOR_STRONG 61e16c2983SSteve WahlPURGATORY_CFLAGS_REMOVE += -fstack-protector-strong 62b059f801SNick Desaulniersendif 63b059f801SNick Desaulniers 64*aefb2f2eSBreno Leitaoifdef CONFIG_MITIGATION_RETPOLINE 65e16c2983SSteve WahlPURGATORY_CFLAGS_REMOVE += $(RETPOLINE_CFLAGS) 66b059f801SNick Desaulniersendif 678fc5b4d4SVivek Goyal 68a4b7a12cSSami Tolvanenifdef CONFIG_CFI_CLANG 69a4b7a12cSSami TolvanenPURGATORY_CFLAGS_REMOVE += $(CC_FLAGS_CFI) 70a4b7a12cSSami Tolvanenendif 71a4b7a12cSSami Tolvanen 72e16c2983SSteve WahlCFLAGS_REMOVE_purgatory.o += $(PURGATORY_CFLAGS_REMOVE) 73e16c2983SSteve WahlCFLAGS_purgatory.o += $(PURGATORY_CFLAGS) 74e16c2983SSteve Wahl 75e16c2983SSteve WahlCFLAGS_REMOVE_sha256.o += $(PURGATORY_CFLAGS_REMOVE) 76e16c2983SSteve WahlCFLAGS_sha256.o += $(PURGATORY_CFLAGS) 77e16c2983SSteve Wahl 78e16c2983SSteve WahlCFLAGS_REMOVE_string.o += $(PURGATORY_CFLAGS_REMOVE) 79e16c2983SSteve WahlCFLAGS_string.o += $(PURGATORY_CFLAGS) 80e16c2983SSteve Wahl 81d83806c4SAlyssa Rossasflags-remove-y += $(foreach x, -g -gdwarf-4 -gdwarf-5, $(x) -Wa,$(x)) 8252416ffcSPingfan Liu 838fc5b4d4SVivek Goyal$(obj)/purgatory.ro: $(PURGATORY_OBJS) FORCE 848fc5b4d4SVivek Goyal $(call if_changed,ld) 858fc5b4d4SVivek Goyal 86e4160b2eSHans de Goede$(obj)/purgatory.chk: $(obj)/purgatory.ro FORCE 87e4160b2eSHans de Goede $(call if_changed,ld) 88e4160b2eSHans de Goede 892d17bd24SMasahiro Yamada$(obj)/kexec-purgatory.o: $(obj)/purgatory.ro $(obj)/purgatory.chk 908fc5b4d4SVivek Goyal 9161922d3fSMasahiro Yamadaobj-y += kexec-purgatory.o 92