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