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 9LDFLAGS_vmlinux := -z norelro 10ifeq ($(CONFIG_RELOCATABLE),y) 11 LDFLAGS_vmlinux += -shared -Bsymbolic -z notext --emit-relocs 12 KBUILD_CFLAGS += -fPIE 13endif 14ifeq ($(CONFIG_DYNAMIC_FTRACE),y) 15 LDFLAGS_vmlinux += --no-relax 16 KBUILD_CPPFLAGS += -DCC_USING_PATCHABLE_FUNCTION_ENTRY 17ifeq ($(CONFIG_RISCV_ISA_C),y) 18 CC_FLAGS_FTRACE := -fpatchable-function-entry=4 19else 20 CC_FLAGS_FTRACE := -fpatchable-function-entry=2 21endif 22endif 23 24ifeq ($(CONFIG_CMODEL_MEDLOW),y) 25KBUILD_CFLAGS_MODULE += -mcmodel=medany 26endif 27 28export BITS 29ifeq ($(CONFIG_ARCH_RV64I),y) 30 BITS := 64 31 UTS_MACHINE := riscv64 32 33 KBUILD_CFLAGS += -mabi=lp64 34 KBUILD_AFLAGS += -mabi=lp64 35 36 KBUILD_LDFLAGS += -melf64lriscv 37else 38 BITS := 32 39 UTS_MACHINE := riscv32 40 41 KBUILD_CFLAGS += -mabi=ilp32 42 KBUILD_AFLAGS += -mabi=ilp32 43 KBUILD_LDFLAGS += -melf32lriscv 44endif 45 46ifeq ($(CONFIG_LD_IS_LLD),y) 47ifeq ($(call test-lt, $(CONFIG_LLD_VERSION), 150000),y) 48 KBUILD_CFLAGS += -mno-relax 49 KBUILD_AFLAGS += -mno-relax 50ifndef CONFIG_AS_IS_LLVM 51 KBUILD_CFLAGS += -Wa,-mno-relax 52 KBUILD_AFLAGS += -Wa,-mno-relax 53endif 54endif 55endif 56 57ifeq ($(CONFIG_SHADOW_CALL_STACK),y) 58 KBUILD_LDFLAGS += --no-relax-gp 59endif 60 61# ISA string setting 62riscv-march-$(CONFIG_ARCH_RV32I) := rv32ima 63riscv-march-$(CONFIG_ARCH_RV64I) := rv64ima 64riscv-march-$(CONFIG_FPU) := $(riscv-march-y)fd 65riscv-march-$(CONFIG_RISCV_ISA_C) := $(riscv-march-y)c 66riscv-march-$(CONFIG_RISCV_ISA_V) := $(riscv-march-y)v 67 68ifdef CONFIG_TOOLCHAIN_NEEDS_OLD_ISA_SPEC 69KBUILD_CFLAGS += -Wa,-misa-spec=2.2 70KBUILD_AFLAGS += -Wa,-misa-spec=2.2 71else 72riscv-march-$(CONFIG_TOOLCHAIN_NEEDS_EXPLICIT_ZICSR_ZIFENCEI) := $(riscv-march-y)_zicsr_zifencei 73endif 74 75# Check if the toolchain supports Zihintpause extension 76riscv-march-$(CONFIG_TOOLCHAIN_HAS_ZIHINTPAUSE) := $(riscv-march-y)_zihintpause 77 78# Remove F,D,V from isa string for all. Keep extensions between "fd" and "v" by 79# matching non-v and non-multi-letter extensions out with the filter ([^v_]*) 80KBUILD_CFLAGS += -march=$(shell echo $(riscv-march-y) | sed -E 's/(rv32ima|rv64ima)fd([^v_]*)v?/\1\2/') 81 82KBUILD_AFLAGS += -march=$(riscv-march-y) 83 84KBUILD_CFLAGS += -mno-save-restore 85KBUILD_CFLAGS += -DCONFIG_PAGE_OFFSET=$(CONFIG_PAGE_OFFSET) 86 87ifeq ($(CONFIG_CMODEL_MEDLOW),y) 88 KBUILD_CFLAGS += -mcmodel=medlow 89endif 90ifeq ($(CONFIG_CMODEL_MEDANY),y) 91 KBUILD_CFLAGS += -mcmodel=medany 92endif 93 94# Avoid generating .eh_frame sections. 95KBUILD_CFLAGS += -fno-asynchronous-unwind-tables -fno-unwind-tables 96 97# The RISC-V attributes frequently cause compatibility issues and provide no 98# information, so just turn them off. 99KBUILD_CFLAGS += $(call cc-option,-mno-riscv-attribute) 100KBUILD_AFLAGS += $(call cc-option,-mno-riscv-attribute) 101KBUILD_CFLAGS += $(call as-option,-Wa$(comma)-mno-arch-attr) 102KBUILD_AFLAGS += $(call as-option,-Wa$(comma)-mno-arch-attr) 103 104KBUILD_CFLAGS_MODULE += $(call cc-option,-mno-relax) 105KBUILD_AFLAGS_MODULE += $(call as-option,-Wa$(comma)-mno-relax) 106 107# GCC versions that support the "-mstrict-align" option default to allowing 108# unaligned accesses. While unaligned accesses are explicitly allowed in the 109# RISC-V ISA, they're emulated by machine mode traps on all extant 110# architectures. It's faster to have GCC emit only aligned accesses. 111ifneq ($(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS),y) 112KBUILD_CFLAGS += $(call cc-option,-mstrict-align) 113endif 114 115ifeq ($(CONFIG_STACKPROTECTOR_PER_TASK),y) 116prepare: stack_protector_prepare 117stack_protector_prepare: prepare0 118 $(eval KBUILD_CFLAGS += -mstack-protector-guard=tls \ 119 -mstack-protector-guard-reg=tp \ 120 -mstack-protector-guard-offset=$(shell \ 121 awk '{if ($$2 == "TSK_STACK_CANARY") print $$3;}' \ 122 include/generated/asm-offsets.h)) 123endif 124 125# arch specific predefines for sparse 126CHECKFLAGS += -D__riscv -D__riscv_xlen=$(BITS) 127 128# Default target when executing plain make 129boot := arch/riscv/boot 130ifeq ($(CONFIG_XIP_KERNEL),y) 131KBUILD_IMAGE := $(boot)/xipImage 132else 133KBUILD_IMAGE := $(boot)/Image.gz 134endif 135 136libs-y += arch/riscv/lib/ 137libs-$(CONFIG_EFI_STUB) += $(objtree)/drivers/firmware/efi/libstub/lib.a 138 139ifeq ($(KBUILD_EXTMOD),) 140ifeq ($(CONFIG_MMU),y) 141prepare: vdso_prepare 142vdso_prepare: prepare0 143 $(Q)$(MAKE) $(build)=arch/riscv/kernel/vdso include/generated/vdso-offsets.h 144 $(if $(CONFIG_COMPAT),$(Q)$(MAKE) \ 145 $(build)=arch/riscv/kernel/compat_vdso include/generated/compat_vdso-offsets.h) 146 147endif 148endif 149 150vdso-install-y += arch/riscv/kernel/vdso/vdso.so.dbg 151vdso-install-$(CONFIG_COMPAT) += arch/riscv/kernel/compat_vdso/compat_vdso.so.dbg:../compat_vdso/compat_vdso.so 152 153ifneq ($(CONFIG_XIP_KERNEL),y) 154ifeq ($(CONFIG_RISCV_M_MODE)$(CONFIG_ARCH_CANAAN),yy) 155KBUILD_IMAGE := $(boot)/loader.bin 156else 157ifeq ($(CONFIG_EFI_ZBOOT),) 158KBUILD_IMAGE := $(boot)/Image.gz 159else 160KBUILD_IMAGE := $(boot)/vmlinuz.efi 161endif 162endif 163endif 164BOOT_TARGETS := Image Image.gz loader loader.bin xipImage vmlinuz.efi 165 166all: $(notdir $(KBUILD_IMAGE)) 167 168$(BOOT_TARGETS): vmlinux 169 $(Q)$(MAKE) $(build)=$(boot) $(boot)/$@ 170 @$(kecho) ' Kernel: $(boot)/$@ is ready' 171 172Image.%: Image 173 $(Q)$(MAKE) $(build)=$(boot) $(boot)/$@ 174 175install: KBUILD_IMAGE := $(boot)/Image 176zinstall: KBUILD_IMAGE := $(boot)/Image.gz 177install zinstall: 178 $(call cmd,install) 179 180PHONY += rv32_randconfig 181rv32_randconfig: 182 $(Q)$(MAKE) KCONFIG_ALLCONFIG=$(srctree)/arch/riscv/configs/32-bit.config \ 183 -f $(srctree)/Makefile randconfig 184 185PHONY += rv64_randconfig 186rv64_randconfig: 187 $(Q)$(MAKE) KCONFIG_ALLCONFIG=$(srctree)/arch/riscv/configs/64-bit.config \ 188 -f $(srctree)/Makefile randconfig 189 190PHONY += rv32_defconfig 191rv32_defconfig: 192 $(Q)$(MAKE) -f $(srctree)/Makefile defconfig 32-bit.config 193 194PHONY += rv32_nommu_virt_defconfig 195rv32_nommu_virt_defconfig: 196 $(Q)$(MAKE) -f $(srctree)/Makefile nommu_virt_defconfig 32-bit.config 197