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 66endif 67 68ifeq ($(CONFIG_STACKPROTECTOR_PER_TASK),y) 69prepare: stack_protector_prepare 70stack_protector_prepare: prepare0 71 $(eval KBUILD_CFLAGS += -mstack-protector-guard=sysreg \ 72 -mstack-protector-guard-reg=sp_el0 \ 73 -mstack-protector-guard-offset=$(shell \ 74 awk '{if ($$2 == "TSK_STACK_CANARY") print $$3;}' \ 75 $(objtree)/include/generated/asm-offsets.h)) 76endif 77 78ifeq ($(CONFIG_ARM64_BTI_KERNEL),y) 79 KBUILD_CFLAGS += -mbranch-protection=pac-ret+bti 80 KBUILD_RUSTFLAGS += -Zbranch-protection=bti,pac-ret 81else ifeq ($(CONFIG_ARM64_PTR_AUTH_KERNEL),y) 82 KBUILD_RUSTFLAGS += -Zbranch-protection=pac-ret 83 ifeq ($(CONFIG_CC_HAS_BRANCH_PROT_PAC_RET),y) 84 KBUILD_CFLAGS += -mbranch-protection=pac-ret 85 else 86 KBUILD_CFLAGS += -msign-return-address=non-leaf 87 endif 88else 89 KBUILD_CFLAGS += $(call cc-option,-mbranch-protection=none) 90endif 91 92# Tell the assembler to support instructions from the latest target 93# architecture. 94# 95# For non-integrated assemblers we'll pass this on the command line, and for 96# integrated assemblers we'll define ARM64_ASM_ARCH and ARM64_ASM_PREAMBLE for 97# inline usage. 98# 99# We cannot pass the same arch flag to the compiler as this would allow it to 100# freely generate instructions which are not supported by earlier architecture 101# versions, which would prevent a single kernel image from working on earlier 102# hardware. 103ifeq ($(CONFIG_AS_HAS_ARMV8_5), y) 104 asm-arch := armv8.5-a 105else 106 asm-arch := armv8.4-a 107endif 108 109ifdef asm-arch 110KBUILD_CFLAGS += -Wa,-march=$(asm-arch) \ 111 -DARM64_ASM_ARCH='"$(asm-arch)"' 112endif 113 114ifeq ($(CONFIG_SHADOW_CALL_STACK), y) 115KBUILD_CFLAGS += -ffixed-x18 116KBUILD_RUSTFLAGS += -Zfixed-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 197 198ifeq ($(KBUILD_EXTMOD),) 199# We need to generate vdso-offsets.h before compiling certain files in kernel/. 200# In order to do that, we should use the archprepare target, but we can't since 201# asm-offsets.h is included in some files used to generate vdso-offsets.h, and 202# asm-offsets.h is built in prepare0, for which archprepare is a dependency. 203# Therefore we need to generate the header after prepare0 has been made, hence 204# this hack. 205prepare: vdso_prepare 206vdso_prepare: prepare0 207 $(Q)$(MAKE) $(build)=arch/arm64/kernel/vdso \ 208 include/generated/vdso-offsets.h arch/arm64/kernel/vdso/vdso.so 209ifdef CONFIG_COMPAT_VDSO 210 $(Q)$(MAKE) $(build)=arch/arm64/kernel/vdso32 \ 211 arch/arm64/kernel/vdso32/vdso.so 212endif 213endif 214 215vdso-install-y += arch/arm64/kernel/vdso/vdso.so.dbg 216vdso-install-$(CONFIG_COMPAT_VDSO) += arch/arm64/kernel/vdso32/vdso32.so.dbg 217 218include $(srctree)/scripts/Makefile.defconf 219 220PHONY += virtconfig 221virtconfig: 222 $(call merge_into_defconfig_override,defconfig,virt) 223 224define archhelp 225 echo '* Image.gz - Compressed kernel image (arch/$(ARCH)/boot/Image.gz)' 226 echo ' Image - Uncompressed kernel image (arch/$(ARCH)/boot/Image)' 227 echo ' image.fit - Flat Image Tree (arch/$(ARCH)/boot/image.fit)' 228 echo ' install - Install kernel (compressed if COMPRESSED_INSTALL set)' 229 echo ' zinstall - Install compressed kernel' 230 echo ' Install using (your) ~/bin/installkernel or' 231 echo ' (distribution) /sbin/installkernel or' 232 echo ' install to $$(INSTALL_PATH) and run lilo' 233endef 234