Merge tag 'kbuild-v6.10' of git://git.kernel.org/pub/scm/linux/kernel/git/masahiroy...
[linux-block.git] / arch / riscv / purgatory / Makefile
CommitLineData
736e30af 1# SPDX-License-Identifier: GPL-2.0
736e30af
LZ
2
3purgatory-y := purgatory.o sha256.o entry.o string.o ctype.o memcpy.o memset.o
56e0790c 4purgatory-y += strcmp.o strlen.o strncmp.o
736e30af
LZ
5
6targets += $(purgatory-y)
7PURGATORY_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 33CFLAGS_sha256.o := -D__DISABLE_EXPORTS -D__NO_FORTIFY
736e30af
LZ
34CFLAGS_string.o := -D__DISABLE_EXPORTS
35CFLAGS_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.
40KBUILD_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.
44PURGATORY_LDFLAGS := -e purgatory_start -z nodefaultlib
45LDFLAGS_purgatory.ro := -r $(PURGATORY_LDFLAGS)
46LDFLAGS_purgatory.chk := $(PURGATORY_LDFLAGS)
47targets += 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
52PURGATORY_CFLAGS_REMOVE := -mcmodel=kernel
53PURGATORY_CFLAGS := -mcmodel=medany -ffreestanding -fno-zero-initialized-in-bss
54PURGATORY_CFLAGS += $(DISABLE_STACKLEAK_PLUGIN) -DDISABLE_BRANCH_PROFILING
55PURGATORY_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.
60ifdef CONFIG_FUNCTION_TRACER
61PURGATORY_CFLAGS_REMOVE += $(CC_FLAGS_FTRACE)
62endif
63
64ifdef CONFIG_STACKPROTECTOR
65PURGATORY_CFLAGS_REMOVE += -fstack-protector
66endif
67
68ifdef CONFIG_STACKPROTECTOR_STRONG
69PURGATORY_CFLAGS_REMOVE += -fstack-protector-strong
70endif
71
a72ab036
ST
72ifdef CONFIG_CFI_CLANG
73PURGATORY_CFLAGS_REMOVE += $(CC_FLAGS_CFI)
74endif
75
0f5f46a8
SS
76ifdef CONFIG_RELOCATABLE
77PURGATORY_CFLAGS_REMOVE += -fPIE
78endif
79
d1584d79
ST
80ifdef CONFIG_SHADOW_CALL_STACK
81PURGATORY_CFLAGS_REMOVE += $(CC_FLAGS_SCS)
82endif
83
736e30af
LZ
84CFLAGS_REMOVE_purgatory.o += $(PURGATORY_CFLAGS_REMOVE)
85CFLAGS_purgatory.o += $(PURGATORY_CFLAGS)
86
87CFLAGS_REMOVE_sha256.o += $(PURGATORY_CFLAGS_REMOVE)
88CFLAGS_sha256.o += $(PURGATORY_CFLAGS)
89
90CFLAGS_REMOVE_string.o += $(PURGATORY_CFLAGS_REMOVE)
91CFLAGS_string.o += $(PURGATORY_CFLAGS)
92
93CFLAGS_REMOVE_ctype.o += $(PURGATORY_CFLAGS_REMOVE)
94CFLAGS_ctype.o += $(PURGATORY_CFLAGS)
95
d83806c4 96asflags-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 106obj-y += kexec-purgatory.o