xref: /linux/arch/arm64/Makefile (revision 2a6b6c9a226279b4f6668450ddb21ae655558087)
1#
2# arch/arm64/Makefile
3#
4# This file is included by the global makefile so that you can add your own
5# architecture-specific flags and dependencies.
6#
7# This file is subject to the terms and conditions of the GNU General Public
8# License.  See the file "COPYING" in the main directory of this archive
9# for more details.
10#
11# Copyright (C) 1995-2001 by Russell King
12
13LDFLAGS_vmlinux	:=--no-undefined -X
14
15ifeq ($(CONFIG_RELOCATABLE), y)
16# Pass --no-apply-dynamic-relocs to restore pre-binutils-2.27 behaviour
17# for relative relocs, since this leads to better Image compression
18# with the relocation offsets always being zero.
19LDFLAGS_vmlinux		+= -shared -Bsymbolic -z notext \
20			$(call ld-option, --no-apply-dynamic-relocs)
21endif
22
23ifeq ($(CONFIG_ARM64_ERRATUM_843419),y)
24  ifeq ($(CONFIG_ARM64_LD_HAS_FIX_ERRATUM_843419),y)
25LDFLAGS_vmlinux	+= --fix-cortex-a53-843419
26  endif
27endif
28
29cc_has_k_constraint := $(call try-run,echo				\
30	'int main(void) {						\
31		asm volatile("and w0, w0, %w0" :: "K" (4294967295));	\
32		return 0;						\
33	}' | $(CC) -S -x c -o "$$TMP" -,,-DCONFIG_CC_HAS_K_CONSTRAINT=1)
34
35ifeq ($(CONFIG_BROKEN_GAS_INST),y)
36$(warning Detected assembler with broken .inst; disassembly will be unreliable)
37endif
38
39# The GCC option -ffreestanding is required in order to compile code containing
40# ARM/NEON intrinsics in a non C99-compliant environment (such as the kernel)
41CC_FLAGS_FPU	:= -ffreestanding
42# Enable <arm_neon.h>
43CC_FLAGS_FPU	+= -isystem $(shell $(CC) -print-file-name=include)
44CC_FLAGS_NO_FPU	:= -mgeneral-regs-only
45
46KBUILD_CFLAGS	+= $(CC_FLAGS_NO_FPU) \
47		   $(compat_vdso) $(cc_has_k_constraint)
48KBUILD_CFLAGS	+= $(call cc-disable-warning, psabi)
49KBUILD_AFLAGS	+= $(compat_vdso)
50
51KBUILD_RUSTFLAGS += --target=aarch64-unknown-none -Ctarget-feature="-neon"
52
53KBUILD_CFLAGS	+= $(call cc-option,-mabi=lp64)
54KBUILD_AFLAGS	+= $(call cc-option,-mabi=lp64)
55
56# Avoid generating .eh_frame* sections.
57ifneq ($(CONFIG_UNWIND_TABLES),y)
58KBUILD_CFLAGS	+= -fno-asynchronous-unwind-tables -fno-unwind-tables
59KBUILD_AFLAGS	+= -fno-asynchronous-unwind-tables -fno-unwind-tables
60else
61KBUILD_CFLAGS	+= -fasynchronous-unwind-tables
62KBUILD_AFLAGS	+= -fasynchronous-unwind-tables
63endif
64
65ifeq ($(CONFIG_STACKPROTECTOR_PER_TASK),y)
66prepare: stack_protector_prepare
67stack_protector_prepare: prepare0
68	$(eval KBUILD_CFLAGS += -mstack-protector-guard=sysreg		  \
69				-mstack-protector-guard-reg=sp_el0	  \
70				-mstack-protector-guard-offset=$(shell	  \
71			awk '{if ($$2 == "TSK_STACK_CANARY") print $$3;}' \
72					include/generated/asm-offsets.h))
73endif
74
75ifeq ($(CONFIG_ARM64_BTI_KERNEL),y)
76  KBUILD_CFLAGS += -mbranch-protection=pac-ret+bti
77  KBUILD_RUSTFLAGS += -Zbranch-protection=bti,pac-ret
78else ifeq ($(CONFIG_ARM64_PTR_AUTH_KERNEL),y)
79  KBUILD_RUSTFLAGS += -Zbranch-protection=pac-ret
80  ifeq ($(CONFIG_CC_HAS_BRANCH_PROT_PAC_RET),y)
81    KBUILD_CFLAGS += -mbranch-protection=pac-ret
82  else
83    KBUILD_CFLAGS += -msign-return-address=non-leaf
84  endif
85else
86  KBUILD_CFLAGS += $(call cc-option,-mbranch-protection=none)
87endif
88
89# Tell the assembler to support instructions from the latest target
90# architecture.
91#
92# For non-integrated assemblers we'll pass this on the command line, and for
93# integrated assemblers we'll define ARM64_ASM_ARCH and ARM64_ASM_PREAMBLE for
94# inline usage.
95#
96# We cannot pass the same arch flag to the compiler as this would allow it to
97# freely generate instructions which are not supported by earlier architecture
98# versions, which would prevent a single kernel image from working on earlier
99# hardware.
100ifeq ($(CONFIG_AS_HAS_ARMV8_5), y)
101  asm-arch := armv8.5-a
102else ifeq ($(CONFIG_AS_HAS_ARMV8_4), y)
103  asm-arch := armv8.4-a
104else ifeq ($(CONFIG_AS_HAS_ARMV8_3), y)
105  asm-arch := armv8.3-a
106else ifeq ($(CONFIG_AS_HAS_ARMV8_2), y)
107  asm-arch := armv8.2-a
108endif
109
110ifdef asm-arch
111KBUILD_CFLAGS	+= -Wa,-march=$(asm-arch) \
112		   -DARM64_ASM_ARCH='"$(asm-arch)"'
113endif
114
115ifeq ($(CONFIG_SHADOW_CALL_STACK), y)
116KBUILD_CFLAGS	+= -ffixed-x18
117endif
118
119ifeq ($(CONFIG_CPU_BIG_ENDIAN), y)
120KBUILD_CPPFLAGS	+= -mbig-endian
121CHECKFLAGS	+= -D__AARCH64EB__
122# Prefer the baremetal ELF build target, but not all toolchains include
123# it so fall back to the standard linux version if needed.
124KBUILD_LDFLAGS	+= -EB $(call ld-option, -maarch64elfb, -maarch64linuxb -z norelro)
125UTS_MACHINE	:= aarch64_be
126else
127KBUILD_CPPFLAGS	+= -mlittle-endian
128CHECKFLAGS	+= -D__AARCH64EL__
129# Same as above, prefer ELF but fall back to linux target if needed.
130KBUILD_LDFLAGS	+= -EL $(call ld-option, -maarch64elf, -maarch64linux -z norelro)
131UTS_MACHINE	:= aarch64
132endif
133
134ifeq ($(CONFIG_LD_IS_LLD), y)
135KBUILD_LDFLAGS	+= -z norelro
136endif
137
138CHECKFLAGS	+= -D__aarch64__
139
140ifeq ($(CONFIG_DYNAMIC_FTRACE_WITH_CALL_OPS),y)
141  KBUILD_CPPFLAGS += -DCC_USING_PATCHABLE_FUNCTION_ENTRY
142  CC_FLAGS_FTRACE := -fpatchable-function-entry=4,2
143else ifeq ($(CONFIG_DYNAMIC_FTRACE_WITH_ARGS),y)
144  KBUILD_CPPFLAGS += -DCC_USING_PATCHABLE_FUNCTION_ENTRY
145  CC_FLAGS_FTRACE := -fpatchable-function-entry=2
146endif
147
148ifeq ($(CONFIG_KASAN_SW_TAGS), y)
149KASAN_SHADOW_SCALE_SHIFT := 4
150else ifeq ($(CONFIG_KASAN_GENERIC), y)
151KASAN_SHADOW_SCALE_SHIFT := 3
152endif
153
154KBUILD_CFLAGS += -DKASAN_SHADOW_SCALE_SHIFT=$(KASAN_SHADOW_SCALE_SHIFT)
155KBUILD_CPPFLAGS += -DKASAN_SHADOW_SCALE_SHIFT=$(KASAN_SHADOW_SCALE_SHIFT)
156KBUILD_AFLAGS += -DKASAN_SHADOW_SCALE_SHIFT=$(KASAN_SHADOW_SCALE_SHIFT)
157
158libs-y		:= arch/arm64/lib/ $(libs-y)
159libs-$(CONFIG_EFI_STUB) += $(objtree)/drivers/firmware/efi/libstub/lib.a
160
161# Default target when executing plain make
162boot		:= arch/arm64/boot
163
164BOOT_TARGETS	:= Image vmlinuz.efi image.fit
165
166PHONY += $(BOOT_TARGETS)
167
168ifeq ($(CONFIG_EFI_ZBOOT),)
169KBUILD_IMAGE	:= $(boot)/Image.gz
170else
171KBUILD_IMAGE	:= $(boot)/vmlinuz.efi
172endif
173
174all:	$(notdir $(KBUILD_IMAGE))
175
176image.fit: dtbs
177
178vmlinuz.efi image.fit: Image
179$(BOOT_TARGETS): vmlinux
180	$(Q)$(MAKE) $(build)=$(boot) $(boot)/$@
181
182Image.%: Image
183	$(Q)$(MAKE) $(build)=$(boot) $(boot)/$@
184
185ifeq ($(CONFIG_COMPRESSED_INSTALL),y)
186 DEFAULT_KBUILD_IMAGE = $(KBUILD_IMAGE)
187else
188 DEFAULT_KBUILD_IMAGE = $(boot)/Image
189endif
190
191install: KBUILD_IMAGE := $(DEFAULT_KBUILD_IMAGE)
192install zinstall:
193	$(call cmd,install)
194
195archprepare:
196	$(Q)$(MAKE) $(build)=arch/arm64/tools kapi
197ifeq ($(CONFIG_ARM64_ERRATUM_843419),y)
198  ifneq ($(CONFIG_ARM64_LD_HAS_FIX_ERRATUM_843419),y)
199	@echo "warning: ld does not support --fix-cortex-a53-843419; kernel may be susceptible to erratum" >&2
200  endif
201endif
202ifeq ($(CONFIG_ARM64_USE_LSE_ATOMICS),y)
203  ifneq ($(CONFIG_ARM64_LSE_ATOMICS),y)
204	@echo "warning: LSE atomics not supported by binutils" >&2
205  endif
206endif
207
208ifeq ($(KBUILD_EXTMOD),)
209# We need to generate vdso-offsets.h before compiling certain files in kernel/.
210# In order to do that, we should use the archprepare target, but we can't since
211# asm-offsets.h is included in some files used to generate vdso-offsets.h, and
212# asm-offsets.h is built in prepare0, for which archprepare is a dependency.
213# Therefore we need to generate the header after prepare0 has been made, hence
214# this hack.
215prepare: vdso_prepare
216vdso_prepare: prepare0
217	$(Q)$(MAKE) $(build)=arch/arm64/kernel/vdso \
218	include/generated/vdso-offsets.h arch/arm64/kernel/vdso/vdso.so
219ifdef CONFIG_COMPAT_VDSO
220	$(Q)$(MAKE) $(build)=arch/arm64/kernel/vdso32 \
221	arch/arm64/kernel/vdso32/vdso.so
222endif
223endif
224
225vdso-install-y				+= arch/arm64/kernel/vdso/vdso.so.dbg
226vdso-install-$(CONFIG_COMPAT_VDSO)	+= arch/arm64/kernel/vdso32/vdso32.so.dbg
227
228include $(srctree)/scripts/Makefile.defconf
229
230PHONY += virtconfig
231virtconfig:
232	$(call merge_into_defconfig_override,defconfig,virt)
233
234define archhelp
235  echo  '* Image.gz      - Compressed kernel image (arch/$(ARCH)/boot/Image.gz)'
236  echo  '  Image         - Uncompressed kernel image (arch/$(ARCH)/boot/Image)'
237  echo  '  image.fit     - Flat Image Tree (arch/$(ARCH)/boot/image.fit)'
238  echo  '  install       - Install kernel (compressed if COMPRESSED_INSTALL set)'
239  echo  '  zinstall      - Install compressed kernel'
240  echo  '                  Install using (your) ~/bin/installkernel or'
241  echo  '                  (distribution) /sbin/installkernel or'
242  echo  '                  install to $$(INSTALL_PATH) and run lilo'
243endef
244