xref: /kernel/linux/linux-6.6/arch/arm64/Makefile (revision 62306a36)
162306a36Sopenharmony_ci#
262306a36Sopenharmony_ci# arch/arm64/Makefile
362306a36Sopenharmony_ci#
462306a36Sopenharmony_ci# This file is included by the global makefile so that you can add your own
562306a36Sopenharmony_ci# architecture-specific flags and dependencies.
662306a36Sopenharmony_ci#
762306a36Sopenharmony_ci# This file is subject to the terms and conditions of the GNU General Public
862306a36Sopenharmony_ci# License.  See the file "COPYING" in the main directory of this archive
962306a36Sopenharmony_ci# for more details.
1062306a36Sopenharmony_ci#
1162306a36Sopenharmony_ci# Copyright (C) 1995-2001 by Russell King
1262306a36Sopenharmony_ci
1362306a36Sopenharmony_ciLDFLAGS_vmlinux	:=--no-undefined -X
1462306a36Sopenharmony_ci
1562306a36Sopenharmony_ciifeq ($(CONFIG_RELOCATABLE), y)
1662306a36Sopenharmony_ci# Pass --no-apply-dynamic-relocs to restore pre-binutils-2.27 behaviour
1762306a36Sopenharmony_ci# for relative relocs, since this leads to better Image compression
1862306a36Sopenharmony_ci# with the relocation offsets always being zero.
1962306a36Sopenharmony_ciLDFLAGS_vmlinux		+= -shared -Bsymbolic -z notext \
2062306a36Sopenharmony_ci			$(call ld-option, --no-apply-dynamic-relocs)
2162306a36Sopenharmony_ciendif
2262306a36Sopenharmony_ci
2362306a36Sopenharmony_ciifeq ($(CONFIG_ARM64_ERRATUM_843419),y)
2462306a36Sopenharmony_ci  ifeq ($(CONFIG_ARM64_LD_HAS_FIX_ERRATUM_843419),y)
2562306a36Sopenharmony_ciLDFLAGS_vmlinux	+= --fix-cortex-a53-843419
2662306a36Sopenharmony_ci  endif
2762306a36Sopenharmony_ciendif
2862306a36Sopenharmony_ci
2962306a36Sopenharmony_cicc_has_k_constraint := $(call try-run,echo				\
3062306a36Sopenharmony_ci	'int main(void) {						\
3162306a36Sopenharmony_ci		asm volatile("and w0, w0, %w0" :: "K" (4294967295));	\
3262306a36Sopenharmony_ci		return 0;						\
3362306a36Sopenharmony_ci	}' | $(CC) -S -x c -o "$$TMP" -,,-DCONFIG_CC_HAS_K_CONSTRAINT=1)
3462306a36Sopenharmony_ci
3562306a36Sopenharmony_ciifeq ($(CONFIG_BROKEN_GAS_INST),y)
3662306a36Sopenharmony_ci$(warning Detected assembler with broken .inst; disassembly will be unreliable)
3762306a36Sopenharmony_ciendif
3862306a36Sopenharmony_ci
3962306a36Sopenharmony_ciKBUILD_CFLAGS	+= -mgeneral-regs-only	\
4062306a36Sopenharmony_ci		   $(compat_vdso) $(cc_has_k_constraint)
4162306a36Sopenharmony_ciKBUILD_CFLAGS	+= $(call cc-disable-warning, psabi)
4262306a36Sopenharmony_ciKBUILD_AFLAGS	+= $(compat_vdso)
4362306a36Sopenharmony_ci
4462306a36Sopenharmony_ciKBUILD_CFLAGS	+= $(call cc-option,-mabi=lp64)
4562306a36Sopenharmony_ciKBUILD_AFLAGS	+= $(call cc-option,-mabi=lp64)
4662306a36Sopenharmony_ci
4762306a36Sopenharmony_ci# Avoid generating .eh_frame* sections.
4862306a36Sopenharmony_ciifneq ($(CONFIG_UNWIND_TABLES),y)
4962306a36Sopenharmony_ciKBUILD_CFLAGS	+= -fno-asynchronous-unwind-tables -fno-unwind-tables
5062306a36Sopenharmony_ciKBUILD_AFLAGS	+= -fno-asynchronous-unwind-tables -fno-unwind-tables
5162306a36Sopenharmony_cielse
5262306a36Sopenharmony_ciKBUILD_CFLAGS	+= -fasynchronous-unwind-tables
5362306a36Sopenharmony_ciKBUILD_AFLAGS	+= -fasynchronous-unwind-tables
5462306a36Sopenharmony_ciendif
5562306a36Sopenharmony_ci
5662306a36Sopenharmony_ciifeq ($(CONFIG_STACKPROTECTOR_PER_TASK),y)
5762306a36Sopenharmony_ciprepare: stack_protector_prepare
5862306a36Sopenharmony_cistack_protector_prepare: prepare0
5962306a36Sopenharmony_ci	$(eval KBUILD_CFLAGS += -mstack-protector-guard=sysreg		  \
6062306a36Sopenharmony_ci				-mstack-protector-guard-reg=sp_el0	  \
6162306a36Sopenharmony_ci				-mstack-protector-guard-offset=$(shell	  \
6262306a36Sopenharmony_ci			awk '{if ($$2 == "TSK_STACK_CANARY") print $$3;}' \
6362306a36Sopenharmony_ci					include/generated/asm-offsets.h))
6462306a36Sopenharmony_ciendif
6562306a36Sopenharmony_ci
6662306a36Sopenharmony_ciifeq ($(CONFIG_ARM64_BTI_KERNEL),y)
6762306a36Sopenharmony_ci  KBUILD_CFLAGS += -mbranch-protection=pac-ret+bti
6862306a36Sopenharmony_cielse ifeq ($(CONFIG_ARM64_PTR_AUTH_KERNEL),y)
6962306a36Sopenharmony_ci  ifeq ($(CONFIG_CC_HAS_BRANCH_PROT_PAC_RET),y)
7062306a36Sopenharmony_ci    KBUILD_CFLAGS += -mbranch-protection=pac-ret
7162306a36Sopenharmony_ci  else
7262306a36Sopenharmony_ci    KBUILD_CFLAGS += -msign-return-address=non-leaf
7362306a36Sopenharmony_ci  endif
7462306a36Sopenharmony_cielse
7562306a36Sopenharmony_ci  KBUILD_CFLAGS += $(call cc-option,-mbranch-protection=none)
7662306a36Sopenharmony_ciendif
7762306a36Sopenharmony_ci
7862306a36Sopenharmony_ci# Tell the assembler to support instructions from the latest target
7962306a36Sopenharmony_ci# architecture.
8062306a36Sopenharmony_ci#
8162306a36Sopenharmony_ci# For non-integrated assemblers we'll pass this on the command line, and for
8262306a36Sopenharmony_ci# integrated assemblers we'll define ARM64_ASM_ARCH and ARM64_ASM_PREAMBLE for
8362306a36Sopenharmony_ci# inline usage.
8462306a36Sopenharmony_ci#
8562306a36Sopenharmony_ci# We cannot pass the same arch flag to the compiler as this would allow it to
8662306a36Sopenharmony_ci# freely generate instructions which are not supported by earlier architecture
8762306a36Sopenharmony_ci# versions, which would prevent a single kernel image from working on earlier
8862306a36Sopenharmony_ci# hardware.
8962306a36Sopenharmony_ciifeq ($(CONFIG_AS_HAS_ARMV8_5), y)
9062306a36Sopenharmony_ci  asm-arch := armv8.5-a
9162306a36Sopenharmony_cielse ifeq ($(CONFIG_AS_HAS_ARMV8_4), y)
9262306a36Sopenharmony_ci  asm-arch := armv8.4-a
9362306a36Sopenharmony_cielse ifeq ($(CONFIG_AS_HAS_ARMV8_3), y)
9462306a36Sopenharmony_ci  asm-arch := armv8.3-a
9562306a36Sopenharmony_cielse ifeq ($(CONFIG_AS_HAS_ARMV8_2), y)
9662306a36Sopenharmony_ci  asm-arch := armv8.2-a
9762306a36Sopenharmony_ciendif
9862306a36Sopenharmony_ci
9962306a36Sopenharmony_ciifdef asm-arch
10062306a36Sopenharmony_ciKBUILD_CFLAGS	+= -Wa,-march=$(asm-arch) \
10162306a36Sopenharmony_ci		   -DARM64_ASM_ARCH='"$(asm-arch)"'
10262306a36Sopenharmony_ciendif
10362306a36Sopenharmony_ci
10462306a36Sopenharmony_ciifeq ($(CONFIG_SHADOW_CALL_STACK), y)
10562306a36Sopenharmony_ciKBUILD_CFLAGS	+= -ffixed-x18
10662306a36Sopenharmony_ciendif
10762306a36Sopenharmony_ci
10862306a36Sopenharmony_ciifeq ($(CONFIG_CPU_BIG_ENDIAN), y)
10962306a36Sopenharmony_ciKBUILD_CPPFLAGS	+= -mbig-endian
11062306a36Sopenharmony_ciCHECKFLAGS	+= -D__AARCH64EB__
11162306a36Sopenharmony_ci# Prefer the baremetal ELF build target, but not all toolchains include
11262306a36Sopenharmony_ci# it so fall back to the standard linux version if needed.
11362306a36Sopenharmony_ciKBUILD_LDFLAGS	+= -EB $(call ld-option, -maarch64elfb, -maarch64linuxb -z norelro)
11462306a36Sopenharmony_ciUTS_MACHINE	:= aarch64_be
11562306a36Sopenharmony_cielse
11662306a36Sopenharmony_ciKBUILD_CPPFLAGS	+= -mlittle-endian
11762306a36Sopenharmony_ciCHECKFLAGS	+= -D__AARCH64EL__
11862306a36Sopenharmony_ci# Same as above, prefer ELF but fall back to linux target if needed.
11962306a36Sopenharmony_ciKBUILD_LDFLAGS	+= -EL $(call ld-option, -maarch64elf, -maarch64linux -z norelro)
12062306a36Sopenharmony_ciUTS_MACHINE	:= aarch64
12162306a36Sopenharmony_ciendif
12262306a36Sopenharmony_ci
12362306a36Sopenharmony_ciifeq ($(CONFIG_LD_IS_LLD), y)
12462306a36Sopenharmony_ciKBUILD_LDFLAGS	+= -z norelro
12562306a36Sopenharmony_ciendif
12662306a36Sopenharmony_ci
12762306a36Sopenharmony_ciCHECKFLAGS	+= -D__aarch64__
12862306a36Sopenharmony_ci
12962306a36Sopenharmony_ciifeq ($(CONFIG_DYNAMIC_FTRACE_WITH_CALL_OPS),y)
13062306a36Sopenharmony_ci  KBUILD_CPPFLAGS += -DCC_USING_PATCHABLE_FUNCTION_ENTRY
13162306a36Sopenharmony_ci  CC_FLAGS_FTRACE := -fpatchable-function-entry=4,2
13262306a36Sopenharmony_cielse ifeq ($(CONFIG_DYNAMIC_FTRACE_WITH_ARGS),y)
13362306a36Sopenharmony_ci  KBUILD_CPPFLAGS += -DCC_USING_PATCHABLE_FUNCTION_ENTRY
13462306a36Sopenharmony_ci  CC_FLAGS_FTRACE := -fpatchable-function-entry=2
13562306a36Sopenharmony_ciendif
13662306a36Sopenharmony_ci
13762306a36Sopenharmony_ciifeq ($(CONFIG_KASAN_SW_TAGS), y)
13862306a36Sopenharmony_ciKASAN_SHADOW_SCALE_SHIFT := 4
13962306a36Sopenharmony_cielse ifeq ($(CONFIG_KASAN_GENERIC), y)
14062306a36Sopenharmony_ciKASAN_SHADOW_SCALE_SHIFT := 3
14162306a36Sopenharmony_ciendif
14262306a36Sopenharmony_ci
14362306a36Sopenharmony_ciKBUILD_CFLAGS += -DKASAN_SHADOW_SCALE_SHIFT=$(KASAN_SHADOW_SCALE_SHIFT)
14462306a36Sopenharmony_ciKBUILD_CPPFLAGS += -DKASAN_SHADOW_SCALE_SHIFT=$(KASAN_SHADOW_SCALE_SHIFT)
14562306a36Sopenharmony_ciKBUILD_AFLAGS += -DKASAN_SHADOW_SCALE_SHIFT=$(KASAN_SHADOW_SCALE_SHIFT)
14662306a36Sopenharmony_ci
14762306a36Sopenharmony_cilibs-y		:= arch/arm64/lib/ $(libs-y)
14862306a36Sopenharmony_cilibs-$(CONFIG_EFI_STUB) += $(objtree)/drivers/firmware/efi/libstub/lib.a
14962306a36Sopenharmony_ci
15062306a36Sopenharmony_ci# Default target when executing plain make
15162306a36Sopenharmony_ciboot		:= arch/arm64/boot
15262306a36Sopenharmony_ci
15362306a36Sopenharmony_ciifeq ($(CONFIG_EFI_ZBOOT),)
15462306a36Sopenharmony_ciKBUILD_IMAGE	:= $(boot)/Image.gz
15562306a36Sopenharmony_cielse
15662306a36Sopenharmony_ciKBUILD_IMAGE	:= $(boot)/vmlinuz.efi
15762306a36Sopenharmony_ciendif
15862306a36Sopenharmony_ci
15962306a36Sopenharmony_ciall:	$(notdir $(KBUILD_IMAGE))
16062306a36Sopenharmony_ci
16162306a36Sopenharmony_civmlinuz.efi: Image
16262306a36Sopenharmony_ciImage vmlinuz.efi: vmlinux
16362306a36Sopenharmony_ci	$(Q)$(MAKE) $(build)=$(boot) $(boot)/$@
16462306a36Sopenharmony_ci
16562306a36Sopenharmony_ciImage.%: Image
16662306a36Sopenharmony_ci	$(Q)$(MAKE) $(build)=$(boot) $(boot)/$@
16762306a36Sopenharmony_ci
16862306a36Sopenharmony_ciinstall: KBUILD_IMAGE := $(boot)/Image
16962306a36Sopenharmony_ciinstall zinstall:
17062306a36Sopenharmony_ci	$(call cmd,install)
17162306a36Sopenharmony_ci
17262306a36Sopenharmony_ciPHONY += vdso_install
17362306a36Sopenharmony_civdso_install:
17462306a36Sopenharmony_ci	$(Q)$(MAKE) $(build)=arch/arm64/kernel/vdso $@
17562306a36Sopenharmony_ci	$(if $(CONFIG_COMPAT_VDSO), \
17662306a36Sopenharmony_ci		$(Q)$(MAKE) $(build)=arch/arm64/kernel/vdso32 $@)
17762306a36Sopenharmony_ci
17862306a36Sopenharmony_ciarchprepare:
17962306a36Sopenharmony_ci	$(Q)$(MAKE) $(build)=arch/arm64/tools kapi
18062306a36Sopenharmony_ciifeq ($(CONFIG_ARM64_ERRATUM_843419),y)
18162306a36Sopenharmony_ci  ifneq ($(CONFIG_ARM64_LD_HAS_FIX_ERRATUM_843419),y)
18262306a36Sopenharmony_ci	@echo "warning: ld does not support --fix-cortex-a53-843419; kernel may be susceptible to erratum" >&2
18362306a36Sopenharmony_ci  endif
18462306a36Sopenharmony_ciendif
18562306a36Sopenharmony_ciifeq ($(CONFIG_ARM64_USE_LSE_ATOMICS),y)
18662306a36Sopenharmony_ci  ifneq ($(CONFIG_ARM64_LSE_ATOMICS),y)
18762306a36Sopenharmony_ci	@echo "warning: LSE atomics not supported by binutils" >&2
18862306a36Sopenharmony_ci  endif
18962306a36Sopenharmony_ciendif
19062306a36Sopenharmony_ci
19162306a36Sopenharmony_ciifeq ($(KBUILD_EXTMOD),)
19262306a36Sopenharmony_ci# We need to generate vdso-offsets.h before compiling certain files in kernel/.
19362306a36Sopenharmony_ci# In order to do that, we should use the archprepare target, but we can't since
19462306a36Sopenharmony_ci# asm-offsets.h is included in some files used to generate vdso-offsets.h, and
19562306a36Sopenharmony_ci# asm-offsets.h is built in prepare0, for which archprepare is a dependency.
19662306a36Sopenharmony_ci# Therefore we need to generate the header after prepare0 has been made, hence
19762306a36Sopenharmony_ci# this hack.
19862306a36Sopenharmony_ciprepare: vdso_prepare
19962306a36Sopenharmony_civdso_prepare: prepare0
20062306a36Sopenharmony_ci	$(Q)$(MAKE) $(build)=arch/arm64/kernel/vdso \
20162306a36Sopenharmony_ci	include/generated/vdso-offsets.h arch/arm64/kernel/vdso/vdso.so
20262306a36Sopenharmony_ciifdef CONFIG_COMPAT_VDSO
20362306a36Sopenharmony_ci	$(Q)$(MAKE) $(build)=arch/arm64/kernel/vdso32 \
20462306a36Sopenharmony_ci	include/generated/vdso32-offsets.h arch/arm64/kernel/vdso32/vdso.so
20562306a36Sopenharmony_ciendif
20662306a36Sopenharmony_ciendif
20762306a36Sopenharmony_ci
20862306a36Sopenharmony_ciinclude $(srctree)/scripts/Makefile.defconf
20962306a36Sopenharmony_ci
21062306a36Sopenharmony_ciPHONY += virtconfig
21162306a36Sopenharmony_civirtconfig:
21262306a36Sopenharmony_ci	$(call merge_into_defconfig_override,defconfig,virt)
21362306a36Sopenharmony_ci
21462306a36Sopenharmony_cidefine archhelp
21562306a36Sopenharmony_ci  echo  '* Image.gz      - Compressed kernel image (arch/$(ARCH)/boot/Image.gz)'
21662306a36Sopenharmony_ci  echo  '  Image         - Uncompressed kernel image (arch/$(ARCH)/boot/Image)'
21762306a36Sopenharmony_ci  echo  '  install       - Install uncompressed kernel'
21862306a36Sopenharmony_ci  echo  '  zinstall      - Install compressed kernel'
21962306a36Sopenharmony_ci  echo  '                  Install using (your) ~/bin/installkernel or'
22062306a36Sopenharmony_ci  echo  '                  (distribution) /sbin/installkernel or'
22162306a36Sopenharmony_ci  echo  '                  install to $$(INSTALL_PATH) and run lilo'
22262306a36Sopenharmony_ciendef
223