Debian Codegraph @

arch/riscv/Makefile

raw symbols SCIP
1 # This file is included by the global makefile so that you can add your own
2 # architecture-specific flags and dependencies.
3 #
4 # This file is subject to the terms and conditions of the GNU General Public
5 # License. See the file "COPYING" in the main directory of this archive
6 # for more details.
7 #
8
9 LDFLAGS_vmlinux := -z norelro
10 ifeq ($(CONFIG_RELOCATABLE),y)
11 LDFLAGS_vmlinux += -shared -Bsymbolic -z notext
12 KBUILD_CFLAGS += -fPIE
13 endif
14 ifeq ($(CONFIG_DYNAMIC_FTRACE),y)
15 LDFLAGS_vmlinux += --no-relax
16 KBUILD_CPPFLAGS += -DCC_USING_PATCHABLE_FUNCTION_ENTRY
17 ifeq ($(CONFIG_RISCV_ISA_C),y)
18 CC_FLAGS_FTRACE := -fpatchable-function-entry=8,4
19 else
20 CC_FLAGS_FTRACE := -fpatchable-function-entry=4,2
21 endif
22 endif
23
24 ifeq ($(CONFIG_CMODEL_MEDLOW),y)
25 KBUILD_CFLAGS_MODULE += -mcmodel=medany
26 endif
27
28 export BITS
29 ifeq ($(CONFIG_ARCH_RV64I),y)
30 BITS := 64
31
32 KBUILD_CFLAGS += -mabi=lp64
33 KBUILD_AFLAGS += -mabi=lp64
34
35 KBUILD_LDFLAGS += -melf64lriscv
36
37 KBUILD_RUSTFLAGS += -Ctarget-cpu=generic-rv64 --target=riscv64imac-unknown-none-elf \
38 -Cno-redzone
39 else
40 BITS := 32
41
42 KBUILD_CFLAGS += -mabi=ilp32
43 KBUILD_AFLAGS += -mabi=ilp32
44 KBUILD_LDFLAGS += -melf32lriscv
45 endif
46
47 UTS_MACHINE := riscv$(BITS)
48
49 # LLVM has an issue with target-features and LTO: https://github.com/llvm/llvm-project/issues/59350
50 # Ensure it is aware of linker relaxation with LTO, otherwise relocations may
51 # be incorrect: https://github.com/llvm/llvm-project/issues/65090
52 ifeq ($(CONFIG_LTO_CLANG),y)
53 KBUILD_LDFLAGS += -mllvm -mattr=+c -mllvm -mattr=+relax
54 endif
55
56 ifeq ($(CONFIG_SHADOW_CALL_STACK),y)
57 KBUILD_LDFLAGS += --no-relax-gp
58 endif
59
60 # ISA string setting
61 riscv-march-$(CONFIG_ARCH_RV32I) := rv32ima
62 riscv-march-$(CONFIG_ARCH_RV64I) := rv64ima
63 riscv-march-$(CONFIG_FPU) := $(riscv-march-y)fd
64 riscv-march-$(CONFIG_RISCV_ISA_C) := $(riscv-march-y)c
65 riscv-march-$(CONFIG_RISCV_ISA_V) := $(riscv-march-y)v
66
67 ifneq ($(CONFIG_RISCV_ISA_C),y)
68 KBUILD_RUSTFLAGS += -Ctarget-feature=-c
69 endif
70
71 ifdef CONFIG_TOOLCHAIN_NEEDS_OLD_ISA_SPEC
72 KBUILD_CFLAGS += -Wa,-misa-spec=2.2
73 KBUILD_AFLAGS += -Wa,-misa-spec=2.2
74 else
75 riscv-march-$(CONFIG_TOOLCHAIN_NEEDS_EXPLICIT_ZICSR_ZIFENCEI) := $(riscv-march-y)_zicsr_zifencei
76 endif
77
78 # Check if the toolchain supports Zacas
79 riscv-march-$(CONFIG_TOOLCHAIN_HAS_ZACAS) := $(riscv-march-y)_zacas
80
81 # Check if the toolchain supports Zabha
82 riscv-march-$(CONFIG_TOOLCHAIN_HAS_ZABHA) := $(riscv-march-y)_zabha
83
84 KBUILD_BASE_ISA = -march=$(shell echo $(riscv-march-y) | sed -E 's/(rv32ima|rv64ima)fd([^v_]*)v?/\1\2/')
85 export KBUILD_BASE_ISA
86
87 # Remove F,D,V from isa string for all. Keep extensions between "fd" and "v" by
88 # matching non-v and non-multi-letter extensions out with the filter ([^v_]*)
89 KBUILD_CFLAGS += $(KBUILD_BASE_ISA)
90
91 KBUILD_AFLAGS += -march=$(riscv-march-y)
92
93 # For C code built with floating-point support, exclude V but keep F and D.
94 CC_FLAGS_FPU := -march=$(shell echo $(riscv-march-y) | sed -E 's/(rv32ima|rv64ima)([^v_]*)v?/\1\2/')
95
96 KBUILD_CFLAGS += -mno-save-restore
97
98 ifeq ($(CONFIG_CMODEL_MEDLOW),y)
99 KBUILD_CFLAGS += -mcmodel=medlow
100 endif
101 ifeq ($(CONFIG_CMODEL_MEDANY),y)
102 KBUILD_CFLAGS += -mcmodel=medany
103 endif
104
105 # Avoid generating .eh_frame sections.
106 KBUILD_CFLAGS += -fno-asynchronous-unwind-tables -fno-unwind-tables
107
108 # The RISC-V attributes frequently cause compatibility issues and provide no
109 # information, so just turn them off.
110 KBUILD_CFLAGS += $(call cc-option,-mno-riscv-attribute)
111 KBUILD_AFLAGS += $(call cc-option,-mno-riscv-attribute)
112 KBUILD_CFLAGS += $(call as-option,-Wa$(comma)-mno-arch-attr)
113 KBUILD_AFLAGS += $(call as-option,-Wa$(comma)-mno-arch-attr)
114
115 KBUILD_CFLAGS_MODULE += $(call cc-option,-mno-relax)
116 KBUILD_AFLAGS_MODULE += $(call as-option,-Wa$(comma)-mno-relax)
117
118 # GCC versions that support the "-mstrict-align" option default to allowing
119 # unaligned accesses. While unaligned accesses are explicitly allowed in the
120 # RISC-V ISA, they're emulated by machine mode traps on all extant
121 # architectures. It's faster to have GCC emit only aligned accesses.
122 ifneq ($(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS),y)
123 KBUILD_CFLAGS += $(call cc-option,-mstrict-align)
124 endif
125
126 ifeq ($(CONFIG_STACKPROTECTOR_PER_TASK),y)
127 prepare: stack_protector_prepare
128 stack_protector_prepare: prepare0
129 $(eval KBUILD_CFLAGS += -mstack-protector-guard=tls \
130 -mstack-protector-guard-reg=tp \
131 -mstack-protector-guard-offset=$(shell \
132 awk '{if ($$2 == "TSK_STACK_CANARY") print $$3;}' \
133 $(objtree)/include/generated/asm-offsets.h))
134 endif
135
136 # arch specific predefines for sparse
137 CHECKFLAGS += -D__riscv -D__riscv_xlen=$(BITS)
138
139 # Default target when executing plain make
140 boot := arch/riscv/boot
141 boot-image-y := Image
142 boot-image-$(CONFIG_KERNEL_BZIP2) := Image.bz2
143 boot-image-$(CONFIG_KERNEL_GZIP) := Image.gz
144 boot-image-$(CONFIG_KERNEL_LZ4) := Image.lz4
145 boot-image-$(CONFIG_KERNEL_LZMA) := Image.lzma
146 boot-image-$(CONFIG_KERNEL_LZO) := Image.lzo
147 boot-image-$(CONFIG_KERNEL_ZSTD) := Image.zst
148 boot-image-$(CONFIG_KERNEL_XZ) := Image.xz
149 ifdef CONFIG_RISCV_M_MODE
150 boot-image-$(CONFIG_SOC_CANAAN_K210) := loader.bin
151 endif
152 boot-image-$(CONFIG_EFI_ZBOOT) := vmlinuz.efi
153 KBUILD_IMAGE := $(boot)/$(boot-image-y)
154
155 libs-y += arch/riscv/lib/
156 libs-$(CONFIG_EFI_STUB) += $(objtree)/drivers/firmware/efi/libstub/lib.a
157
158 ifeq ($(KBUILD_EXTMOD),)
159 ifeq ($(CONFIG_MMU),y)
160 prepare: vdso_prepare
161 vdso_prepare: prepare0
162 $(Q)$(MAKE) $(build)=arch/riscv/kernel/vdso include/generated/vdso-offsets.h
163 $(if $(CONFIG_RISCV_USER_CFI),$(Q)$(MAKE) \
164 $(build)=arch/riscv/kernel/vdso_cfi include/generated/vdso-cfi-offsets.h)
165 $(if $(CONFIG_COMPAT),$(Q)$(MAKE) \
166 $(build)=arch/riscv/kernel/compat_vdso include/generated/compat_vdso-offsets.h)
167
168 endif
169 endif
170
171 vdso-install-$(CONFIG_MMU) += arch/riscv/kernel/vdso/vdso.so.dbg
172 vdso-install-$(CONFIG_RISCV_USER_CFI) += arch/riscv/kernel/vdso_cfi/vdso-cfi.so.dbg
173 vdso-install-$(CONFIG_COMPAT) += arch/riscv/kernel/compat_vdso/compat_vdso.so.dbg
174
175 BOOT_TARGETS := Image Image.gz Image.bz2 Image.lz4 Image.lzma Image.lzo Image.zst Image.xz loader loader.bin xipImage vmlinuz.efi
176
177 all: $(notdir $(KBUILD_IMAGE))
178
179 loader.bin: loader
180 Image.gz Image.bz2 Image.lz4 Image.lzma Image.lzo Image.zst Image.xz loader xipImage vmlinuz.efi: Image
181
182 $(BOOT_TARGETS): vmlinux
183 $(Q)$(MAKE) $(build)=$(boot) $(boot)/$@
184 @$(kecho) ' Kernel: $(boot)/$@ is ready'
185
186 # the install target always installs KBUILD_IMAGE (which may be compressed)
187 # but keep the zinstall target for compatibility with older releases
188 install zinstall:
189 $(call cmd,install)
190
191 PHONY += rv32_randconfig
192 rv32_randconfig:
193 $(Q)$(MAKE) KCONFIG_ALLCONFIG=$(srctree)/arch/riscv/configs/32-bit.config \
194 -f $(srctree)/Makefile randconfig
195
196 PHONY += rv64_randconfig
197 rv64_randconfig:
198 $(Q)$(MAKE) KCONFIG_ALLCONFIG=$(srctree)/arch/riscv/configs/64-bit.config \
199 -f $(srctree)/Makefile randconfig
200
201 PHONY += rv32_defconfig
202 rv32_defconfig:
203 $(Q)$(MAKE) -f $(srctree)/Makefile defconfig 32-bit.config
204
205 PHONY += rv32_nommu_virt_defconfig
206 rv32_nommu_virt_defconfig:
207 $(Q)$(MAKE) -f $(srctree)/Makefile nommu_virt_defconfig 32-bit.config
208
209 define archhelp
210 echo ' Image - Uncompressed kernel image (arch/riscv/boot/Image)'
211 echo ' Image.gz - Compressed kernel image (arch/riscv/boot/Image.gz)'
212 echo ' Image.bz2 - Compressed kernel image (arch/riscv/boot/Image.bz2)'
213 echo ' Image.lz4 - Compressed kernel image (arch/riscv/boot/Image.lz4)'
214 echo ' Image.lzma - Compressed kernel image (arch/riscv/boot/Image.lzma)'
215 echo ' Image.lzo - Compressed kernel image (arch/riscv/boot/Image.lzo)'
216 echo ' Image.zst - Compressed kernel image (arch/riscv/boot/Image.zst)'
217 echo ' Image.xz - Compressed kernel image (arch/riscv/boot/Image.xz)'
218 echo ' vmlinuz.efi - Compressed EFI kernel image (arch/riscv/boot/vmlinuz.efi)'
219 echo ' Default when CONFIG_EFI_ZBOOT=y'
220 echo ' install - Install kernel using (your) ~/bin/$(INSTALLKERNEL) or'
221 echo ' (distribution) /sbin/$(INSTALLKERNEL) or install to '
222 echo ' $$(INSTALL_PATH)'
223 endef