blob: d62bd221828f79f5a5503824837eab939a1aef15 [file] [log] [blame]
Catalin Marinas8c2c3df2012-04-20 14:45:54 +01001#
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
Nick Desaulniers311bea32020-12-17 16:24:32 -080013LDFLAGS_vmlinux :=--no-undefined -X
Catalin Marinas8c2c3df2012-04-20 14:45:54 +010014
Nick Desaulniersfd9dde62017-10-27 09:33:41 -070015ifeq ($(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.
Nick Desaulniers3b92fa72020-10-16 10:53:39 -070019LDFLAGS_vmlinux += -shared -Bsymbolic -z notext \
Nick Desaulniersfd9dde62017-10-27 09:33:41 -070020 $(call ld-option, --no-apply-dynamic-relocs)
Ard Biesheuvel1e48ef72016-01-26 09:13:44 +010021endif
22
Will Deacon6ffe9922016-08-22 11:58:36 +010023ifeq ($(CONFIG_ARM64_ERRATUM_843419),y)
Masahiro Yamada64ee84c2021-08-01 14:35:25 +090024 ifeq ($(CONFIG_ARM64_LD_HAS_FIX_ERRATUM_843419),y)
Will Deacon6ffe9922016-08-22 11:58:36 +010025LDFLAGS_vmlinux += --fix-cortex-a53-843419
26 endif
27endif
28
Will Deacon03adcbd2019-08-29 14:34:42 +010029cc_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
Vladimir Murzin8bf92842020-01-15 14:18:25 +000035ifeq ($(CONFIG_BROKEN_GAS_INST),y)
Marc Zyngierbbb56c22016-12-06 15:27:43 +000036$(warning Detected assembler with broken .inst; disassembly will be unreliable)
37endif
38
Vladimir Murzin8bf92842020-01-15 14:18:25 +000039KBUILD_CFLAGS += -mgeneral-regs-only \
Will Deacon03adcbd2019-08-29 14:34:42 +010040 $(compat_vdso) $(cc_has_k_constraint)
Nathan Chancellorfa63da22019-06-11 10:19:32 -070041KBUILD_CFLAGS += $(call cc-disable-warning, psabi)
Vladimir Murzin8bf92842020-01-15 14:18:25 +000042KBUILD_AFLAGS += $(compat_vdso)
Will Deaconc09d6a02015-02-03 16:14:13 +000043
Andrew Pinski3d6a7b92017-09-18 11:20:20 +010044KBUILD_CFLAGS += $(call cc-option,-mabi=lp64)
45KBUILD_AFLAGS += $(call cc-option,-mabi=lp64)
46
Kees Cook6e0a66d2020-08-21 12:42:51 -070047# Avoid generating .eh_frame* sections.
Ard Biesheuvel68c76ad2022-10-27 17:59:06 +020048ifneq ($(CONFIG_UNWIND_TABLES),y)
Kees Cook6e0a66d2020-08-21 12:42:51 -070049KBUILD_CFLAGS += -fno-asynchronous-unwind-tables -fno-unwind-tables
50KBUILD_AFLAGS += -fno-asynchronous-unwind-tables -fno-unwind-tables
Ard Biesheuvel68c76ad2022-10-27 17:59:06 +020051else
52KBUILD_CFLAGS += -fasynchronous-unwind-tables
53KBUILD_AFLAGS += -fasynchronous-unwind-tables
54endif
Kees Cook6e0a66d2020-08-21 12:42:51 -070055
Ard Biesheuvel0a1213f2018-12-12 13:08:44 +010056ifeq ($(CONFIG_STACKPROTECTOR_PER_TASK),y)
57prepare: stack_protector_prepare
58stack_protector_prepare: prepare0
59 $(eval KBUILD_CFLAGS += -mstack-protector-guard=sysreg \
60 -mstack-protector-guard-reg=sp_el0 \
61 -mstack-protector-guard-offset=$(shell \
62 awk '{if ($$2 == "TSK_STACK_CANARY") print $$3;}' \
63 include/generated/asm-offsets.h))
64endif
65
Ard Biesheuvel2c54b422021-12-13 15:02:52 +010066ifeq ($(CONFIG_AS_HAS_ARMV8_2), y)
67# make sure to pass the newest target architecture to -march.
68asm-arch := armv8.2-a
69endif
70
Mark Brownb8fdef32020-03-31 20:44:59 +010071# Ensure that if the compiler supports branch protection we default it
72# off, this will be overridden if we are using branch protection.
73branch-prot-flags-y += $(call cc-option,-mbranch-protection=none)
74
Daniel Kissb27a9f42021-06-13 11:26:31 +020075ifeq ($(CONFIG_ARM64_PTR_AUTH_KERNEL),y)
Kristina Martsenko74afda42020-03-13 14:35:03 +053076branch-prot-flags-$(CONFIG_CC_HAS_SIGN_RETURN_ADDRESS) := -msign-return-address=all
Mark Brown717b9382020-05-06 20:51:28 +010077# We enable additional protection for leaf functions as there is some
78# narrow potential for ROP protection benefits and no substantial
79# performance impact has been observed.
Ard Biesheuvel3b619e22022-10-27 17:59:08 +020080PACRET-y := pac-ret+leaf
81
82# Using a shadow call stack in leaf functions is too costly, so avoid PAC there
83# as well when we may be patching PAC into SCS
84PACRET-$(CONFIG_UNWIND_PATCH_PAC_INTO_SCS) := pac-ret
85
Mark Brown92e22942020-05-06 20:51:29 +010086ifeq ($(CONFIG_ARM64_BTI_KERNEL),y)
Ard Biesheuvel3b619e22022-10-27 17:59:08 +020087branch-prot-flags-$(CONFIG_CC_HAS_BRANCH_PROT_PAC_RET_BTI) := -mbranch-protection=$(PACRET-y)+bti
Mark Brown92e22942020-05-06 20:51:29 +010088else
Ard Biesheuvel3b619e22022-10-27 17:59:08 +020089branch-prot-flags-$(CONFIG_CC_HAS_BRANCH_PROT_PAC_RET) := -mbranch-protection=$(PACRET-y)
Mark Brown92e22942020-05-06 20:51:29 +010090endif
Kristina Martsenko74afda42020-03-13 14:35:03 +053091# -march=armv8.3-a enables the non-nops instructions for PAC, to avoid the
92# compiler to generate them and consequently to break the single image contract
93# we pass it only to the assembler. This option is utilized only in case of non
94# integrated assemblers.
Sami Tolvanen1764c3e2020-08-27 13:36:08 -070095ifeq ($(CONFIG_AS_HAS_PAC), y)
96asm-arch := armv8.3-a
Kristina Martsenko74afda42020-03-13 14:35:03 +053097endif
Zhenyu Ye7c78f672020-07-15 15:19:44 +080098endif
Kristina Martsenko74afda42020-03-13 14:35:03 +053099
Mark Brownb8fdef32020-03-31 20:44:59 +0100100KBUILD_CFLAGS += $(branch-prot-flags-y)
101
Zhenyu Ye7c78f672020-07-15 15:19:44 +0800102ifeq ($(CONFIG_AS_HAS_ARMV8_4), y)
103# make sure to pass the newest target architecture to -march.
Sami Tolvanen1764c3e2020-08-27 13:36:08 -0700104asm-arch := armv8.4-a
105endif
106
Vincenzo Frascinof469c032020-12-22 12:01:24 -0800107ifeq ($(CONFIG_AS_HAS_ARMV8_5), y)
108# make sure to pass the newest target architecture to -march.
109asm-arch := armv8.5-a
110endif
111
Sami Tolvanen1764c3e2020-08-27 13:36:08 -0700112ifdef asm-arch
113KBUILD_CFLAGS += -Wa,-march=$(asm-arch) \
114 -DARM64_ASM_ARCH='"$(asm-arch)"'
Zhenyu Ye7c78f672020-07-15 15:19:44 +0800115endif
116
Sami Tolvanenda64e9d2020-04-27 09:00:11 -0700117ifeq ($(CONFIG_SHADOW_CALL_STACK), y)
118KBUILD_CFLAGS += -ffixed-x18
119endif
120
Will Deacona0974e62013-10-11 14:52:08 +0100121ifeq ($(CONFIG_CPU_BIG_ENDIAN), y)
122KBUILD_CPPFLAGS += -mbig-endian
Luc Van Oostenryckbcde5192017-06-24 17:42:11 +0200123CHECKFLAGS += -D__AARCH64EB__
Olof Johanssonc931d342018-07-13 08:30:33 -0700124# Prefer the baremetal ELF build target, but not all toolchains include
125# it so fall back to the standard linux version if needed.
Nick Desaulniers311bea32020-12-17 16:24:32 -0800126KBUILD_LDFLAGS += -EB $(call ld-option, -maarch64elfb, -maarch64linuxb -z norelro)
Michal Marekcfa88c72016-08-30 10:31:35 +0200127UTS_MACHINE := aarch64_be
Will Deacona0974e62013-10-11 14:52:08 +0100128else
Catalin Marinas8c2c3df2012-04-20 14:45:54 +0100129KBUILD_CPPFLAGS += -mlittle-endian
Luc Van Oostenryckbcde5192017-06-24 17:42:11 +0200130CHECKFLAGS += -D__AARCH64EL__
Olof Johanssonc931d342018-07-13 08:30:33 -0700131# Same as above, prefer ELF but fall back to linux target if needed.
Nick Desaulniers311bea32020-12-17 16:24:32 -0800132KBUILD_LDFLAGS += -EL $(call ld-option, -maarch64elf, -maarch64linux -z norelro)
Michal Marekcfa88c72016-08-30 10:31:35 +0200133UTS_MACHINE := aarch64
Will Deacona0974e62013-10-11 14:52:08 +0100134endif
Catalin Marinas8c2c3df2012-04-20 14:45:54 +0100135
Nick Desaulniers311bea32020-12-17 16:24:32 -0800136ifeq ($(CONFIG_LD_IS_LLD), y)
137KBUILD_LDFLAGS += -z norelro
138endif
139
Luc Van Oostenryck1f2f01b2018-05-30 22:48:38 +0200140CHECKFLAGS += -D__aarch64__
Catalin Marinas8c2c3df2012-04-20 14:45:54 +0100141
Mark Rutland26299b32022-11-03 17:05:20 +0000142ifeq ($(CONFIG_DYNAMIC_FTRACE_WITH_ARGS),y)
Torsten Duwe3b23e4992019-02-08 16:10:19 +0100143 KBUILD_CPPFLAGS += -DCC_USING_PATCHABLE_FUNCTION_ENTRY
144 CC_FLAGS_FTRACE := -fpatchable-function-entry=2
145endif
146
Andrey Konovalovb2f557e2018-12-28 00:29:57 -0800147ifeq ($(CONFIG_KASAN_SW_TAGS), y)
148KASAN_SHADOW_SCALE_SHIFT := 4
Andrey Konovalov0fea6e92020-12-22 12:02:06 -0800149else ifeq ($(CONFIG_KASAN_GENERIC), y)
Andrey Konovalovb2f557e2018-12-28 00:29:57 -0800150KASAN_SHADOW_SCALE_SHIFT := 3
151endif
152
153KBUILD_CFLAGS += -DKASAN_SHADOW_SCALE_SHIFT=$(KASAN_SHADOW_SCALE_SHIFT)
154KBUILD_CPPFLAGS += -DKASAN_SHADOW_SCALE_SHIFT=$(KASAN_SHADOW_SCALE_SHIFT)
155KBUILD_AFLAGS += -DKASAN_SHADOW_SCALE_SHIFT=$(KASAN_SHADOW_SCALE_SHIFT)
156
Catalin Marinas8c2c3df2012-04-20 14:45:54 +0100157libs-y := arch/arm64/lib/ $(libs-y)
Masahiro Yamadac1aac642020-06-04 11:20:30 +0900158libs-$(CONFIG_EFI_STUB) += $(objtree)/drivers/firmware/efi/libstub/lib.a
Catalin Marinas8c2c3df2012-04-20 14:45:54 +0100159
160# Default target when executing plain make
Michal Marek06995802016-11-22 22:34:29 +0100161boot := arch/arm64/boot
Ard Biesheuvelc37b830f2022-05-02 01:10:03 +0200162
163ifeq ($(CONFIG_EFI_ZBOOT),)
Michal Marek06995802016-11-22 22:34:29 +0100164KBUILD_IMAGE := $(boot)/Image.gz
Ard Biesheuvelc37b830f2022-05-02 01:10:03 +0200165else
166KBUILD_IMAGE := $(boot)/vmlinuz.efi
167endif
Catalin Marinas8c2c3df2012-04-20 14:45:54 +0100168
Ard Biesheuvelc37b830f2022-05-02 01:10:03 +0200169all: $(notdir $(KBUILD_IMAGE))
Catalin Marinas8c2c3df2012-04-20 14:45:54 +0100170
Catalin Marinas8c2c3df2012-04-20 14:45:54 +0100171
Ard Biesheuvelc37b830f2022-05-02 01:10:03 +0200172Image vmlinuz.efi: vmlinux
Olof Johansson0723c052015-07-16 21:26:16 +0100173 $(Q)$(MAKE) $(build)=$(boot) $(boot)/$@
174
Masahiro Yamada9ca4e582016-06-21 10:44:00 +0900175Image.%: Image
Rob Herring70f915a2012-12-03 17:17:21 -0600176 $(Q)$(MAKE) $(build)=$(boot) $(boot)/$@
Catalin Marinas8c2c3df2012-04-20 14:45:54 +0100177
Masahiro Yamadaf774f5b2022-05-03 11:47:16 +0900178install: KBUILD_IMAGE := $(boot)/Image
Masahiro Yamada70a40392021-07-29 23:05:27 +0900179install zinstall:
Masahiro Yamadaf774f5b2022-05-03 11:47:16 +0900180 $(call cmd,install)
Catalin Marinas8c2c3df2012-04-20 14:45:54 +0100181
Kyle McMartin3c017422013-06-16 20:32:44 +0100182PHONY += vdso_install
183vdso_install:
184 $(Q)$(MAKE) $(build)=arch/arm64/kernel/vdso $@
Frank van der Linden5d28ba52020-08-27 23:40:12 +0000185 $(if $(CONFIG_COMPAT_VDSO), \
186 $(Q)$(MAKE) $(build)=arch/arm64/kernel/vdso32 $@)
Kyle McMartin3c017422013-06-16 20:32:44 +0100187
Mark Brown0c6c2d32021-04-28 13:12:31 +0100188archprepare:
189 $(Q)$(MAKE) $(build)=arch/arm64/tools kapi
Masahiro Yamada64ee84c2021-08-01 14:35:25 +0900190ifeq ($(CONFIG_ARM64_ERRATUM_843419),y)
191 ifneq ($(CONFIG_ARM64_LD_HAS_FIX_ERRATUM_843419),y)
192 @echo "warning: ld does not support --fix-cortex-a53-843419; kernel may be susceptible to erratum" >&2
193 endif
194endif
195ifeq ($(CONFIG_ARM64_USE_LSE_ATOMICS),y)
196 ifneq ($(CONFIG_ARM64_LSE_ATOMICS),y)
197 @echo "warning: LSE atomics not supported by binutils" >&2
198 endif
199endif
200
Victor Kamensky98356eb2018-10-30 16:37:10 -0700201ifeq ($(KBUILD_EXTMOD),)
Kevin Brodskya66649d2016-05-12 17:39:15 +0100202# We need to generate vdso-offsets.h before compiling certain files in kernel/.
203# In order to do that, we should use the archprepare target, but we can't since
204# asm-offsets.h is included in some files used to generate vdso-offsets.h, and
205# asm-offsets.h is built in prepare0, for which archprepare is a dependency.
206# Therefore we need to generate the header after prepare0 has been made, hence
207# this hack.
208prepare: vdso_prepare
209vdso_prepare: prepare0
Masahiro Yamadaa5b8ca972020-12-18 11:45:40 +0900210 $(Q)$(MAKE) $(build)=arch/arm64/kernel/vdso \
211 include/generated/vdso-offsets.h arch/arm64/kernel/vdso/vdso.so
212ifdef CONFIG_COMPAT_VDSO
213 $(Q)$(MAKE) $(build)=arch/arm64/kernel/vdso32 \
214 include/generated/vdso32-offsets.h arch/arm64/kernel/vdso32/vdso.so
215endif
Victor Kamensky98356eb2018-10-30 16:37:10 -0700216endif
Kevin Brodskya66649d2016-05-12 17:39:15 +0100217
Catalin Marinas8c2c3df2012-04-20 14:45:54 +0100218define archhelp
219 echo '* Image.gz - Compressed kernel image (arch/$(ARCH)/boot/Image.gz)'
220 echo ' Image - Uncompressed kernel image (arch/$(ARCH)/boot/Image)'
Catalin Marinas8c2c3df2012-04-20 14:45:54 +0100221 echo ' install - Install uncompressed kernel'
222 echo ' zinstall - Install compressed kernel'
223 echo ' Install using (your) ~/bin/installkernel or'
224 echo ' (distribution) /sbin/installkernel or'
225 echo ' install to $$(INSTALL_PATH) and run lilo'
226endef