Linux 6.16-rc6
[linux-block.git] / arch / arm64 / Makefile
CommitLineData
8c2c3df3
CM
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
9abe390e 13LDFLAGS_vmlinux :=--no-undefined -X --pic-veneer
8c2c3df3 14
fd9dde6a
ND
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.
2555d4c6 19LDFLAGS_vmlinux += -shared -Bsymbolic -z notext --no-apply-dynamic-relocs
1e48ef7f
AB
20endif
21
6ffe9923 22ifeq ($(CONFIG_ARM64_ERRATUM_843419),y)
6ffe9923 23LDFLAGS_vmlinux += --fix-cortex-a53-843419
6ffe9923
WD
24endif
25
03adcbd9
WD
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
8bf9284d 32ifeq ($(CONFIG_BROKEN_GAS_INST),y)
bbb56c27
MZ
33$(warning Detected assembler with broken .inst; disassembly will be unreliable)
34endif
35
71883ae3
SH
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) \
03adcbd9 44 $(compat_vdso) $(cc_has_k_constraint)
fa63da2a 45KBUILD_CFLAGS += $(call cc-disable-warning, psabi)
8bf9284d 46KBUILD_AFLAGS += $(compat_vdso)
c09d6a04 47
ac954145 48ifeq ($(call rustc-min-version, 108500),y)
446a8351
MO
49KBUILD_RUSTFLAGS += --target=aarch64-unknown-none-softfloat
50else
724a75ac 51KBUILD_RUSTFLAGS += --target=aarch64-unknown-none -Ctarget-feature="-neon"
446a8351 52endif
724a75ac 53
3d6a7b99
AP
54KBUILD_CFLAGS += $(call cc-option,-mabi=lp64)
55KBUILD_AFLAGS += $(call cc-option,-mabi=lp64)
56
6e0a66d1 57# Avoid generating .eh_frame* sections.
68c76ad4 58ifneq ($(CONFIG_UNWIND_TABLES),y)
6e0a66d1
KC
59KBUILD_CFLAGS += -fno-asynchronous-unwind-tables -fno-unwind-tables
60KBUILD_AFLAGS += -fno-asynchronous-unwind-tables -fno-unwind-tables
d077242d 61KBUILD_RUSTFLAGS += -Cforce-unwind-tables=n
68c76ad4
AB
62else
63KBUILD_CFLAGS += -fasynchronous-unwind-tables
64KBUILD_AFLAGS += -fasynchronous-unwind-tables
d077242d 65KBUILD_RUSTFLAGS += -Cforce-unwind-tables=y -Zuse-sync-unwind=n
68c76ad4 66endif
6e0a66d1 67
0a1213fa
AB
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;}' \
214c0eea 75 $(objtree)/include/generated/asm-offsets.h))
0a1213fa
AB
76endif
77
92e2294d 78ifeq ($(CONFIG_ARM64_BTI_KERNEL),y)
c68cf528 79 KBUILD_CFLAGS += -mbranch-protection=pac-ret+bti
724a75ac 80 KBUILD_RUSTFLAGS += -Zbranch-protection=bti,pac-ret
c68cf528 81else ifeq ($(CONFIG_ARM64_PTR_AUTH_KERNEL),y)
724a75ac 82 KBUILD_RUSTFLAGS += -Zbranch-protection=pac-ret
c68cf528
MR
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
92e2294d 88else
c68cf528 89 KBUILD_CFLAGS += $(call cc-option,-mbranch-protection=none)
1764c3ed
ST
90endif
91
1e249c41
MR
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.
f469c032 103ifeq ($(CONFIG_AS_HAS_ARMV8_5), y)
1e249c41 104 asm-arch := armv8.5-a
2555d4c6 105else
1e249c41 106 asm-arch := armv8.4-a
f469c032
VF
107endif
108
1764c3ed
ST
109ifdef asm-arch
110KBUILD_CFLAGS += -Wa,-march=$(asm-arch) \
111 -DARM64_ASM_ARCH='"$(asm-arch)"'
7c78f67e
ZY
112endif
113
da64e9d1
ST
114ifeq ($(CONFIG_SHADOW_CALL_STACK), y)
115KBUILD_CFLAGS += -ffixed-x18
d077242d 116KBUILD_RUSTFLAGS += -Zfixed-x18
da64e9d1
ST
117endif
118
a0974e6e
WD
119ifeq ($(CONFIG_CPU_BIG_ENDIAN), y)
120KBUILD_CPPFLAGS += -mbig-endian
bcde519e 121CHECKFLAGS += -D__AARCH64EB__
c931d34e
OJ
122# Prefer the baremetal ELF build target, but not all toolchains include
123# it so fall back to the standard linux version if needed.
311bea3c 124KBUILD_LDFLAGS += -EB $(call ld-option, -maarch64elfb, -maarch64linuxb -z norelro)
cfa88c79 125UTS_MACHINE := aarch64_be
a0974e6e 126else
8c2c3df3 127KBUILD_CPPFLAGS += -mlittle-endian
bcde519e 128CHECKFLAGS += -D__AARCH64EL__
c931d34e 129# Same as above, prefer ELF but fall back to linux target if needed.
311bea3c 130KBUILD_LDFLAGS += -EL $(call ld-option, -maarch64elf, -maarch64linux -z norelro)
cfa88c79 131UTS_MACHINE := aarch64
a0974e6e 132endif
8c2c3df3 133
311bea3c
ND
134ifeq ($(CONFIG_LD_IS_LLD), y)
135KBUILD_LDFLAGS += -z norelro
136endif
137
1f2f01b1 138CHECKFLAGS += -D__aarch64__
8c2c3df3 139
baaf553d
MR
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)
3b23e499
TD
144 KBUILD_CPPFLAGS += -DCC_USING_PATCHABLE_FUNCTION_ENTRY
145 CC_FLAGS_FTRACE := -fpatchable-function-entry=2
146endif
147
b2f557ea
AK
148ifeq ($(CONFIG_KASAN_SW_TAGS), y)
149KASAN_SHADOW_SCALE_SHIFT := 4
0fea6e9a 150else ifeq ($(CONFIG_KASAN_GENERIC), y)
b2f557ea
AK
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
8c2c3df3 158libs-y := arch/arm64/lib/ $(libs-y)
c1aac64d 159libs-$(CONFIG_EFI_STUB) += $(objtree)/drivers/firmware/efi/libstub/lib.a
8c2c3df3
CM
160
161# Default target when executing plain make
06995804 162boot := arch/arm64/boot
c37b830f 163
7a23b027 164BOOT_TARGETS := Image vmlinuz.efi image.fit
0dc1670b
SG
165
166PHONY += $(BOOT_TARGETS)
167
c37b830f 168ifeq ($(CONFIG_EFI_ZBOOT),)
06995804 169KBUILD_IMAGE := $(boot)/Image.gz
c37b830f
AB
170else
171KBUILD_IMAGE := $(boot)/vmlinuz.efi
172endif
8c2c3df3 173
c37b830f 174all: $(notdir $(KBUILD_IMAGE))
8c2c3df3 175
7a23b027
SG
176image.fit: dtbs
177
178vmlinuz.efi image.fit: Image
0dc1670b 179$(BOOT_TARGETS): vmlinux
0723c05f
OJ
180 $(Q)$(MAKE) $(build)=$(boot) $(boot)/$@
181
9ca4e58c 182Image.%: Image
70f915a2 183 $(Q)$(MAKE) $(build)=$(boot) $(boot)/$@
8c2c3df3 184
4c7be57f
LT
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)
70a4039b 192install zinstall:
f774f5bb 193 $(call cmd,install)
8c2c3df3 194
0c6c2d36
MB
195archprepare:
196 $(Q)$(MAKE) $(build)=arch/arm64/tools kapi
64ee84c7 197
98356eb0 198ifeq ($(KBUILD_EXTMOD),)
a66649da
KB
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
a5b8ca97
MY
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 \
c7767f5c 211 arch/arm64/kernel/vdso32/vdso.so
a5b8ca97 212endif
98356eb0 213endif
a66649da 214
56769ba4 215vdso-install-y += arch/arm64/kernel/vdso/vdso.so.dbg
a099bec7 216vdso-install-$(CONFIG_COMPAT_VDSO) += arch/arm64/kernel/vdso32/vdso32.so.dbg
56769ba4 217
c6cd63f5
MB
218include $(srctree)/scripts/Makefile.defconf
219
220PHONY += virtconfig
221virtconfig:
222 $(call merge_into_defconfig_override,defconfig,virt)
223
8c2c3df3
CM
224define archhelp
225 echo '* Image.gz - Compressed kernel image (arch/$(ARCH)/boot/Image.gz)'
226 echo ' Image - Uncompressed kernel image (arch/$(ARCH)/boot/Image)'
7a23b027 227 echo ' image.fit - Flat Image Tree (arch/$(ARCH)/boot/image.fit)'
4c7be57f 228 echo ' install - Install kernel (compressed if COMPRESSED_INSTALL set)'
8c2c3df3
CM
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