Makefile 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  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 -z norelro
  13. CPPFLAGS_vmlinux.lds = -DTEXT_OFFSET=$(TEXT_OFFSET)
  14. GZFLAGS :=-9
  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 += -Bsymbolic -z notext \
  20. $(call ld-option, --no-apply-dynamic-relocs)
  21. # Pass -shared for bfd and -pie for lld to minimize Image size on both
  22. ifeq ($(ld-name),bfd)
  23. LDFLAGS_vmlinux += -shared
  24. endif
  25. ifeq ($(ld-name),lld)
  26. LDFLAGS_vmlinux += -pie
  27. endif
  28. endif
  29. ifeq ($(CONFIG_ARM64_ERRATUM_843419),y)
  30. ifeq ($(call ld-option, --fix-cortex-a53-843419),)
  31. $(warning ld does not support --fix-cortex-a53-843419; kernel may be susceptible to erratum)
  32. else
  33. ifeq ($(call gold-ifversion, -lt, 114000000, y), y)
  34. $(warning This version of GNU gold may generate incorrect code with --fix-cortex-a53-843419;\
  35. see https://sourceware.org/bugzilla/show_bug.cgi?id=21491)
  36. endif
  37. LDFLAGS_vmlinux += --fix-cortex-a53-843419
  38. endif
  39. else
  40. ifeq ($(ld-name),gold)
  41. # Pass --no-fix-cortex-a53-843419 to ensure the erratum fix is disabled
  42. LDFLAGS += --no-fix-cortex-a53-843419
  43. endif
  44. endif
  45. KBUILD_DEFCONFIG := defconfig
  46. # Check for binutils support for specific extensions
  47. lseinstr := $(call as-instr,.arch_extension lse,-DCONFIG_AS_LSE=1)
  48. ifeq ($(CONFIG_ARM64_LSE_ATOMICS), y)
  49. ifeq ($(lseinstr),)
  50. $(warning LSE atomics not supported by binutils)
  51. endif
  52. endif
  53. ifeq ($(CONFIG_ARM64), y)
  54. brokengasinst := $(call as-instr,1:\n.inst 0\n.rept . - 1b\n\nnop\n.endr\n,,-DCONFIG_BROKEN_GAS_INST=1)
  55. ifneq ($(brokengasinst),)
  56. $(warning Detected assembler with broken .inst; disassembly will be unreliable)
  57. endif
  58. endif
  59. ifeq ($(CONFIG_COMPAT_VDSO), y)
  60. CROSS_COMPILE_ARM32 ?= $(CONFIG_CROSS_COMPILE_ARM32:"%"=%)
  61. # Check that the user has provided a valid prefix for the 32-bit toolchain.
  62. # To prevent selecting the system $(cc-name) by default, the prefix is not
  63. # allowed to be empty, unlike CROSS_COMPILE. In the unlikely event that the
  64. # system $(cc-name) is actually the 32-bit ARM compiler to be used, the
  65. # variable can be set to the dirname (e.g. CROSS_COMPILE_ARM32=/usr/bin/).
  66. # Note: this Makefile is read both before and after regenerating the config
  67. # (if needed). Any warning appearing before the config has been regenerated
  68. # should be ignored. If the error is triggered and you set
  69. # CONFIG_CROSS_COMPILE_ARM32, set CROSS_COMPILE_ARM32 to an appropriate value
  70. # when invoking make and fix CONFIG_CROSS_COMPILE_ARM32.
  71. ifeq ($(CROSS_COMPILE_ARM32),)
  72. $(error CROSS_COMPILE_ARM32 not defined or empty, the compat vDSO will not be built)
  73. else ifeq ($(cc-name),clang)
  74. export CLANG_TRIPLE_ARM32 ?= $(CROSS_COMPILE_ARM32)
  75. export CLANG_TARGET_ARM32 := --target=$(notdir $(CLANG_TRIPLE_ARM32:%-=%))
  76. export GCC_TOOLCHAIN32_DIR := $(dir $(shell which $(CROSS_COMPILE_ARM32)ld))
  77. export GCC_TOOLCHAIN32 := $(realpath $(GCC_TOOLCHAIN32_DIR)/..)
  78. export CLANG_PREFIX32 := --prefix=$(GCC_TOOLCHAIN32_DIR)$(notdir $(CROSS_COMPILE_ARM32))
  79. export CLANG_GCC32_TC := --gcc-toolchain=$(GCC_TOOLCHAIN32)
  80. export CONFIG_VDSO32 := y
  81. vdso32 := -DCONFIG_VDSO32=1
  82. else ifeq ($(shell which $(CROSS_COMPILE_ARM32)$(cc-name) 2> /dev/null),)
  83. $(error $(CROSS_COMPILE_ARM32)$(cc-name) not found, check CROSS_COMPILE_ARM32)
  84. else
  85. export CROSS_COMPILE_ARM32
  86. export CONFIG_VDSO32 := y
  87. vdso32 := -DCONFIG_VDSO32=1
  88. endif
  89. endif
  90. ifeq ($(cc-name),clang)
  91. # This is a workaround for https://bugs.llvm.org/show_bug.cgi?id=30792.
  92. # TODO: revert when this is fixed in LLVM.
  93. KBUILD_CFLAGS += -mno-implicit-float
  94. else
  95. KBUILD_CFLAGS += -mgeneral-regs-only
  96. endif
  97. KBUILD_CFLAGS += $(lseinstr) $(brokengasinst) $(vdso32)
  98. KBUILD_CFLAGS += -fno-asynchronous-unwind-tables
  99. KBUILD_CFLAGS += $(call cc-option, -mpc-relative-literal-loads)
  100. KBUILD_CFLAGS += -fno-pic
  101. KBUILD_CFLAGS += $(call cc-disable-warning, psabi)
  102. KBUILD_AFLAGS += $(lseinstr) $(brokengasinst) $(vdso32)
  103. KBUILD_CFLAGS += $(call cc-option,-mabi=lp64)
  104. KBUILD_AFLAGS += $(call cc-option,-mabi=lp64)
  105. ifeq ($(CONFIG_SHADOW_CALL_STACK), y)
  106. KBUILD_CFLAGS += -ffixed-x18
  107. endif
  108. ifeq ($(CONFIG_CPU_BIG_ENDIAN), y)
  109. KBUILD_CPPFLAGS += -mbig-endian
  110. CHECKFLAGS += -D__AARCH64EB__
  111. AS += -EB
  112. LD += -EB
  113. ifeq ($(ld-name),gold)
  114. LDFLAGS += -maarch64_elf64_be_vec
  115. else
  116. LDFLAGS += -maarch64elfb
  117. endif
  118. UTS_MACHINE := aarch64_be
  119. else
  120. KBUILD_CPPFLAGS += -mlittle-endian
  121. CHECKFLAGS += -D__AARCH64EL__
  122. AS += -EL
  123. LD += -EL
  124. ifeq ($(ld-name),gold)
  125. LDFLAGS += -maarch64_elf64_le_vec
  126. else
  127. LDFLAGS += -maarch64elf
  128. endif
  129. UTS_MACHINE := aarch64
  130. endif
  131. CHECKFLAGS += -D__aarch64__ -m64
  132. ifeq ($(CONFIG_ARM64_MODULE_CMODEL_LARGE), y)
  133. KBUILD_CFLAGS_MODULE += -mcmodel=large
  134. ifeq ($(CONFIG_LTO_CLANG), y)
  135. # Code model is not stored in LLVM IR, so we need to pass it also to LLVMgold
  136. KBUILD_LDFLAGS_MODULE += -plugin-opt=-code-model=large
  137. endif
  138. endif
  139. ifeq ($(CONFIG_ARM64_MODULE_PLTS),y)
  140. KBUILD_LDFLAGS_MODULE += -T $(srctree)/arch/arm64/kernel/module.lds
  141. endif
  142. # Default value
  143. head-y := arch/arm64/kernel/head.o
  144. # The byte offset of the kernel image in RAM from the start of RAM.
  145. ifeq ($(CONFIG_ARM64_RANDOMIZE_TEXT_OFFSET), y)
  146. TEXT_OFFSET := $(shell awk "BEGIN {srand(); printf \"0x%06x\n\", \
  147. int(2 * 1024 * 1024 / (2 ^ $(CONFIG_ARM64_PAGE_SHIFT)) * \
  148. rand()) * (2 ^ $(CONFIG_ARM64_PAGE_SHIFT))}")
  149. else
  150. TEXT_OFFSET := 0x00080000
  151. endif
  152. ifeq ($(cc-name),clang)
  153. KBUILD_CFLAGS += $(call cc-disable-warning, asm-operand-widths)
  154. endif
  155. ifeq ($(CONFIG_KASAN_SW_TAGS), y)
  156. KASAN_SHADOW_SCALE_SHIFT := 4
  157. else
  158. KASAN_SHADOW_SCALE_SHIFT := 3
  159. endif
  160. KBUILD_CFLAGS += -DKASAN_SHADOW_SCALE_SHIFT=$(KASAN_SHADOW_SCALE_SHIFT)
  161. KBUILD_CPPFLAGS += -DKASAN_SHADOW_SCALE_SHIFT=$(KASAN_SHADOW_SCALE_SHIFT)
  162. KBUILD_AFLAGS += -DKASAN_SHADOW_SCALE_SHIFT=$(KASAN_SHADOW_SCALE_SHIFT)
  163. # KASAN_SHADOW_OFFSET = VA_START + (1 << (VA_BITS - KASAN_SHADOW_SCALE_SHIFT))
  164. # - (1 << (64 - KASAN_SHADOW_SCALE_SHIFT))
  165. # in 32-bit arithmetic
  166. KASAN_SHADOW_OFFSET := $(shell printf "0x%08x00000000\n" $$(( \
  167. (0xffffffff & (-1 << ($(CONFIG_ARM64_VA_BITS) - 32))) \
  168. + (1 << ($(CONFIG_ARM64_VA_BITS) - 32 - $(KASAN_SHADOW_SCALE_SHIFT))) \
  169. - (1 << (64 - 32 - $(KASAN_SHADOW_SCALE_SHIFT))) )) )
  170. export TEXT_OFFSET GZFLAGS
  171. core-y += arch/arm64/kernel/ arch/arm64/mm/
  172. core-$(CONFIG_NET) += arch/arm64/net/
  173. core-$(CONFIG_KVM) += arch/arm64/kvm/
  174. core-$(CONFIG_XEN) += arch/arm64/xen/
  175. core-$(CONFIG_CRYPTO) += arch/arm64/crypto/
  176. libs-y := arch/arm64/lib/ $(libs-y)
  177. core-$(CONFIG_EFI_STUB) += $(objtree)/drivers/firmware/efi/libstub/lib.a
  178. # Default target when executing plain make
  179. boot := arch/arm64/boot
  180. ifeq ($(CONFIG_BUILD_ARM64_APPENDED_DTB_IMAGE),y)
  181. KBUILD_IMAGE := $(boot)/$(subst $\",,$(CONFIG_BUILD_ARM64_APPENDED_KERNEL_IMAGE_NAME))
  182. else
  183. KBUILD_IMAGE := $(boot)/Image.gz
  184. endif
  185. KBUILD_DTBS := dtbs
  186. all: Image.gz $(KBUILD_DTBS) $(subst $\",,$(CONFIG_BUILD_ARM64_APPENDED_KERNEL_IMAGE_NAME))
  187. MTK_PLATFORM := $(CONFIG_MTK_PLATFORM:"%"=%)
  188. MTK_PROJECT := $(CONFIG_ARCH_MTK_PROJECT:"%"=%)
  189. export MTK_PLATFORM MTK_PROJECT
  190. Image: vmlinux
  191. $(Q)$(MAKE) $(build)=$(boot) $(boot)/$@
  192. Image.%: Image
  193. $(Q)$(MAKE) $(build)=$(boot) $(boot)/$@
  194. zinstall install:
  195. $(Q)$(MAKE) $(build)=$(boot) $@
  196. %.dtb: scripts
  197. $(Q)$(MAKE) $(build)=$(boot)/dts $(boot)/dts/$@
  198. PHONY += dtbs dtbs_install
  199. dtbs: prepare scripts
  200. $(Q)$(MAKE) $(build)=$(boot)/dts
  201. dtbs_install:
  202. $(Q)$(MAKE) $(dtbinst)=$(boot)/dts
  203. Image-dtb: vmlinux scripts dtbs
  204. $(Q)$(MAKE) $(build)=$(boot) $(boot)/$@
  205. Image.gz-dtb: vmlinux scripts dtbs Image.gz
  206. $(Q)$(MAKE) $(build)=$(boot) $(boot)/$@
  207. PHONY += vdso_install
  208. vdso_install:
  209. $(Q)$(MAKE) $(build)=arch/arm64/kernel/vdso $@
  210. # We use MRPROPER_FILES and CLEAN_FILES now
  211. archclean:
  212. $(Q)$(MAKE) $(clean)=$(boot)
  213. $(Q)$(MAKE) $(clean)=$(boot)/dts
  214. ifeq ($(KBUILD_EXTMOD),)
  215. # We need to generate vdso-offsets.h before compiling certain files in kernel/.
  216. # In order to do that, we should use the archprepare target, but we can't since
  217. # asm-offsets.h is included in some files used to generate vdso-offsets.h, and
  218. # asm-offsets.h is built in prepare0, for which archprepare is a dependency.
  219. # Therefore we need to generate the header after prepare0 has been made, hence
  220. # this hack.
  221. prepare: vdso_prepare
  222. vdso_prepare: prepare0
  223. $(Q)$(MAKE) $(build)=arch/arm64/kernel/vdso include/generated/vdso-offsets.h
  224. $(if $(CONFIG_VDSO32),$(Q)$(MAKE) $(build)=arch/arm64/kernel/vdso32 \
  225. include/generated/vdso32-offsets.h)
  226. endif
  227. define archhelp
  228. echo '* Image.gz - Compressed kernel image (arch/$(ARCH)/boot/Image.gz)'
  229. echo ' Image - Uncompressed kernel image (arch/$(ARCH)/boot/Image)'
  230. echo '* dtbs - Build device tree blobs for enabled boards'
  231. echo ' dtbs_install - Install dtbs to $(INSTALL_DTBS_PATH)'
  232. echo ' install - Install uncompressed kernel'
  233. echo ' zinstall - Install compressed kernel'
  234. echo ' Install using (your) ~/bin/installkernel or'
  235. echo ' (distribution) /sbin/installkernel or'
  236. echo ' install to $$(INSTALL_PATH) and run lilo'
  237. endef