| 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 |
|
| 13 |
LDFLAGS_vmlinux :=--no-undefined -X --pic-veneer |
| 14 |
|
| 15 |
ifeq ($(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. |
| 19 |
LDFLAGS_vmlinux += -shared -Bsymbolic -z notext --no-apply-dynamic-relocs |
| 20 |
endif |
| 21 |
|
| 22 |
ifeq ($(CONFIG_ARM64_ERRATUM_843419),y) |
| 23 |
LDFLAGS_vmlinux += --fix-cortex-a53-843419 |
| 24 |
endif |
| 25 |
|
| 26 |
cc_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 |
|
| 32 |
ifeq ($(CONFIG_BROKEN_GAS_INST),y) |
| 33 |
$(warning Detected assembler with broken .inst; disassembly will be unreliable) |
| 34 |
endif |
| 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) |
| 38 |
CC_FLAGS_FPU := -ffreestanding |
| 39 |
# Enable <arm_neon.h> |
| 40 |
CC_FLAGS_FPU += -isystem $(shell $(CC) -print-file-name=include) |
| 41 |
CC_FLAGS_NO_FPU := -mgeneral-regs-only |
| 42 |
|
| 43 |
KBUILD_CFLAGS += $(CC_FLAGS_NO_FPU) \ |
| 44 |
$(compat_vdso) $(cc_has_k_constraint) |
| 45 |
KBUILD_CFLAGS += $(call cc-disable-warning, psabi) |
| 46 |
KBUILD_AFLAGS += $(compat_vdso) |
| 47 |
|
| 48 |
ifeq ($(call rustc-min-version, 108500),y) |
| 49 |
KBUILD_RUSTFLAGS += --target=aarch64-unknown-none-softfloat |
| 50 |
else |
| 51 |
KBUILD_RUSTFLAGS += --target=aarch64-unknown-none -Ctarget-feature="-neon" |
| 52 |
endif |
| 53 |
|
| 54 |
KBUILD_CFLAGS += $(call cc-option,-mabi=lp64) |
| 55 |
KBUILD_AFLAGS += $(call cc-option,-mabi=lp64) |
| 56 |
|
| 57 |
# Avoid generating .eh_frame* sections. |
| 58 |
ifneq ($(CONFIG_UNWIND_TABLES),y) |
| 59 |
KBUILD_CFLAGS += -fno-asynchronous-unwind-tables -fno-unwind-tables |
| 60 |
KBUILD_AFLAGS += -fno-asynchronous-unwind-tables -fno-unwind-tables |
| 61 |
KBUILD_RUSTFLAGS += -Cforce-unwind-tables=n |
| 62 |
else |
| 63 |
KBUILD_CFLAGS += -fasynchronous-unwind-tables |
| 64 |
KBUILD_AFLAGS += -fasynchronous-unwind-tables |
| 65 |
KBUILD_RUSTFLAGS += -Cforce-unwind-tables=y -Zuse-sync-unwind=n |
| 66 |
endif |
| 67 |
|
| 68 |
ifeq ($(CONFIG_STACKPROTECTOR_PER_TASK),y) |
| 69 |
prepare: stack_protector_prepare |
| 70 |
stack_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)) |
| 76 |
endif |
| 77 |
|
| 78 |
ifeq ($(CONFIG_ARM64_BTI_KERNEL),y) |
| 79 |
KBUILD_CFLAGS += -mbranch-protection=pac-ret+bti |
| 80 |
KBUILD_RUSTFLAGS += -Zbranch-protection=bti,pac-ret |
| 81 |
else 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 |
| 88 |
else |
| 89 |
KBUILD_CFLAGS += $(call cc-option,-mbranch-protection=none) |
| 90 |
endif |
| 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. |
| 103 |
ifeq ($(CONFIG_AS_HAS_ARMV8_5), y) |
| 104 |
asm-arch := armv8.5-a |
| 105 |
else |
| 106 |
asm-arch := armv8.4-a |
| 107 |
endif |
| 108 |
|
| 109 |
ifdef asm-arch |
| 110 |
KBUILD_CFLAGS += -Wa,-march=$(asm-arch) \ |
| 111 |
-DARM64_ASM_ARCH='"$(asm-arch)"' |
| 112 |
endif |
| 113 |
|
| 114 |
ifeq ($(CONFIG_SHADOW_CALL_STACK), y) |
| 115 |
KBUILD_CFLAGS += -ffixed-x18 |
| 116 |
KBUILD_RUSTFLAGS += -Zfixed-x18 |
| 117 |
endif |
| 118 |
|
| 119 |
ifeq ($(CONFIG_CPU_BIG_ENDIAN), y) |
| 120 |
KBUILD_CPPFLAGS += -mbig-endian |
| 121 |
CHECKFLAGS += -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. |
| 124 |
KBUILD_LDFLAGS += -EB $(call ld-option, -maarch64elfb, -maarch64linuxb -z norelro) |
| 125 |
UTS_MACHINE := aarch64_be |
| 126 |
else |
| 127 |
KBUILD_CPPFLAGS += -mlittle-endian |
| 128 |
CHECKFLAGS += -D__AARCH64EL__ |
| 129 |
# Same as above, prefer ELF but fall back to linux target if needed. |
| 130 |
KBUILD_LDFLAGS += -EL $(call ld-option, -maarch64elf, -maarch64linux -z norelro) |
| 131 |
UTS_MACHINE := aarch64 |
| 132 |
endif |
| 133 |
|
| 134 |
ifeq ($(CONFIG_LD_IS_LLD), y) |
| 135 |
KBUILD_LDFLAGS += -z norelro |
| 136 |
endif |
| 137 |
|
| 138 |
CHECKFLAGS += -D__aarch64__ |
| 139 |
|
| 140 |
ifeq ($(CONFIG_DYNAMIC_FTRACE_WITH_CALL_OPS),y) |
| 141 |
KBUILD_CPPFLAGS += -DCC_USING_PATCHABLE_FUNCTION_ENTRY |
| 142 |
CC_FLAGS_FTRACE := -fpatchable-function-entry=4,2 |
| 143 |
else ifeq ($(CONFIG_DYNAMIC_FTRACE_WITH_ARGS),y) |
| 144 |
KBUILD_CPPFLAGS += -DCC_USING_PATCHABLE_FUNCTION_ENTRY |
| 145 |
CC_FLAGS_FTRACE := -fpatchable-function-entry=2 |
| 146 |
endif |
| 147 |
|
| 148 |
ifeq ($(CONFIG_KASAN_SW_TAGS), y) |
| 149 |
KASAN_SHADOW_SCALE_SHIFT := 4 |
| 150 |
else ifeq ($(CONFIG_KASAN_GENERIC), y) |
| 151 |
KASAN_SHADOW_SCALE_SHIFT := 3 |
| 152 |
endif |
| 153 |
|
| 154 |
KBUILD_CFLAGS += -DKASAN_SHADOW_SCALE_SHIFT=$(KASAN_SHADOW_SCALE_SHIFT) |
| 155 |
KBUILD_CPPFLAGS += -DKASAN_SHADOW_SCALE_SHIFT=$(KASAN_SHADOW_SCALE_SHIFT) |
| 156 |
KBUILD_AFLAGS += -DKASAN_SHADOW_SCALE_SHIFT=$(KASAN_SHADOW_SCALE_SHIFT) |
| 157 |
|
| 158 |
libs-y := arch/arm64/lib/ $(libs-y) |
| 159 |
libs-$(CONFIG_EFI_STUB) += $(objtree)/drivers/firmware/efi/libstub/lib.a |
| 160 |
|
| 161 |
# Default target when executing plain make |
| 162 |
boot := arch/arm64/boot |
| 163 |
|
| 164 |
BOOT_TARGETS := Image vmlinuz.efi image.fit |
| 165 |
|
| 166 |
PHONY += $(BOOT_TARGETS) |
| 167 |
|
| 168 |
ifeq ($(CONFIG_EFI_ZBOOT),) |
| 169 |
KBUILD_IMAGE := $(boot)/Image.gz |
| 170 |
else |
| 171 |
KBUILD_IMAGE := $(boot)/vmlinuz.efi |
| 172 |
endif |
| 173 |
|
| 174 |
all: $(notdir $(KBUILD_IMAGE)) |
| 175 |
|
| 176 |
image.fit: dtbs |
| 177 |
|
| 178 |
vmlinuz.efi image.fit: Image |
| 179 |
$(BOOT_TARGETS): vmlinux |
| 180 |
$(Q)$(MAKE) $(build)=$(boot) $(boot)/$@ |
| 181 |
|
| 182 |
Image.%: Image |
| 183 |
$(Q)$(MAKE) $(build)=$(boot) $(boot)/$@ |
| 184 |
|
| 185 |
ifeq ($(CONFIG_COMPRESSED_INSTALL),y) |
| 186 |
DEFAULT_KBUILD_IMAGE = $(KBUILD_IMAGE) |
| 187 |
else |
| 188 |
DEFAULT_KBUILD_IMAGE = $(boot)/Image |
| 189 |
endif |
| 190 |
|
| 191 |
install: KBUILD_IMAGE := $(DEFAULT_KBUILD_IMAGE) |
| 192 |
install zinstall: |
| 193 |
$(call cmd,install) |
| 194 |
|
| 195 |
archprepare: |
| 196 |
$(Q)$(MAKE) $(build)=arch/arm64/tools kapi |
| 197 |
|
| 198 |
ifeq ($(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. |
| 205 |
prepare: vdso_prepare |
| 206 |
vdso_prepare: prepare0 |
| 207 |
$(Q)$(MAKE) $(build)=arch/arm64/kernel/vdso \ |
| 208 |
include/generated/vdso-offsets.h arch/arm64/kernel/vdso/vdso.so |
| 209 |
ifdef CONFIG_COMPAT_VDSO |
| 210 |
$(Q)$(MAKE) $(build)=arch/arm64/kernel/vdso32 \ |
| 211 |
arch/arm64/kernel/vdso32/vdso.so |
| 212 |
endif |
| 213 |
endif |
| 214 |
|
| 215 |
vdso-install-y += arch/arm64/kernel/vdso/vdso.so.dbg |
| 216 |
vdso-install-$(CONFIG_COMPAT_VDSO) += arch/arm64/kernel/vdso32/vdso32.so.dbg |
| 217 |
|
| 218 |
include $(srctree)/scripts/Makefile.defconf |
| 219 |
|
| 220 |
PHONY += virtconfig |
| 221 |
virtconfig: |
| 222 |
$(call merge_into_defconfig_override,defconfig,virt) |
| 223 |
|
| 224 |
define 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' |
| 233 |
endef |