hc
2023-12-09 958e46acc8e900e8569dd467c1af9b8d2d019394
kernel/arch/arm64/Makefile
....@@ -10,9 +10,7 @@
1010 #
1111 # Copyright (C) 1995-2001 by Russell King
1212
13
-LDFLAGS_vmlinux :=--no-undefined -X -z norelro
14
-CPPFLAGS_vmlinux.lds = -DTEXT_OFFSET=$(TEXT_OFFSET)
15
-GZFLAGS :=-9
13
+LDFLAGS_vmlinux :=--no-undefined -X
1614
1715 ifeq ($(CONFIG_RELOCATABLE), y)
1816 # Pass --no-apply-dynamic-relocs to restore pre-binutils-2.27 behaviour
....@@ -30,32 +28,83 @@
3028 endif
3129 endif
3230
33
-KBUILD_DEFCONFIG := defconfig
34
-
35
-# Check for binutils support for specific extensions
36
-lseinstr := $(call as-instr,.arch_extension lse,-DCONFIG_AS_LSE=1)
37
-
38
-ifeq ($(CONFIG_ARM64_LSE_ATOMICS), y)
39
- ifeq ($(lseinstr),)
31
+ifeq ($(CONFIG_ARM64_USE_LSE_ATOMICS), y)
32
+ ifneq ($(CONFIG_ARM64_LSE_ATOMICS), y)
4033 $(warning LSE atomics not supported by binutils)
4134 endif
4235 endif
4336
44
-ifeq ($(CONFIG_ARM64), y)
45
-brokengasinst := $(call as-instr,1:\n.inst 0\n.rept . - 1b\n\nnop\n.endr\n,,-DCONFIG_BROKEN_GAS_INST=1)
37
+cc_has_k_constraint := $(call try-run,echo \
38
+ 'int main(void) { \
39
+ asm volatile("and w0, w0, %w0" :: "K" (4294967295)); \
40
+ return 0; \
41
+ }' | $(CC) -S -x c -o "$$TMP" -,,-DCONFIG_CC_HAS_K_CONSTRAINT=1)
4642
47
- ifneq ($(brokengasinst),)
43
+ifeq ($(CONFIG_BROKEN_GAS_INST),y)
4844 $(warning Detected assembler with broken .inst; disassembly will be unreliable)
49
- endif
5045 endif
5146
52
-KBUILD_CFLAGS += -mgeneral-regs-only $(lseinstr) $(brokengasinst) $(compat_vdso)
53
-KBUILD_CFLAGS += -fno-asynchronous-unwind-tables
47
+KBUILD_CFLAGS += -mgeneral-regs-only \
48
+ $(compat_vdso) $(cc_has_k_constraint)
5449 KBUILD_CFLAGS += $(call cc-disable-warning, psabi)
55
-KBUILD_AFLAGS += $(lseinstr) $(brokengasinst) $(compat_vdso)
50
+KBUILD_AFLAGS += $(compat_vdso)
5651
5752 KBUILD_CFLAGS += $(call cc-option,-mabi=lp64)
5853 KBUILD_AFLAGS += $(call cc-option,-mabi=lp64)
54
+
55
+# Avoid generating .eh_frame* sections.
56
+KBUILD_CFLAGS += -fno-asynchronous-unwind-tables -fno-unwind-tables
57
+KBUILD_AFLAGS += -fno-asynchronous-unwind-tables -fno-unwind-tables
58
+
59
+ifeq ($(CONFIG_STACKPROTECTOR_PER_TASK),y)
60
+prepare: stack_protector_prepare
61
+stack_protector_prepare: prepare0
62
+ $(eval KBUILD_CFLAGS += -mstack-protector-guard=sysreg \
63
+ -mstack-protector-guard-reg=sp_el0 \
64
+ -mstack-protector-guard-offset=$(shell \
65
+ awk '{if ($$2 == "TSK_STACK_CANARY") print $$3;}' \
66
+ include/generated/asm-offsets.h))
67
+endif
68
+
69
+# Ensure that if the compiler supports branch protection we default it
70
+# off, this will be overridden if we are using branch protection.
71
+branch-prot-flags-y += $(call cc-option,-mbranch-protection=none)
72
+
73
+ifeq ($(CONFIG_ARM64_PTR_AUTH),y)
74
+branch-prot-flags-$(CONFIG_CC_HAS_SIGN_RETURN_ADDRESS) := -msign-return-address=all
75
+# We enable additional protection for leaf functions as there is some
76
+# narrow potential for ROP protection benefits and no substantial
77
+# performance impact has been observed.
78
+ifeq ($(CONFIG_ARM64_BTI_KERNEL),y)
79
+branch-prot-flags-$(CONFIG_CC_HAS_BRANCH_PROT_PAC_RET_BTI) := -mbranch-protection=pac-ret+leaf+bti
80
+else
81
+branch-prot-flags-$(CONFIG_CC_HAS_BRANCH_PROT_PAC_RET) := -mbranch-protection=pac-ret+leaf
82
+endif
83
+# -march=armv8.3-a enables the non-nops instructions for PAC, to avoid the
84
+# compiler to generate them and consequently to break the single image contract
85
+# we pass it only to the assembler. This option is utilized only in case of non
86
+# integrated assemblers.
87
+ifeq ($(CONFIG_AS_HAS_PAC), y)
88
+asm-arch := armv8.3-a
89
+endif
90
+endif
91
+
92
+KBUILD_CFLAGS += $(branch-prot-flags-y)
93
+
94
+ifeq ($(CONFIG_AS_HAS_ARMV8_4), y)
95
+# make sure to pass the newest target architecture to -march.
96
+asm-arch := armv8.4-a
97
+endif
98
+
99
+ifeq ($(CONFIG_AS_HAS_ARMV8_5), y)
100
+# make sure to pass the newest target architecture to -march.
101
+asm-arch := armv8.5-a
102
+endif
103
+
104
+ifdef asm-arch
105
+KBUILD_CFLAGS += -Wa,-march=$(asm-arch) \
106
+ -DARM64_ASM_ARCH='"$(asm-arch)"'
107
+endif
59108
60109 ifeq ($(CONFIG_SHADOW_CALL_STACK), y)
61110 KBUILD_CFLAGS += -ffixed-x18
....@@ -64,41 +113,35 @@
64113 ifeq ($(CONFIG_CPU_BIG_ENDIAN), y)
65114 KBUILD_CPPFLAGS += -mbig-endian
66115 CHECKFLAGS += -D__AARCH64EB__
67
-AS += -EB
68116 # Prefer the baremetal ELF build target, but not all toolchains include
69117 # it so fall back to the standard linux version if needed.
70
-KBUILD_LDFLAGS += -EB $(call ld-option, -maarch64elfb, -maarch64linuxb)
118
+KBUILD_LDFLAGS += -EB $(call ld-option, -maarch64elfb, -maarch64linuxb -z norelro)
71119 UTS_MACHINE := aarch64_be
72120 else
73121 KBUILD_CPPFLAGS += -mlittle-endian
74122 CHECKFLAGS += -D__AARCH64EL__
75
-AS += -EL
76123 # Same as above, prefer ELF but fall back to linux target if needed.
77
-KBUILD_LDFLAGS += -EL $(call ld-option, -maarch64elf, -maarch64linux)
124
+KBUILD_LDFLAGS += -EL $(call ld-option, -maarch64elf, -maarch64linux -z norelro)
78125 UTS_MACHINE := aarch64
126
+endif
127
+
128
+ifeq ($(CONFIG_LD_IS_LLD), y)
129
+KBUILD_LDFLAGS += -z norelro
79130 endif
80131
81132 CHECKFLAGS += -D__aarch64__
82133
83
-ifeq ($(CONFIG_ARM64_MODULE_PLTS),y)
84
-KBUILD_LDFLAGS_MODULE += -T $(srctree)/arch/arm64/kernel/module.lds
134
+ifeq ($(CONFIG_DYNAMIC_FTRACE_WITH_REGS),y)
135
+ KBUILD_CPPFLAGS += -DCC_USING_PATCHABLE_FUNCTION_ENTRY
136
+ CC_FLAGS_FTRACE := -fpatchable-function-entry=2
85137 endif
86138
87139 # Default value
88140 head-y := arch/arm64/kernel/head.o
89141
90
-# The byte offset of the kernel image in RAM from the start of RAM.
91
-ifeq ($(CONFIG_ARM64_RANDOMIZE_TEXT_OFFSET), y)
92
-TEXT_OFFSET := $(shell awk "BEGIN {srand(); printf \"0x%06x\n\", \
93
- int(2 * 1024 * 1024 / (2 ^ $(CONFIG_ARM64_PAGE_SHIFT)) * \
94
- rand()) * (2 ^ $(CONFIG_ARM64_PAGE_SHIFT))}")
95
-else
96
-TEXT_OFFSET := 0x00080000
97
-endif
98
-
99142 ifeq ($(CONFIG_KASAN_SW_TAGS), y)
100143 KASAN_SHADOW_SCALE_SHIFT := 4
101
-else
144
+else ifeq ($(CONFIG_KASAN_GENERIC), y)
102145 KASAN_SHADOW_SCALE_SHIFT := 3
103146 endif
104147
....@@ -106,30 +149,18 @@
106149 KBUILD_CPPFLAGS += -DKASAN_SHADOW_SCALE_SHIFT=$(KASAN_SHADOW_SCALE_SHIFT)
107150 KBUILD_AFLAGS += -DKASAN_SHADOW_SCALE_SHIFT=$(KASAN_SHADOW_SCALE_SHIFT)
108151
109
-# KASAN_SHADOW_OFFSET = VA_START + (1 << (VA_BITS - KASAN_SHADOW_SCALE_SHIFT))
110
-# - (1 << (64 - KASAN_SHADOW_SCALE_SHIFT))
111
-# in 32-bit arithmetic
112
-KASAN_SHADOW_OFFSET := $(shell printf "0x%08x00000000\n" $$(( \
113
- (0xffffffff & (-1 << ($(CONFIG_ARM64_VA_BITS) - 32))) \
114
- + (1 << ($(CONFIG_ARM64_VA_BITS) - 32 - $(KASAN_SHADOW_SCALE_SHIFT))) \
115
- - (1 << (64 - 32 - $(KASAN_SHADOW_SCALE_SHIFT))) )) )
116
-
117
-export TEXT_OFFSET GZFLAGS
118
-
119
-core-y += arch/arm64/kernel/ arch/arm64/mm/
120
-core-$(CONFIG_NET) += arch/arm64/net/
121
-core-$(CONFIG_KVM) += arch/arm64/kvm/
122
-core-$(CONFIG_XEN) += arch/arm64/xen/
123
-core-$(CONFIG_CRYPTO) += arch/arm64/crypto/
152
+core-y += arch/arm64/
124153 libs-y := arch/arm64/lib/ $(libs-y)
125
-core-$(CONFIG_EFI_STUB) += $(objtree)/drivers/firmware/efi/libstub/lib.a
154
+libs-$(CONFIG_EFI_STUB) += $(objtree)/drivers/firmware/efi/libstub/lib.a
126155
127156 # Default target when executing plain make
128157 boot := arch/arm64/boot
129158 KBUILD_IMAGE := $(boot)/Image.gz
130
-KBUILD_DTBS := dtbs
131159
132
-all: Image.gz $(KBUILD_DTBS)
160
+# Don't compile Image in mixed build with "all" target
161
+ifndef KBUILD_MIXED_TREE
162
+all: Image.gz
163
+endif
133164
134165
135166 Image: vmlinux
....@@ -141,26 +172,15 @@
141172 zinstall install:
142173 $(Q)$(MAKE) $(build)=$(boot) $@
143174
144
-%.dtb: scripts
145
- $(Q)$(MAKE) $(build)=$(boot)/dts $(boot)/dts/$@
146
-
147
-PHONY += dtbs dtbs_install
148
-
149
-dtbs: prepare scripts
150
- $(Q)$(MAKE) $(build)=$(boot)/dts
151
-
152
-dtbs_install:
153
- $(Q)$(MAKE) $(dtbinst)=$(boot)/dts
154
-
155175 PHONY += vdso_install
156176 vdso_install:
157177 $(Q)$(MAKE) $(build)=arch/arm64/kernel/vdso $@
158
- $(Q)$(MAKE) $(build)=arch/arm64/kernel/vdso32 $@
178
+ $(if $(CONFIG_COMPAT_VDSO), \
179
+ $(Q)$(MAKE) $(build)=arch/arm64/kernel/vdso32 $@)
159180
160181 # We use MRPROPER_FILES and CLEAN_FILES now
161182 archclean:
162183 $(Q)$(MAKE) $(clean)=$(boot)
163
- $(Q)$(MAKE) $(clean)=$(boot)/dts
164184
165185 ifeq ($(KBUILD_EXTMOD),)
166186 # We need to generate vdso-offsets.h before compiling certain files in kernel/.
....@@ -180,8 +200,6 @@
180200 define archhelp
181201 echo '* Image.gz - Compressed kernel image (arch/$(ARCH)/boot/Image.gz)'
182202 echo ' Image - Uncompressed kernel image (arch/$(ARCH)/boot/Image)'
183
- echo '* dtbs - Build device tree blobs for enabled boards'
184
- echo ' dtbs_install - Install dtbs to $(INSTALL_DTBS_PATH)'
185203 echo ' install - Install uncompressed kernel'
186204 echo ' zinstall - Install compressed kernel'
187205 echo ' Install using (your) ~/bin/installkernel or'
....@@ -189,17 +207,14 @@
189207 echo ' install to $$(INSTALL_PATH) and run lilo'
190208 endef
191209
192
-kernel.img: Image.lz4
193
- $(Q)scripts/mkkrnlimg $(objtree)/arch/arm64/boot/Image $(objtree)/kernel.img >/dev/null
194
- @echo ' Image: kernel.img is ready'
195
-ifdef CONFIG_MODULES
196
- $(Q)if [ "$(srctree)" = "$(objtree)" ]; then $(MAKE) modules; fi
210
+MAKE_MODULES ?= y
211
+
212
+%.img:
213
+ifeq ("$(CONFIG_MODULES)$(MAKE_MODULES)$(srctree)","yy$(objtree)")
214
+ $(Q)$(MAKE) rockchip/$*.dtb Image.lz4 modules
215
+else
216
+ $(Q)$(MAKE) rockchip/$*.dtb Image.lz4
197217 endif
198
-
199
-LOGO := $(notdir $(wildcard $(srctree)/logo.bmp))
200
-LOGO_KERNEL := $(notdir $(wildcard $(srctree)/logo_kernel.bmp))
201
-
202
-%.img: rockchip/%.dtb kernel.img $(LOGO) $(LOGO_KERNEL)
203218 $(Q)$(srctree)/scripts/mkimg --dtb $*.dtb
204219
205220 CLEAN_DIRS += out