blob: 08aa0f25f12a0fb92b7f9002740c50a1c0f2ad9d [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001# SPDX-License-Identifier: GPL-2.0
Josh Poimboeufc0dd6716862016-02-28 22:22:34 -06002OBJECT_FILES_NON_STANDARD := y
3
Vivek Goyal8fc5b4d2014-08-08 14:26:02 -07004purgatory-y := purgatory.o stack.o setup-x86_$(BITS).o sha256.o entry64.o string.o
5
6targets += $(purgatory-y)
7PURGATORY_OBJS = $(addprefix $(obj)/,$(purgatory-y))
8
Nick Desaulniers4ce97312019-08-07 15:15:32 -07009$(obj)/string.o: $(srctree)/arch/x86/boot/compressed/string.c FORCE
10 $(call if_changed_rule,cc_o_c)
11
Hans de Goedead767ee2019-08-17 16:24:31 +020012$(obj)/sha256.o: $(srctree)/lib/crypto/sha256.c FORCE
Philipp Rudodf6f2802018-04-13 15:36:46 -070013 $(call if_changed_rule,cc_o_c)
14
Kees Cook91218d72023-05-30 17:33:48 -070015CFLAGS_sha256.o := -D__DISABLE_EXPORTS -D__NO_FORTIFY
Hans de Goede01d3aee2019-08-17 16:24:33 +020016
Ricardo Ribalda97b6b9cb2023-05-19 16:47:37 +020017# When profile-guided optimization is enabled, llvm emits two different
18# overlapping text sections, which is not supported by kexec. Remove profile
19# optimization flags.
20KBUILD_CFLAGS := $(filter-out -fprofile-sample-use=% -fprofile-use=%,$(KBUILD_CFLAGS))
21
Song Liu75b2f7e2023-09-14 10:01:38 -070022# When LTO is enabled, llvm emits many text sections, which is not supported
23# by kexec. Remove -flto=* flags.
24KBUILD_CFLAGS := $(filter-out $(CC_FLAGS_LTO),$(KBUILD_CFLAGS))
25
Hans de Goedee4160b22020-03-17 14:08:41 +010026# When linking purgatory.ro with -r unresolved symbols are not checked,
27# also link a purgatory.chk binary without -r to check for unresolved symbols.
Masahiro Yamada9102fa32021-11-08 01:26:41 +090028PURGATORY_LDFLAGS := -e purgatory_start -z nodefaultlib
Hans de Goedee4160b22020-03-17 14:08:41 +010029LDFLAGS_purgatory.ro := -r $(PURGATORY_LDFLAGS)
30LDFLAGS_purgatory.chk := $(PURGATORY_LDFLAGS)
31targets += purgatory.ro purgatory.chk
Vivek Goyal8fc5b4d2014-08-08 14:26:02 -070032
Hans de Goedee2ac07c2020-03-17 14:08:40 +010033# Sanitizer, etc. runtimes are unavailable and cannot be linked here.
34GCOV_PROFILE := n
Mike Galbraith13a6798e2017-03-31 15:12:12 -070035KASAN_SANITIZE := n
Hans de Goedee2ac07c2020-03-17 14:08:40 +010036UBSAN_SANITIZE := n
Marco Elver40d04112019-11-14 19:03:03 +010037KCSAN_SANITIZE := n
Alexander Potapenko42855f52022-10-24 23:21:41 +020038KMSAN_SANITIZE := n
Emese Revfy543c37c2016-05-24 00:11:37 +020039KCOV_INSTRUMENT := n
40
Steve Wahle16c2982019-09-05 15:23:46 -050041# These are adjustments to the compiler flags used for objects that
42# make up the standalone purgatory.ro
43
44PURGATORY_CFLAGS_REMOVE := -mcmodel=kernel
Pingfan Liu52416ff2020-08-03 13:49:48 +080045PURGATORY_CFLAGS := -mcmodel=large -ffreestanding -fno-zero-initialized-in-bss -g0
Hans de Goedee2ac07c2020-03-17 14:08:40 +010046PURGATORY_CFLAGS += $(DISABLE_STACKLEAK_PLUGIN) -DDISABLE_BRANCH_PROFILING
Masahiro Yamada893ab0042020-06-27 03:59:12 +090047PURGATORY_CFLAGS += -fno-stack-protector
Steve Wahle16c2982019-09-05 15:23:46 -050048
Vivek Goyal8fc5b4d2014-08-08 14:26:02 -070049# Default KBUILD_CFLAGS can have -pg option set when FTRACE is enabled. That
50# in turn leaves some undefined symbols like __fentry__ in purgatory and not
Nick Desaulniersb059f802019-08-07 15:15:33 -070051# sure how to relocate those.
52ifdef CONFIG_FUNCTION_TRACER
Steve Wahle16c2982019-09-05 15:23:46 -050053PURGATORY_CFLAGS_REMOVE += $(CC_FLAGS_FTRACE)
Nick Desaulniersb059f802019-08-07 15:15:33 -070054endif
Vivek Goyal8fc5b4d2014-08-08 14:26:02 -070055
Nick Desaulniersb059f802019-08-07 15:15:33 -070056ifdef CONFIG_STACKPROTECTOR
Steve Wahle16c2982019-09-05 15:23:46 -050057PURGATORY_CFLAGS_REMOVE += -fstack-protector
Nick Desaulniersb059f802019-08-07 15:15:33 -070058endif
59
60ifdef CONFIG_STACKPROTECTOR_STRONG
Steve Wahle16c2982019-09-05 15:23:46 -050061PURGATORY_CFLAGS_REMOVE += -fstack-protector-strong
Nick Desaulniersb059f802019-08-07 15:15:33 -070062endif
63
64ifdef CONFIG_RETPOLINE
Steve Wahle16c2982019-09-05 15:23:46 -050065PURGATORY_CFLAGS_REMOVE += $(RETPOLINE_CFLAGS)
Nick Desaulniersb059f802019-08-07 15:15:33 -070066endif
Vivek Goyal8fc5b4d2014-08-08 14:26:02 -070067
Sami Tolvanena4b7a122022-09-08 14:55:03 -070068ifdef CONFIG_CFI_CLANG
69PURGATORY_CFLAGS_REMOVE += $(CC_FLAGS_CFI)
70endif
71
Steve Wahle16c2982019-09-05 15:23:46 -050072CFLAGS_REMOVE_purgatory.o += $(PURGATORY_CFLAGS_REMOVE)
73CFLAGS_purgatory.o += $(PURGATORY_CFLAGS)
74
75CFLAGS_REMOVE_sha256.o += $(PURGATORY_CFLAGS_REMOVE)
76CFLAGS_sha256.o += $(PURGATORY_CFLAGS)
77
78CFLAGS_REMOVE_string.o += $(PURGATORY_CFLAGS_REMOVE)
79CFLAGS_string.o += $(PURGATORY_CFLAGS)
80
Alyssa Rossd83806c2023-03-26 18:21:21 +000081asflags-remove-y += $(foreach x, -g -gdwarf-4 -gdwarf-5, $(x) -Wa,$(x))
Pingfan Liu52416ff2020-08-03 13:49:48 +080082
Vivek Goyal8fc5b4d2014-08-08 14:26:02 -070083$(obj)/purgatory.ro: $(PURGATORY_OBJS) FORCE
84 $(call if_changed,ld)
85
Hans de Goedee4160b22020-03-17 14:08:41 +010086$(obj)/purgatory.chk: $(obj)/purgatory.ro FORCE
87 $(call if_changed,ld)
88
Masahiro Yamada2d17bd22022-07-25 11:08:12 +090089$(obj)/kexec-purgatory.o: $(obj)/purgatory.ro $(obj)/purgatory.chk
Vivek Goyal8fc5b4d2014-08-08 14:26:02 -070090
Masahiro Yamada61922d32022-07-25 11:08:11 +090091obj-y += kexec-purgatory.o