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