.. | .. |
---|
10 | 10 | # |
---|
11 | 11 | # Copyright (C) 1995-2001 by Russell King |
---|
12 | 12 | |
---|
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 |
---|
16 | 14 | |
---|
17 | 15 | ifeq ($(CONFIG_RELOCATABLE), y) |
---|
18 | 16 | # Pass --no-apply-dynamic-relocs to restore pre-binutils-2.27 behaviour |
---|
.. | .. |
---|
30 | 28 | endif |
---|
31 | 29 | endif |
---|
32 | 30 | |
---|
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) |
---|
40 | 33 | $(warning LSE atomics not supported by binutils) |
---|
41 | 34 | endif |
---|
42 | 35 | endif |
---|
43 | 36 | |
---|
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) |
---|
46 | 42 | |
---|
47 | | - ifneq ($(brokengasinst),) |
---|
| 43 | +ifeq ($(CONFIG_BROKEN_GAS_INST),y) |
---|
48 | 44 | $(warning Detected assembler with broken .inst; disassembly will be unreliable) |
---|
49 | | - endif |
---|
50 | 45 | endif |
---|
51 | 46 | |
---|
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) |
---|
54 | 49 | KBUILD_CFLAGS += $(call cc-disable-warning, psabi) |
---|
55 | | -KBUILD_AFLAGS += $(lseinstr) $(brokengasinst) $(compat_vdso) |
---|
| 50 | +KBUILD_AFLAGS += $(compat_vdso) |
---|
56 | 51 | |
---|
57 | 52 | KBUILD_CFLAGS += $(call cc-option,-mabi=lp64) |
---|
58 | 53 | 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 |
---|
59 | 108 | |
---|
60 | 109 | ifeq ($(CONFIG_SHADOW_CALL_STACK), y) |
---|
61 | 110 | KBUILD_CFLAGS += -ffixed-x18 |
---|
.. | .. |
---|
64 | 113 | ifeq ($(CONFIG_CPU_BIG_ENDIAN), y) |
---|
65 | 114 | KBUILD_CPPFLAGS += -mbig-endian |
---|
66 | 115 | CHECKFLAGS += -D__AARCH64EB__ |
---|
67 | | -AS += -EB |
---|
68 | 116 | # Prefer the baremetal ELF build target, but not all toolchains include |
---|
69 | 117 | # 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) |
---|
71 | 119 | UTS_MACHINE := aarch64_be |
---|
72 | 120 | else |
---|
73 | 121 | KBUILD_CPPFLAGS += -mlittle-endian |
---|
74 | 122 | CHECKFLAGS += -D__AARCH64EL__ |
---|
75 | | -AS += -EL |
---|
76 | 123 | # 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) |
---|
78 | 125 | UTS_MACHINE := aarch64 |
---|
| 126 | +endif |
---|
| 127 | + |
---|
| 128 | +ifeq ($(CONFIG_LD_IS_LLD), y) |
---|
| 129 | +KBUILD_LDFLAGS += -z norelro |
---|
79 | 130 | endif |
---|
80 | 131 | |
---|
81 | 132 | CHECKFLAGS += -D__aarch64__ |
---|
82 | 133 | |
---|
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 |
---|
85 | 137 | endif |
---|
86 | 138 | |
---|
87 | 139 | # Default value |
---|
88 | 140 | head-y := arch/arm64/kernel/head.o |
---|
89 | 141 | |
---|
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 | | - |
---|
99 | 142 | ifeq ($(CONFIG_KASAN_SW_TAGS), y) |
---|
100 | 143 | KASAN_SHADOW_SCALE_SHIFT := 4 |
---|
101 | | -else |
---|
| 144 | +else ifeq ($(CONFIG_KASAN_GENERIC), y) |
---|
102 | 145 | KASAN_SHADOW_SCALE_SHIFT := 3 |
---|
103 | 146 | endif |
---|
104 | 147 | |
---|
.. | .. |
---|
106 | 149 | KBUILD_CPPFLAGS += -DKASAN_SHADOW_SCALE_SHIFT=$(KASAN_SHADOW_SCALE_SHIFT) |
---|
107 | 150 | KBUILD_AFLAGS += -DKASAN_SHADOW_SCALE_SHIFT=$(KASAN_SHADOW_SCALE_SHIFT) |
---|
108 | 151 | |
---|
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/ |
---|
124 | 153 | 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 |
---|
126 | 155 | |
---|
127 | 156 | # Default target when executing plain make |
---|
128 | 157 | boot := arch/arm64/boot |
---|
129 | 158 | KBUILD_IMAGE := $(boot)/Image.gz |
---|
130 | | -KBUILD_DTBS := dtbs |
---|
131 | 159 | |
---|
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 |
---|
133 | 164 | |
---|
134 | 165 | |
---|
135 | 166 | Image: vmlinux |
---|
.. | .. |
---|
141 | 172 | zinstall install: |
---|
142 | 173 | $(Q)$(MAKE) $(build)=$(boot) $@ |
---|
143 | 174 | |
---|
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 | | - |
---|
155 | 175 | PHONY += vdso_install |
---|
156 | 176 | vdso_install: |
---|
157 | 177 | $(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 $@) |
---|
159 | 180 | |
---|
160 | 181 | # We use MRPROPER_FILES and CLEAN_FILES now |
---|
161 | 182 | archclean: |
---|
162 | 183 | $(Q)$(MAKE) $(clean)=$(boot) |
---|
163 | | - $(Q)$(MAKE) $(clean)=$(boot)/dts |
---|
164 | 184 | |
---|
165 | 185 | ifeq ($(KBUILD_EXTMOD),) |
---|
166 | 186 | # We need to generate vdso-offsets.h before compiling certain files in kernel/. |
---|
.. | .. |
---|
180 | 200 | define archhelp |
---|
181 | 201 | echo '* Image.gz - Compressed kernel image (arch/$(ARCH)/boot/Image.gz)' |
---|
182 | 202 | 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)' |
---|
185 | 203 | echo ' install - Install uncompressed kernel' |
---|
186 | 204 | echo ' zinstall - Install compressed kernel' |
---|
187 | 205 | echo ' Install using (your) ~/bin/installkernel or' |
---|
.. | .. |
---|
189 | 207 | echo ' install to $$(INSTALL_PATH) and run lilo' |
---|
190 | 208 | endef |
---|
191 | 209 | |
---|
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 |
---|
197 | 217 | 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) |
---|
203 | 218 | $(Q)$(srctree)/scripts/mkimg --dtb $*.dtb |
---|
204 | 219 | |
---|
205 | 220 | CLEAN_DIRS += out |
---|