162306a36Sopenharmony_ci# SPDX-License-Identifier: GPL-2.0 262306a36Sopenharmony_ciOBJECT_FILES_NON_STANDARD := y 362306a36Sopenharmony_ci 462306a36Sopenharmony_cipurgatory-y := purgatory.o stack.o setup-x86_$(BITS).o sha256.o entry64.o string.o 562306a36Sopenharmony_ci 662306a36Sopenharmony_citargets += $(purgatory-y) 762306a36Sopenharmony_ciPURGATORY_OBJS = $(addprefix $(obj)/,$(purgatory-y)) 862306a36Sopenharmony_ci 962306a36Sopenharmony_ci$(obj)/string.o: $(srctree)/arch/x86/boot/compressed/string.c FORCE 1062306a36Sopenharmony_ci $(call if_changed_rule,cc_o_c) 1162306a36Sopenharmony_ci 1262306a36Sopenharmony_ci$(obj)/sha256.o: $(srctree)/lib/crypto/sha256.c FORCE 1362306a36Sopenharmony_ci $(call if_changed_rule,cc_o_c) 1462306a36Sopenharmony_ci 1562306a36Sopenharmony_ciCFLAGS_sha256.o := -D__DISABLE_EXPORTS -D__NO_FORTIFY 1662306a36Sopenharmony_ci 1762306a36Sopenharmony_ci# When profile-guided optimization is enabled, llvm emits two different 1862306a36Sopenharmony_ci# overlapping text sections, which is not supported by kexec. Remove profile 1962306a36Sopenharmony_ci# optimization flags. 2062306a36Sopenharmony_ciKBUILD_CFLAGS := $(filter-out -fprofile-sample-use=% -fprofile-use=%,$(KBUILD_CFLAGS)) 2162306a36Sopenharmony_ci 2262306a36Sopenharmony_ci# When LTO is enabled, llvm emits many text sections, which is not supported 2362306a36Sopenharmony_ci# by kexec. Remove -flto=* flags. 2462306a36Sopenharmony_ciKBUILD_CFLAGS := $(filter-out $(CC_FLAGS_LTO),$(KBUILD_CFLAGS)) 2562306a36Sopenharmony_ci 2662306a36Sopenharmony_ci# When linking purgatory.ro with -r unresolved symbols are not checked, 2762306a36Sopenharmony_ci# also link a purgatory.chk binary without -r to check for unresolved symbols. 2862306a36Sopenharmony_ciPURGATORY_LDFLAGS := -e purgatory_start -z nodefaultlib 2962306a36Sopenharmony_ciLDFLAGS_purgatory.ro := -r $(PURGATORY_LDFLAGS) 3062306a36Sopenharmony_ciLDFLAGS_purgatory.chk := $(PURGATORY_LDFLAGS) 3162306a36Sopenharmony_citargets += purgatory.ro purgatory.chk 3262306a36Sopenharmony_ci 3362306a36Sopenharmony_ci# Sanitizer, etc. runtimes are unavailable and cannot be linked here. 3462306a36Sopenharmony_ciGCOV_PROFILE := n 3562306a36Sopenharmony_ciKASAN_SANITIZE := n 3662306a36Sopenharmony_ciUBSAN_SANITIZE := n 3762306a36Sopenharmony_ciKCSAN_SANITIZE := n 3862306a36Sopenharmony_ciKMSAN_SANITIZE := n 3962306a36Sopenharmony_ciKCOV_INSTRUMENT := n 4062306a36Sopenharmony_ci 4162306a36Sopenharmony_ci# These are adjustments to the compiler flags used for objects that 4262306a36Sopenharmony_ci# make up the standalone purgatory.ro 4362306a36Sopenharmony_ci 4462306a36Sopenharmony_ciPURGATORY_CFLAGS_REMOVE := -mcmodel=kernel 4562306a36Sopenharmony_ciPURGATORY_CFLAGS := -mcmodel=large -ffreestanding -fno-zero-initialized-in-bss -g0 4662306a36Sopenharmony_ciPURGATORY_CFLAGS += $(DISABLE_STACKLEAK_PLUGIN) -DDISABLE_BRANCH_PROFILING 4762306a36Sopenharmony_ciPURGATORY_CFLAGS += -fno-stack-protector 4862306a36Sopenharmony_ci 4962306a36Sopenharmony_ci# Default KBUILD_CFLAGS can have -pg option set when FTRACE is enabled. That 5062306a36Sopenharmony_ci# in turn leaves some undefined symbols like __fentry__ in purgatory and not 5162306a36Sopenharmony_ci# sure how to relocate those. 5262306a36Sopenharmony_ciifdef CONFIG_FUNCTION_TRACER 5362306a36Sopenharmony_ciPURGATORY_CFLAGS_REMOVE += $(CC_FLAGS_FTRACE) 5462306a36Sopenharmony_ciendif 5562306a36Sopenharmony_ci 5662306a36Sopenharmony_ciifdef CONFIG_STACKPROTECTOR 5762306a36Sopenharmony_ciPURGATORY_CFLAGS_REMOVE += -fstack-protector 5862306a36Sopenharmony_ciendif 5962306a36Sopenharmony_ci 6062306a36Sopenharmony_ciifdef CONFIG_STACKPROTECTOR_STRONG 6162306a36Sopenharmony_ciPURGATORY_CFLAGS_REMOVE += -fstack-protector-strong 6262306a36Sopenharmony_ciendif 6362306a36Sopenharmony_ci 6462306a36Sopenharmony_ciifdef CONFIG_RETPOLINE 6562306a36Sopenharmony_ciPURGATORY_CFLAGS_REMOVE += $(RETPOLINE_CFLAGS) 6662306a36Sopenharmony_ciendif 6762306a36Sopenharmony_ci 6862306a36Sopenharmony_ciifdef CONFIG_CFI_CLANG 6962306a36Sopenharmony_ciPURGATORY_CFLAGS_REMOVE += $(CC_FLAGS_CFI) 7062306a36Sopenharmony_ciendif 7162306a36Sopenharmony_ci 7262306a36Sopenharmony_ciCFLAGS_REMOVE_purgatory.o += $(PURGATORY_CFLAGS_REMOVE) 7362306a36Sopenharmony_ciCFLAGS_purgatory.o += $(PURGATORY_CFLAGS) 7462306a36Sopenharmony_ci 7562306a36Sopenharmony_ciCFLAGS_REMOVE_sha256.o += $(PURGATORY_CFLAGS_REMOVE) 7662306a36Sopenharmony_ciCFLAGS_sha256.o += $(PURGATORY_CFLAGS) 7762306a36Sopenharmony_ci 7862306a36Sopenharmony_ciCFLAGS_REMOVE_string.o += $(PURGATORY_CFLAGS_REMOVE) 7962306a36Sopenharmony_ciCFLAGS_string.o += $(PURGATORY_CFLAGS) 8062306a36Sopenharmony_ci 8162306a36Sopenharmony_ciasflags-remove-y += $(foreach x, -g -gdwarf-4 -gdwarf-5, $(x) -Wa,$(x)) 8262306a36Sopenharmony_ci 8362306a36Sopenharmony_ci$(obj)/purgatory.ro: $(PURGATORY_OBJS) FORCE 8462306a36Sopenharmony_ci $(call if_changed,ld) 8562306a36Sopenharmony_ci 8662306a36Sopenharmony_ci$(obj)/purgatory.chk: $(obj)/purgatory.ro FORCE 8762306a36Sopenharmony_ci $(call if_changed,ld) 8862306a36Sopenharmony_ci 8962306a36Sopenharmony_ci$(obj)/kexec-purgatory.o: $(obj)/purgatory.ro $(obj)/purgatory.chk 9062306a36Sopenharmony_ci 9162306a36Sopenharmony_ciobj-y += kexec-purgatory.o 92