Makefile 8.2 KB

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