GNU Linux-libre 6.1.90-gnu
[releases.git] / arch / riscv / purgatory / Makefile
1 # SPDX-License-Identifier: GPL-2.0
2 OBJECT_FILES_NON_STANDARD := y
3
4 purgatory-y := purgatory.o sha256.o entry.o string.o ctype.o memcpy.o memset.o
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
21 $(obj)/sha256.o: $(srctree)/lib/crypto/sha256.c FORCE
22         $(call if_changed_rule,cc_o_c)
23
24 CFLAGS_sha256.o := -D__DISABLE_EXPORTS
25 CFLAGS_string.o := -D__DISABLE_EXPORTS
26 CFLAGS_ctype.o := -D__DISABLE_EXPORTS
27
28 # When profile-guided optimization is enabled, llvm emits two different
29 # overlapping text sections, which is not supported by kexec. Remove profile
30 # optimization flags.
31 KBUILD_CFLAGS := $(filter-out -fprofile-sample-use=% -fprofile-use=%,$(KBUILD_CFLAGS))
32
33 # When linking purgatory.ro with -r unresolved symbols are not checked,
34 # also link a purgatory.chk binary without -r to check for unresolved symbols.
35 PURGATORY_LDFLAGS := -e purgatory_start -z nodefaultlib
36 LDFLAGS_purgatory.ro := -r $(PURGATORY_LDFLAGS)
37 LDFLAGS_purgatory.chk := $(PURGATORY_LDFLAGS)
38 targets += purgatory.ro purgatory.chk
39
40 # Sanitizer, etc. runtimes are unavailable and cannot be linked here.
41 GCOV_PROFILE    := n
42 KASAN_SANITIZE  := n
43 UBSAN_SANITIZE  := n
44 KCSAN_SANITIZE  := n
45 KCOV_INSTRUMENT := n
46
47 # These are adjustments to the compiler flags used for objects that
48 # make up the standalone purgatory.ro
49
50 PURGATORY_CFLAGS_REMOVE := -mcmodel=kernel
51 PURGATORY_CFLAGS := -mcmodel=medany -ffreestanding -fno-zero-initialized-in-bss
52 PURGATORY_CFLAGS += $(DISABLE_STACKLEAK_PLUGIN) -DDISABLE_BRANCH_PROFILING
53 PURGATORY_CFLAGS += -fno-stack-protector -g0
54
55 # Default KBUILD_CFLAGS can have -pg option set when FTRACE is enabled. That
56 # in turn leaves some undefined symbols like __fentry__ in purgatory and not
57 # sure how to relocate those.
58 ifdef CONFIG_FUNCTION_TRACER
59 PURGATORY_CFLAGS_REMOVE         += $(CC_FLAGS_FTRACE)
60 endif
61
62 ifdef CONFIG_STACKPROTECTOR
63 PURGATORY_CFLAGS_REMOVE         += -fstack-protector
64 endif
65
66 ifdef CONFIG_STACKPROTECTOR_STRONG
67 PURGATORY_CFLAGS_REMOVE         += -fstack-protector-strong
68 endif
69
70 CFLAGS_REMOVE_purgatory.o       += $(PURGATORY_CFLAGS_REMOVE)
71 CFLAGS_purgatory.o              += $(PURGATORY_CFLAGS)
72
73 CFLAGS_REMOVE_sha256.o          += $(PURGATORY_CFLAGS_REMOVE)
74 CFLAGS_sha256.o                 += $(PURGATORY_CFLAGS)
75
76 CFLAGS_REMOVE_string.o          += $(PURGATORY_CFLAGS_REMOVE)
77 CFLAGS_string.o                 += $(PURGATORY_CFLAGS)
78
79 CFLAGS_REMOVE_ctype.o           += $(PURGATORY_CFLAGS_REMOVE)
80 CFLAGS_ctype.o                  += $(PURGATORY_CFLAGS)
81
82 asflags-remove-y                += $(foreach x, -g -gdwarf-4 -gdwarf-5, $(x) -Wa,$(x))
83
84 $(obj)/purgatory.ro: $(PURGATORY_OBJS) FORCE
85                 $(call if_changed,ld)
86
87 $(obj)/purgatory.chk: $(obj)/purgatory.ro FORCE
88                 $(call if_changed,ld)
89
90 $(obj)/kexec-purgatory.o: $(obj)/purgatory.ro $(obj)/purgatory.chk
91
92 obj-y += kexec-purgatory.o