Commit | Line | Data |
---|---|---|
736e30af | 1 | # SPDX-License-Identifier: GPL-2.0 |
736e30af LZ |
2 | |
3 | purgatory-y := purgatory.o sha256.o entry.o string.o ctype.o memcpy.o memset.o | |
56e0790c | 4 | purgatory-y += strcmp.o strlen.o strncmp.o |
736e30af LZ |
5 | |
6 | targets += $(purgatory-y) | |
7 | PURGATORY_OBJS = $(addprefix $(obj)/,$(purgatory-y)) | |
8 | ||
9 | $(obj)/string.o: $(srctree)/lib/string.c FORCE | |
10 | $(call if_changed_rule,cc_o_c) | |
11 | ||
12 | $(obj)/ctype.o: $(srctree)/lib/ctype.c FORCE | |
13 | $(call if_changed_rule,cc_o_c) | |
14 | ||
15 | $(obj)/memcpy.o: $(srctree)/arch/riscv/lib/memcpy.S FORCE | |
16 | $(call if_changed_rule,as_o_S) | |
17 | ||
18 | $(obj)/memset.o: $(srctree)/arch/riscv/lib/memset.S FORCE | |
19 | $(call if_changed_rule,as_o_S) | |
20 | ||
56e0790c HS |
21 | $(obj)/strcmp.o: $(srctree)/arch/riscv/lib/strcmp.S FORCE |
22 | $(call if_changed_rule,as_o_S) | |
23 | ||
24 | $(obj)/strlen.o: $(srctree)/arch/riscv/lib/strlen.S FORCE | |
25 | $(call if_changed_rule,as_o_S) | |
26 | ||
27 | $(obj)/strncmp.o: $(srctree)/arch/riscv/lib/strncmp.S FORCE | |
28 | $(call if_changed_rule,as_o_S) | |
29 | ||
736e30af LZ |
30 | $(obj)/sha256.o: $(srctree)/lib/crypto/sha256.c FORCE |
31 | $(call if_changed_rule,cc_o_c) | |
32 | ||
8762606a | 33 | CFLAGS_sha256.o := -D__DISABLE_EXPORTS -D__NO_FORTIFY |
736e30af LZ |
34 | CFLAGS_string.o := -D__DISABLE_EXPORTS |
35 | CFLAGS_ctype.o := -D__DISABLE_EXPORTS | |
36 | ||
88ac3bbc RR |
37 | # When profile-guided optimization is enabled, llvm emits two different |
38 | # overlapping text sections, which is not supported by kexec. Remove profile | |
39 | # optimization flags. | |
40 | KBUILD_CFLAGS := $(filter-out -fprofile-sample-use=% -fprofile-use=%,$(KBUILD_CFLAGS)) | |
41 | ||
736e30af LZ |
42 | # When linking purgatory.ro with -r unresolved symbols are not checked, |
43 | # also link a purgatory.chk binary without -r to check for unresolved symbols. | |
44 | PURGATORY_LDFLAGS := -e purgatory_start -z nodefaultlib | |
45 | LDFLAGS_purgatory.ro := -r $(PURGATORY_LDFLAGS) | |
46 | LDFLAGS_purgatory.chk := $(PURGATORY_LDFLAGS) | |
47 | targets += purgatory.ro purgatory.chk | |
48 | ||
736e30af LZ |
49 | # These are adjustments to the compiler flags used for objects that |
50 | # make up the standalone purgatory.ro | |
51 | ||
52 | PURGATORY_CFLAGS_REMOVE := -mcmodel=kernel | |
53 | PURGATORY_CFLAGS := -mcmodel=medany -ffreestanding -fno-zero-initialized-in-bss | |
54 | PURGATORY_CFLAGS += $(DISABLE_STACKLEAK_PLUGIN) -DDISABLE_BRANCH_PROFILING | |
55 | PURGATORY_CFLAGS += -fno-stack-protector -g0 | |
56 | ||
57 | # Default KBUILD_CFLAGS can have -pg option set when FTRACE is enabled. That | |
58 | # in turn leaves some undefined symbols like __fentry__ in purgatory and not | |
59 | # sure how to relocate those. | |
60 | ifdef CONFIG_FUNCTION_TRACER | |
61 | PURGATORY_CFLAGS_REMOVE += $(CC_FLAGS_FTRACE) | |
62 | endif | |
63 | ||
64 | ifdef CONFIG_STACKPROTECTOR | |
65 | PURGATORY_CFLAGS_REMOVE += -fstack-protector | |
66 | endif | |
67 | ||
68 | ifdef CONFIG_STACKPROTECTOR_STRONG | |
69 | PURGATORY_CFLAGS_REMOVE += -fstack-protector-strong | |
70 | endif | |
71 | ||
a72ab036 ST |
72 | ifdef CONFIG_CFI_CLANG |
73 | PURGATORY_CFLAGS_REMOVE += $(CC_FLAGS_CFI) | |
74 | endif | |
75 | ||
0f5f46a8 SS |
76 | ifdef CONFIG_RELOCATABLE |
77 | PURGATORY_CFLAGS_REMOVE += -fPIE | |
78 | endif | |
79 | ||
d1584d79 ST |
80 | ifdef CONFIG_SHADOW_CALL_STACK |
81 | PURGATORY_CFLAGS_REMOVE += $(CC_FLAGS_SCS) | |
82 | endif | |
83 | ||
736e30af LZ |
84 | CFLAGS_REMOVE_purgatory.o += $(PURGATORY_CFLAGS_REMOVE) |
85 | CFLAGS_purgatory.o += $(PURGATORY_CFLAGS) | |
86 | ||
87 | CFLAGS_REMOVE_sha256.o += $(PURGATORY_CFLAGS_REMOVE) | |
88 | CFLAGS_sha256.o += $(PURGATORY_CFLAGS) | |
89 | ||
90 | CFLAGS_REMOVE_string.o += $(PURGATORY_CFLAGS_REMOVE) | |
91 | CFLAGS_string.o += $(PURGATORY_CFLAGS) | |
92 | ||
93 | CFLAGS_REMOVE_ctype.o += $(PURGATORY_CFLAGS_REMOVE) | |
94 | CFLAGS_ctype.o += $(PURGATORY_CFLAGS) | |
95 | ||
d83806c4 | 96 | asflags-remove-y += $(foreach x, -g -gdwarf-4 -gdwarf-5, $(x) -Wa,$(x)) |
736e30af LZ |
97 | |
98 | $(obj)/purgatory.ro: $(PURGATORY_OBJS) FORCE | |
99 | $(call if_changed,ld) | |
100 | ||
101 | $(obj)/purgatory.chk: $(obj)/purgatory.ro FORCE | |
102 | $(call if_changed,ld) | |
103 | ||
d8357e3b | 104 | $(obj)/kexec-purgatory.o: $(obj)/purgatory.ro $(obj)/purgatory.chk |
736e30af | 105 | |
788177e7 | 106 | obj-y += kexec-purgatory.o |