Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | # SPDX-License-Identifier: GPL-2.0 |
Josh Poimboeuf | c0dd671686 | 2016-02-28 22:22:34 -0600 | [diff] [blame] | 2 | OBJECT_FILES_NON_STANDARD := y |
| 3 | |
Vivek Goyal | 8fc5b4d | 2014-08-08 14:26:02 -0700 | [diff] [blame] | 4 | purgatory-y := purgatory.o stack.o setup-x86_$(BITS).o sha256.o entry64.o string.o |
| 5 | |
| 6 | targets += $(purgatory-y) |
| 7 | PURGATORY_OBJS = $(addprefix $(obj)/,$(purgatory-y)) |
| 8 | |
Nick Desaulniers | 4ce9731 | 2019-08-07 15:15:32 -0700 | [diff] [blame] | 9 | $(obj)/string.o: $(srctree)/arch/x86/boot/compressed/string.c FORCE |
| 10 | $(call if_changed_rule,cc_o_c) |
| 11 | |
Hans de Goede | ad767ee | 2019-08-17 16:24:31 +0200 | [diff] [blame] | 12 | $(obj)/sha256.o: $(srctree)/lib/crypto/sha256.c FORCE |
Philipp Rudo | df6f280 | 2018-04-13 15:36:46 -0700 | [diff] [blame] | 13 | $(call if_changed_rule,cc_o_c) |
| 14 | |
Kees Cook | 91218d7 | 2023-05-30 17:33:48 -0700 | [diff] [blame] | 15 | CFLAGS_sha256.o := -D__DISABLE_EXPORTS -D__NO_FORTIFY |
Hans de Goede | 01d3aee | 2019-08-17 16:24:33 +0200 | [diff] [blame] | 16 | |
Ricardo Ribalda | 97b6b9cb | 2023-05-19 16:47:37 +0200 | [diff] [blame] | 17 | # 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. |
| 20 | KBUILD_CFLAGS := $(filter-out -fprofile-sample-use=% -fprofile-use=%,$(KBUILD_CFLAGS)) |
| 21 | |
Song Liu | 75b2f7e | 2023-09-14 10:01:38 -0700 | [diff] [blame] | 22 | # When LTO is enabled, llvm emits many text sections, which is not supported |
| 23 | # by kexec. Remove -flto=* flags. |
| 24 | KBUILD_CFLAGS := $(filter-out $(CC_FLAGS_LTO),$(KBUILD_CFLAGS)) |
| 25 | |
Hans de Goede | e4160b2 | 2020-03-17 14:08:41 +0100 | [diff] [blame] | 26 | # 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 Yamada | 9102fa3 | 2021-11-08 01:26:41 +0900 | [diff] [blame] | 28 | PURGATORY_LDFLAGS := -e purgatory_start -z nodefaultlib |
Hans de Goede | e4160b2 | 2020-03-17 14:08:41 +0100 | [diff] [blame] | 29 | LDFLAGS_purgatory.ro := -r $(PURGATORY_LDFLAGS) |
| 30 | LDFLAGS_purgatory.chk := $(PURGATORY_LDFLAGS) |
| 31 | targets += purgatory.ro purgatory.chk |
Vivek Goyal | 8fc5b4d | 2014-08-08 14:26:02 -0700 | [diff] [blame] | 32 | |
Hans de Goede | e2ac07c | 2020-03-17 14:08:40 +0100 | [diff] [blame] | 33 | # Sanitizer, etc. runtimes are unavailable and cannot be linked here. |
| 34 | GCOV_PROFILE := n |
Mike Galbraith | 13a6798e | 2017-03-31 15:12:12 -0700 | [diff] [blame] | 35 | KASAN_SANITIZE := n |
Hans de Goede | e2ac07c | 2020-03-17 14:08:40 +0100 | [diff] [blame] | 36 | UBSAN_SANITIZE := n |
Marco Elver | 40d0411 | 2019-11-14 19:03:03 +0100 | [diff] [blame] | 37 | KCSAN_SANITIZE := n |
Alexander Potapenko | 42855f5 | 2022-10-24 23:21:41 +0200 | [diff] [blame] | 38 | KMSAN_SANITIZE := n |
Emese Revfy | 543c37c | 2016-05-24 00:11:37 +0200 | [diff] [blame] | 39 | KCOV_INSTRUMENT := n |
| 40 | |
Steve Wahl | e16c298 | 2019-09-05 15:23:46 -0500 | [diff] [blame] | 41 | # These are adjustments to the compiler flags used for objects that |
| 42 | # make up the standalone purgatory.ro |
| 43 | |
| 44 | PURGATORY_CFLAGS_REMOVE := -mcmodel=kernel |
Pingfan Liu | 52416ff | 2020-08-03 13:49:48 +0800 | [diff] [blame] | 45 | PURGATORY_CFLAGS := -mcmodel=large -ffreestanding -fno-zero-initialized-in-bss -g0 |
Hans de Goede | e2ac07c | 2020-03-17 14:08:40 +0100 | [diff] [blame] | 46 | PURGATORY_CFLAGS += $(DISABLE_STACKLEAK_PLUGIN) -DDISABLE_BRANCH_PROFILING |
Masahiro Yamada | 893ab004 | 2020-06-27 03:59:12 +0900 | [diff] [blame] | 47 | PURGATORY_CFLAGS += -fno-stack-protector |
Steve Wahl | e16c298 | 2019-09-05 15:23:46 -0500 | [diff] [blame] | 48 | |
Vivek Goyal | 8fc5b4d | 2014-08-08 14:26:02 -0700 | [diff] [blame] | 49 | # 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 Desaulniers | b059f80 | 2019-08-07 15:15:33 -0700 | [diff] [blame] | 51 | # sure how to relocate those. |
| 52 | ifdef CONFIG_FUNCTION_TRACER |
Steve Wahl | e16c298 | 2019-09-05 15:23:46 -0500 | [diff] [blame] | 53 | PURGATORY_CFLAGS_REMOVE += $(CC_FLAGS_FTRACE) |
Nick Desaulniers | b059f80 | 2019-08-07 15:15:33 -0700 | [diff] [blame] | 54 | endif |
Vivek Goyal | 8fc5b4d | 2014-08-08 14:26:02 -0700 | [diff] [blame] | 55 | |
Nick Desaulniers | b059f80 | 2019-08-07 15:15:33 -0700 | [diff] [blame] | 56 | ifdef CONFIG_STACKPROTECTOR |
Steve Wahl | e16c298 | 2019-09-05 15:23:46 -0500 | [diff] [blame] | 57 | PURGATORY_CFLAGS_REMOVE += -fstack-protector |
Nick Desaulniers | b059f80 | 2019-08-07 15:15:33 -0700 | [diff] [blame] | 58 | endif |
| 59 | |
| 60 | ifdef CONFIG_STACKPROTECTOR_STRONG |
Steve Wahl | e16c298 | 2019-09-05 15:23:46 -0500 | [diff] [blame] | 61 | PURGATORY_CFLAGS_REMOVE += -fstack-protector-strong |
Nick Desaulniers | b059f80 | 2019-08-07 15:15:33 -0700 | [diff] [blame] | 62 | endif |
| 63 | |
| 64 | ifdef CONFIG_RETPOLINE |
Steve Wahl | e16c298 | 2019-09-05 15:23:46 -0500 | [diff] [blame] | 65 | PURGATORY_CFLAGS_REMOVE += $(RETPOLINE_CFLAGS) |
Nick Desaulniers | b059f80 | 2019-08-07 15:15:33 -0700 | [diff] [blame] | 66 | endif |
Vivek Goyal | 8fc5b4d | 2014-08-08 14:26:02 -0700 | [diff] [blame] | 67 | |
Sami Tolvanen | a4b7a12 | 2022-09-08 14:55:03 -0700 | [diff] [blame] | 68 | ifdef CONFIG_CFI_CLANG |
| 69 | PURGATORY_CFLAGS_REMOVE += $(CC_FLAGS_CFI) |
| 70 | endif |
| 71 | |
Steve Wahl | e16c298 | 2019-09-05 15:23:46 -0500 | [diff] [blame] | 72 | CFLAGS_REMOVE_purgatory.o += $(PURGATORY_CFLAGS_REMOVE) |
| 73 | CFLAGS_purgatory.o += $(PURGATORY_CFLAGS) |
| 74 | |
| 75 | CFLAGS_REMOVE_sha256.o += $(PURGATORY_CFLAGS_REMOVE) |
| 76 | CFLAGS_sha256.o += $(PURGATORY_CFLAGS) |
| 77 | |
| 78 | CFLAGS_REMOVE_string.o += $(PURGATORY_CFLAGS_REMOVE) |
| 79 | CFLAGS_string.o += $(PURGATORY_CFLAGS) |
| 80 | |
Alyssa Ross | d83806c | 2023-03-26 18:21:21 +0000 | [diff] [blame] | 81 | asflags-remove-y += $(foreach x, -g -gdwarf-4 -gdwarf-5, $(x) -Wa,$(x)) |
Pingfan Liu | 52416ff | 2020-08-03 13:49:48 +0800 | [diff] [blame] | 82 | |
Vivek Goyal | 8fc5b4d | 2014-08-08 14:26:02 -0700 | [diff] [blame] | 83 | $(obj)/purgatory.ro: $(PURGATORY_OBJS) FORCE |
| 84 | $(call if_changed,ld) |
| 85 | |
Hans de Goede | e4160b2 | 2020-03-17 14:08:41 +0100 | [diff] [blame] | 86 | $(obj)/purgatory.chk: $(obj)/purgatory.ro FORCE |
| 87 | $(call if_changed,ld) |
| 88 | |
Masahiro Yamada | 2d17bd2 | 2022-07-25 11:08:12 +0900 | [diff] [blame] | 89 | $(obj)/kexec-purgatory.o: $(obj)/purgatory.ro $(obj)/purgatory.chk |
Vivek Goyal | 8fc5b4d | 2014-08-08 14:26:02 -0700 | [diff] [blame] | 90 | |
Masahiro Yamada | 61922d3 | 2022-07-25 11:08:11 +0900 | [diff] [blame] | 91 | obj-y += kexec-purgatory.o |