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 45*cba786afSArd BiesheuvelPURGATORY_CFLAGS := -mcmodel=small -ffreestanding -fno-zero-initialized-in-bss -g0 46*cba786afSArd BiesheuvelPURGATORY_CFLAGS += -fpic -fvisibility=hidden 47e2ac07c0SHans de GoedePURGATORY_CFLAGS += $(DISABLE_STACKLEAK_PLUGIN) -DDISABLE_BRANCH_PROFILING 48893ab004SMasahiro YamadaPURGATORY_CFLAGS += -fno-stack-protector 49e16c2983SSteve Wahl 508fc5b4d4SVivek Goyal# Default KBUILD_CFLAGS can have -pg option set when FTRACE is enabled. That 518fc5b4d4SVivek Goyal# in turn leaves some undefined symbols like __fentry__ in purgatory and not 52b059f801SNick Desaulniers# sure how to relocate those. 53b059f801SNick Desaulniersifdef CONFIG_FUNCTION_TRACER 54e16c2983SSteve WahlPURGATORY_CFLAGS_REMOVE += $(CC_FLAGS_FTRACE) 55b059f801SNick Desaulniersendif 568fc5b4d4SVivek Goyal 57b059f801SNick Desaulniersifdef CONFIG_STACKPROTECTOR 58e16c2983SSteve WahlPURGATORY_CFLAGS_REMOVE += -fstack-protector 59b059f801SNick Desaulniersendif 60b059f801SNick Desaulniers 61b059f801SNick Desaulniersifdef CONFIG_STACKPROTECTOR_STRONG 62e16c2983SSteve WahlPURGATORY_CFLAGS_REMOVE += -fstack-protector-strong 63b059f801SNick Desaulniersendif 64b059f801SNick Desaulniers 65aefb2f2eSBreno Leitaoifdef CONFIG_MITIGATION_RETPOLINE 66e16c2983SSteve WahlPURGATORY_CFLAGS_REMOVE += $(RETPOLINE_CFLAGS) 67b059f801SNick Desaulniersendif 688fc5b4d4SVivek Goyal 69a4b7a12cSSami Tolvanenifdef CONFIG_CFI_CLANG 70a4b7a12cSSami TolvanenPURGATORY_CFLAGS_REMOVE += $(CC_FLAGS_CFI) 71a4b7a12cSSami Tolvanenendif 72a4b7a12cSSami Tolvanen 73e16c2983SSteve WahlCFLAGS_REMOVE_purgatory.o += $(PURGATORY_CFLAGS_REMOVE) 74e16c2983SSteve WahlCFLAGS_purgatory.o += $(PURGATORY_CFLAGS) 75e16c2983SSteve Wahl 76e16c2983SSteve WahlCFLAGS_REMOVE_sha256.o += $(PURGATORY_CFLAGS_REMOVE) 77e16c2983SSteve WahlCFLAGS_sha256.o += $(PURGATORY_CFLAGS) 78e16c2983SSteve Wahl 79e16c2983SSteve WahlCFLAGS_REMOVE_string.o += $(PURGATORY_CFLAGS_REMOVE) 80e16c2983SSteve WahlCFLAGS_string.o += $(PURGATORY_CFLAGS) 81e16c2983SSteve Wahl 82d83806c4SAlyssa Rossasflags-remove-y += $(foreach x, -g -gdwarf-4 -gdwarf-5, $(x) -Wa,$(x)) 8352416ffcSPingfan Liu 848fc5b4d4SVivek Goyal$(obj)/purgatory.ro: $(PURGATORY_OBJS) FORCE 858fc5b4d4SVivek Goyal $(call if_changed,ld) 868fc5b4d4SVivek Goyal 87e4160b2eSHans de Goede$(obj)/purgatory.chk: $(obj)/purgatory.ro FORCE 88e4160b2eSHans de Goede $(call if_changed,ld) 89e4160b2eSHans de Goede 902d17bd24SMasahiro Yamada$(obj)/kexec-purgatory.o: $(obj)/purgatory.ro $(obj)/purgatory.chk 918fc5b4d4SVivek Goyal 9261922d3fSMasahiro Yamadaobj-y += kexec-purgatory.o 93