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