Makefile 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  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. LDFLAGS_vmlinux :=--no-undefined -X --pic-veneer
  13. ifeq ($(CONFIG_RELOCATABLE), y)
  14. # Pass --no-apply-dynamic-relocs to restore pre-binutils-2.27 behaviour
  15. # for relative relocs, since this leads to better Image compression
  16. # with the relocation offsets always being zero.
  17. LDFLAGS_vmlinux += -shared -Bsymbolic -z notext --no-apply-dynamic-relocs
  18. endif
  19. ifeq ($(CONFIG_ARM64_ERRATUM_843419),y)
  20. LDFLAGS_vmlinux += --fix-cortex-a53-843419
  21. endif
  22. cc_has_k_constraint := $(call try-run,echo \
  23. 'int main(void) { \
  24. asm volatile("and w0, w0, %w0" :: "K" (4294967295)); \
  25. return 0; \
  26. }' | $(CC) -S -x c -o "$$TMP" -,,-DCONFIG_CC_HAS_K_CONSTRAINT=1)
  27. ifeq ($(CONFIG_BROKEN_GAS_INST),y)
  28. $(warning Detected assembler with broken .inst; disassembly will be unreliable)
  29. endif
  30. # The GCC option -ffreestanding is required in order to compile code containing
  31. # ARM/NEON intrinsics in a non C99-compliant environment (such as the kernel)
  32. CC_FLAGS_FPU := -ffreestanding
  33. # Enable <arm_neon.h>
  34. CC_FLAGS_FPU += -isystem $(shell $(CC) -print-file-name=include)
  35. CC_FLAGS_NO_FPU := -mgeneral-regs-only
  36. KBUILD_CFLAGS += $(CC_FLAGS_NO_FPU) \
  37. $(compat_vdso) $(cc_has_k_constraint)
  38. KBUILD_CFLAGS += $(call cc-disable-warning, psabi)
  39. KBUILD_AFLAGS += $(compat_vdso)
  40. ifeq ($(call rustc-min-version, 108500),y)
  41. KBUILD_RUSTFLAGS += --target=aarch64-unknown-none-softfloat
  42. else
  43. KBUILD_RUSTFLAGS += --target=aarch64-unknown-none -Ctarget-feature="-neon"
  44. endif
  45. KBUILD_CFLAGS += $(call cc-option,-mabi=lp64)
  46. KBUILD_AFLAGS += $(call cc-option,-mabi=lp64)
  47. # Avoid generating .eh_frame* sections.
  48. ifneq ($(CONFIG_UNWIND_TABLES),y)
  49. KBUILD_CFLAGS += -fno-asynchronous-unwind-tables -fno-unwind-tables
  50. KBUILD_AFLAGS += -fno-asynchronous-unwind-tables -fno-unwind-tables
  51. KBUILD_RUSTFLAGS += -Cforce-unwind-tables=n
  52. else
  53. KBUILD_CFLAGS += -fasynchronous-unwind-tables
  54. KBUILD_AFLAGS += -fasynchronous-unwind-tables
  55. KBUILD_RUSTFLAGS += -Cforce-unwind-tables=y -Zuse-sync-unwind=n
  56. endif
  57. ifeq ($(CONFIG_STACKPROTECTOR_PER_TASK),y)
  58. prepare: stack_protector_prepare
  59. stack_protector_prepare: prepare0
  60. $(eval KBUILD_CFLAGS += -mstack-protector-guard=sysreg \
  61. -mstack-protector-guard-reg=sp_el0 \
  62. -mstack-protector-guard-offset=$(shell \
  63. awk '{if ($$2 == "TSK_STACK_CANARY") print $$3;}' \
  64. $(objtree)/include/generated/asm-offsets.h))
  65. endif
  66. ifeq ($(CONFIG_ARM64_BTI_KERNEL),y)
  67. KBUILD_CFLAGS += -mbranch-protection=pac-ret+bti
  68. KBUILD_RUSTFLAGS += -Zbranch-protection=bti,pac-ret
  69. else ifeq ($(CONFIG_ARM64_PTR_AUTH_KERNEL),y)
  70. KBUILD_RUSTFLAGS += -Zbranch-protection=pac-ret
  71. ifeq ($(CONFIG_CC_HAS_BRANCH_PROT_PAC_RET),y)
  72. KBUILD_CFLAGS += -mbranch-protection=pac-ret
  73. else
  74. KBUILD_CFLAGS += -msign-return-address=non-leaf
  75. endif
  76. else
  77. KBUILD_CFLAGS += $(call cc-option,-mbranch-protection=none)
  78. endif
  79. # Tell the assembler to support instructions from the latest target
  80. # architecture.
  81. #
  82. # For non-integrated assemblers we'll pass this on the command line, and for
  83. # integrated assemblers we'll define ARM64_ASM_ARCH and ARM64_ASM_PREAMBLE for
  84. # inline usage.
  85. #
  86. # We cannot pass the same arch flag to the compiler as this would allow it to
  87. # freely generate instructions which are not supported by earlier architecture
  88. # versions, which would prevent a single kernel image from working on earlier
  89. # hardware.
  90. ifeq ($(CONFIG_AS_HAS_ARMV8_5), y)
  91. asm-arch := armv8.5-a
  92. else
  93. asm-arch := armv8.4-a
  94. endif
  95. ifdef asm-arch
  96. KBUILD_CFLAGS += -Wa,-march=$(asm-arch) \
  97. -DARM64_ASM_ARCH='"$(asm-arch)"'
  98. endif
  99. ifeq ($(CONFIG_SHADOW_CALL_STACK), y)
  100. KBUILD_CFLAGS += -ffixed-x18
  101. KBUILD_RUSTFLAGS += -Zfixed-x18
  102. endif
  103. ifeq ($(CONFIG_CPU_BIG_ENDIAN), y)
  104. KBUILD_CPPFLAGS += -mbig-endian
  105. CHECKFLAGS += -D__AARCH64EB__
  106. # Prefer the baremetal ELF build target, but not all toolchains include
  107. # it so fall back to the standard linux version if needed.
  108. KBUILD_LDFLAGS += -EB $(call ld-option, -maarch64elfb, -maarch64linuxb -z norelro)
  109. UTS_MACHINE := aarch64_be
  110. else
  111. KBUILD_CPPFLAGS += -mlittle-endian
  112. CHECKFLAGS += -D__AARCH64EL__
  113. # Same as above, prefer ELF but fall back to linux target if needed.
  114. KBUILD_LDFLAGS += -EL $(call ld-option, -maarch64elf, -maarch64linux -z norelro)
  115. UTS_MACHINE := aarch64
  116. endif
  117. ifeq ($(CONFIG_LD_IS_LLD), y)
  118. KBUILD_LDFLAGS += -z norelro
  119. endif
  120. CHECKFLAGS += -D__aarch64__
  121. ifeq ($(CONFIG_DYNAMIC_FTRACE_WITH_CALL_OPS),y)
  122. KBUILD_CPPFLAGS += -DCC_USING_PATCHABLE_FUNCTION_ENTRY
  123. CC_FLAGS_FTRACE := -fpatchable-function-entry=4,2
  124. else ifeq ($(CONFIG_DYNAMIC_FTRACE_WITH_ARGS),y)
  125. KBUILD_CPPFLAGS += -DCC_USING_PATCHABLE_FUNCTION_ENTRY
  126. CC_FLAGS_FTRACE := -fpatchable-function-entry=2
  127. endif
  128. ifeq ($(CONFIG_KASAN_SW_TAGS), y)
  129. KASAN_SHADOW_SCALE_SHIFT := 4
  130. else ifeq ($(CONFIG_KASAN_GENERIC), y)
  131. KASAN_SHADOW_SCALE_SHIFT := 3
  132. endif
  133. KBUILD_CFLAGS += -DKASAN_SHADOW_SCALE_SHIFT=$(KASAN_SHADOW_SCALE_SHIFT)
  134. KBUILD_CPPFLAGS += -DKASAN_SHADOW_SCALE_SHIFT=$(KASAN_SHADOW_SCALE_SHIFT)
  135. KBUILD_AFLAGS += -DKASAN_SHADOW_SCALE_SHIFT=$(KASAN_SHADOW_SCALE_SHIFT)
  136. libs-y := arch/arm64/lib/ $(libs-y)
  137. libs-$(CONFIG_EFI_STUB) += $(objtree)/drivers/firmware/efi/libstub/lib.a
  138. # Default target when executing plain make
  139. boot := arch/arm64/boot
  140. BOOT_TARGETS := Image vmlinuz.efi image.fit
  141. PHONY += $(BOOT_TARGETS)
  142. ifeq ($(CONFIG_EFI_ZBOOT),)
  143. KBUILD_IMAGE := $(boot)/Image.gz
  144. else
  145. KBUILD_IMAGE := $(boot)/vmlinuz.efi
  146. endif
  147. all: $(notdir $(KBUILD_IMAGE))
  148. image.fit: dtbs
  149. vmlinuz.efi image.fit: Image
  150. $(BOOT_TARGETS): vmlinux
  151. $(Q)$(MAKE) $(build)=$(boot) $(boot)/$@
  152. Image.%: Image
  153. $(Q)$(MAKE) $(build)=$(boot) $(boot)/$@
  154. ifeq ($(CONFIG_COMPRESSED_INSTALL),y)
  155. DEFAULT_KBUILD_IMAGE = $(KBUILD_IMAGE)
  156. else
  157. DEFAULT_KBUILD_IMAGE = $(boot)/Image
  158. endif
  159. install: KBUILD_IMAGE := $(DEFAULT_KBUILD_IMAGE)
  160. install zinstall:
  161. $(call cmd,install)
  162. archprepare:
  163. $(Q)$(MAKE) $(build)=arch/arm64/tools kapi
  164. ifeq ($(KBUILD_EXTMOD),)
  165. # We need to generate vdso-offsets.h before compiling certain files in kernel/.
  166. # In order to do that, we should use the archprepare target, but we can't since
  167. # asm-offsets.h is included in some files used to generate vdso-offsets.h, and
  168. # asm-offsets.h is built in prepare0, for which archprepare is a dependency.
  169. # Therefore we need to generate the header after prepare0 has been made, hence
  170. # this hack.
  171. prepare: vdso_prepare
  172. vdso_prepare: prepare0
  173. $(Q)$(MAKE) $(build)=arch/arm64/kernel/vdso \
  174. include/generated/vdso-offsets.h arch/arm64/kernel/vdso/vdso.so
  175. ifdef CONFIG_COMPAT_VDSO
  176. $(Q)$(MAKE) $(build)=arch/arm64/kernel/vdso32 \
  177. arch/arm64/kernel/vdso32/vdso.so
  178. endif
  179. endif
  180. vdso-install-y += arch/arm64/kernel/vdso/vdso.so.dbg
  181. vdso-install-$(CONFIG_COMPAT_VDSO) += arch/arm64/kernel/vdso32/vdso32.so.dbg
  182. include $(srctree)/scripts/Makefile.defconf
  183. PHONY += virtconfig
  184. virtconfig:
  185. $(call merge_into_defconfig_override,defconfig,virt)
  186. define archhelp
  187. echo '* Image.gz - Compressed kernel image (arch/$(ARCH)/boot/Image.gz)'
  188. echo ' Image - Uncompressed kernel image (arch/$(ARCH)/boot/Image)'
  189. echo ' image.fit - Flat Image Tree (arch/$(ARCH)/boot/image.fit)'
  190. echo ' install - Install kernel (compressed if COMPRESSED_INSTALL set)'
  191. echo ' zinstall - Install compressed kernel'
  192. echo ' Install using (your) ~/bin/installkernel or'
  193. echo ' (distribution) /sbin/installkernel or'
  194. echo ' install to $$(INSTALL_PATH) and run lilo'
  195. endef