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