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