1 # This file is included by the global makefile so that you can add your own
2 # architecture-specific flags and dependencies.
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
9 LDFLAGS_vmlinux := -z norelro
10 ifeq ($(CONFIG_RELOCATABLE),y)
11 LDFLAGS_vmlinux += -shared -Bsymbolic -z notext --emit-relocs
12 KBUILD_CFLAGS += -fPIE
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=4
20 CC_FLAGS_FTRACE := -fpatchable-function-entry=2
24 ifeq ($(CONFIG_CMODEL_MEDLOW),y)
25 KBUILD_CFLAGS_MODULE += -mcmodel=medany
29 ifeq ($(CONFIG_ARCH_RV64I),y)
31 UTS_MACHINE := riscv64
33 KBUILD_CFLAGS += -mabi=lp64
34 KBUILD_AFLAGS += -mabi=lp64
36 KBUILD_LDFLAGS += -melf64lriscv
39 UTS_MACHINE := riscv32
41 KBUILD_CFLAGS += -mabi=ilp32
42 KBUILD_AFLAGS += -mabi=ilp32
43 KBUILD_LDFLAGS += -melf32lriscv
46 ifndef CONFIG_RISCV_USE_LINKER_RELAXATION
47 KBUILD_CFLAGS += -mno-relax
48 KBUILD_AFLAGS += -mno-relax
49 ifndef CONFIG_AS_IS_LLVM
50 KBUILD_CFLAGS += -Wa,-mno-relax
51 KBUILD_AFLAGS += -Wa,-mno-relax
53 # LLVM has an issue with target-features and LTO: https://github.com/llvm/llvm-project/issues/59350
54 # Ensure it is aware of linker relaxation with LTO, otherwise relocations may
55 # be incorrect: https://github.com/llvm/llvm-project/issues/65090
56 else ifeq ($(CONFIG_LTO_CLANG),y)
57 KBUILD_LDFLAGS += -mllvm -mattr=+c -mllvm -mattr=+relax
60 ifeq ($(CONFIG_SHADOW_CALL_STACK),y)
61 KBUILD_LDFLAGS += --no-relax-gp
65 riscv-march-$(CONFIG_ARCH_RV32I) := rv32ima
66 riscv-march-$(CONFIG_ARCH_RV64I) := rv64ima
67 riscv-march-$(CONFIG_FPU) := $(riscv-march-y)fd
68 riscv-march-$(CONFIG_RISCV_ISA_C) := $(riscv-march-y)c
69 riscv-march-$(CONFIG_RISCV_ISA_V) := $(riscv-march-y)v
71 ifdef CONFIG_TOOLCHAIN_NEEDS_OLD_ISA_SPEC
72 KBUILD_CFLAGS += -Wa,-misa-spec=2.2
73 KBUILD_AFLAGS += -Wa,-misa-spec=2.2
75 riscv-march-$(CONFIG_TOOLCHAIN_NEEDS_EXPLICIT_ZICSR_ZIFENCEI) := $(riscv-march-y)_zicsr_zifencei
78 # Check if the toolchain supports Zihintpause extension
79 riscv-march-$(CONFIG_TOOLCHAIN_HAS_ZIHINTPAUSE) := $(riscv-march-y)_zihintpause
81 # Remove F,D,V from isa string for all. Keep extensions between "fd" and "v" by
82 # matching non-v and non-multi-letter extensions out with the filter ([^v_]*)
83 KBUILD_CFLAGS += -march=$(shell echo $(riscv-march-y) | sed -E 's/(rv32ima|rv64ima)fd([^v_]*)v?/\1\2/')
85 KBUILD_AFLAGS += -march=$(riscv-march-y)
87 KBUILD_CFLAGS += -mno-save-restore
88 KBUILD_CFLAGS += -DCONFIG_PAGE_OFFSET=$(CONFIG_PAGE_OFFSET)
90 ifeq ($(CONFIG_CMODEL_MEDLOW),y)
91 KBUILD_CFLAGS += -mcmodel=medlow
93 ifeq ($(CONFIG_CMODEL_MEDANY),y)
94 KBUILD_CFLAGS += -mcmodel=medany
97 # Avoid generating .eh_frame sections.
98 KBUILD_CFLAGS += -fno-asynchronous-unwind-tables -fno-unwind-tables
100 # The RISC-V attributes frequently cause compatibility issues and provide no
101 # information, so just turn them off.
102 KBUILD_CFLAGS += $(call cc-option,-mno-riscv-attribute)
103 KBUILD_AFLAGS += $(call cc-option,-mno-riscv-attribute)
104 KBUILD_CFLAGS += $(call as-option,-Wa$(comma)-mno-arch-attr)
105 KBUILD_AFLAGS += $(call as-option,-Wa$(comma)-mno-arch-attr)
107 KBUILD_CFLAGS_MODULE += $(call cc-option,-mno-relax)
108 KBUILD_AFLAGS_MODULE += $(call as-option,-Wa$(comma)-mno-relax)
110 # GCC versions that support the "-mstrict-align" option default to allowing
111 # unaligned accesses. While unaligned accesses are explicitly allowed in the
112 # RISC-V ISA, they're emulated by machine mode traps on all extant
113 # architectures. It's faster to have GCC emit only aligned accesses.
114 ifneq ($(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS),y)
115 KBUILD_CFLAGS += $(call cc-option,-mstrict-align)
118 ifeq ($(CONFIG_STACKPROTECTOR_PER_TASK),y)
119 prepare: stack_protector_prepare
120 stack_protector_prepare: prepare0
121 $(eval KBUILD_CFLAGS += -mstack-protector-guard=tls \
122 -mstack-protector-guard-reg=tp \
123 -mstack-protector-guard-offset=$(shell \
124 awk '{if ($$2 == "TSK_STACK_CANARY") print $$3;}' \
125 include/generated/asm-offsets.h))
128 # arch specific predefines for sparse
129 CHECKFLAGS += -D__riscv -D__riscv_xlen=$(BITS)
131 # Default target when executing plain make
132 boot := arch/riscv/boot
133 ifeq ($(CONFIG_XIP_KERNEL),y)
134 KBUILD_IMAGE := $(boot)/xipImage
136 KBUILD_IMAGE := $(boot)/Image.gz
139 libs-y += arch/riscv/lib/
140 libs-$(CONFIG_EFI_STUB) += $(objtree)/drivers/firmware/efi/libstub/lib.a
142 ifeq ($(KBUILD_EXTMOD),)
143 ifeq ($(CONFIG_MMU),y)
144 prepare: vdso_prepare
145 vdso_prepare: prepare0
146 $(Q)$(MAKE) $(build)=arch/riscv/kernel/vdso include/generated/vdso-offsets.h
147 $(if $(CONFIG_COMPAT),$(Q)$(MAKE) \
148 $(build)=arch/riscv/kernel/compat_vdso include/generated/compat_vdso-offsets.h)
153 vdso-install-y += arch/riscv/kernel/vdso/vdso.so.dbg
154 vdso-install-$(CONFIG_COMPAT) += arch/riscv/kernel/compat_vdso/compat_vdso.so.dbg
156 ifneq ($(CONFIG_XIP_KERNEL),y)
157 ifeq ($(CONFIG_RISCV_M_MODE)$(CONFIG_ARCH_CANAAN),yy)
158 KBUILD_IMAGE := $(boot)/loader.bin
160 ifeq ($(CONFIG_EFI_ZBOOT),)
161 KBUILD_IMAGE := $(boot)/Image.gz
163 KBUILD_IMAGE := $(boot)/vmlinuz.efi
167 BOOT_TARGETS := Image Image.gz loader loader.bin xipImage vmlinuz.efi
169 all: $(notdir $(KBUILD_IMAGE))
172 Image.gz loader vmlinuz.efi: Image
173 $(BOOT_TARGETS): vmlinux
174 $(Q)$(MAKE) $(build)=$(boot) $(boot)/$@
175 @$(kecho) ' Kernel: $(boot)/$@ is ready'
178 $(Q)$(MAKE) $(build)=$(boot) $(boot)/$@
180 install: KBUILD_IMAGE := $(boot)/Image
181 zinstall: KBUILD_IMAGE := $(boot)/Image.gz
185 PHONY += rv32_randconfig
187 $(Q)$(MAKE) KCONFIG_ALLCONFIG=$(srctree)/arch/riscv/configs/32-bit.config \
188 -f $(srctree)/Makefile randconfig
190 PHONY += rv64_randconfig
192 $(Q)$(MAKE) KCONFIG_ALLCONFIG=$(srctree)/arch/riscv/configs/64-bit.config \
193 -f $(srctree)/Makefile randconfig
195 PHONY += rv32_defconfig
197 $(Q)$(MAKE) -f $(srctree)/Makefile defconfig 32-bit.config
199 PHONY += rv32_nommu_virt_defconfig
200 rv32_nommu_virt_defconfig:
201 $(Q)$(MAKE) -f $(srctree)/Makefile nommu_virt_defconfig 32-bit.config