arm64: link with -z norelro regardless of CONFIG_RELOCATABLE
[GitHub/LineageOS/G12/android_kernel_amlogic_linux-4.9.git] / arch / arm64 / Makefile
CommitLineData
8c2c3df3
CM
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
d4abc006 13LDFLAGS_vmlinux :=--no-undefined -X -z norelro
8c2c3df3 14CPPFLAGS_vmlinux.lds = -DTEXT_OFFSET=$(TEXT_OFFSET)
8c2c3df3
CM
15GZFLAGS :=-9
16
b7ada2c0
ND
17ifeq ($(CONFIG_RELOCATABLE), y)
18# Pass --no-apply-dynamic-relocs to restore pre-binutils-2.27 behaviour
19# for relative relocs, since this leads to better Image compression
20# with the relocation offsets always being zero.
d4abc006 21LDFLAGS_vmlinux += -shared -Bsymbolic -z notext \
b7ada2c0 22 $(call ld-option, --no-apply-dynamic-relocs)
1e48ef7f
AB
23endif
24
6ffe9923
WD
25ifeq ($(CONFIG_ARM64_ERRATUM_843419),y)
26 ifeq ($(call ld-option, --fix-cortex-a53-843419),)
27$(warning ld does not support --fix-cortex-a53-843419; kernel may be susceptible to erratum)
28 else
5c41c483
ST
29 ifeq ($(call gold-ifversion, -lt, 114000000, y), y)
30$(warning This version of GNU gold may generate incorrect code with --fix-cortex-a53-843419;\
31 see https://sourceware.org/bugzilla/show_bug.cgi?id=21491)
32 endif
6ffe9923
WD
33LDFLAGS_vmlinux += --fix-cortex-a53-843419
34 endif
5c41c483
ST
35else
36 ifeq ($(ld-name),gold)
37# Pass --no-fix-cortex-a53-843419 to ensure the erratum fix is disabled
38LDFLAGS += --no-fix-cortex-a53-843419
39 endif
6ffe9923
WD
40endif
41
8c2c3df3
CM
42KBUILD_DEFCONFIG := defconfig
43
c09d6a04
WD
44# Check for binutils support for specific extensions
45lseinstr := $(call as-instr,.arch_extension lse,-DCONFIG_AS_LSE=1)
46
47ifeq ($(CONFIG_ARM64_LSE_ATOMICS), y)
48 ifeq ($(lseinstr),)
49$(warning LSE atomics not supported by binutils)
50 endif
51endif
52
e07bcf71
GH
53ifeq ($(cc-name),clang)
54# This is a workaround for https://bugs.llvm.org/show_bug.cgi?id=30792.
55# TODO: revert when this is fixed in LLVM.
56KBUILD_CFLAGS += -mno-implicit-float
57else
58KBUILD_CFLAGS += -mgeneral-regs-only
59endif
60KBUILD_CFLAGS += $(lseinstr)
3af78e25
KB
61
62ifeq ($(CONFIG_COMPAT_VDSO), y)
63 CROSS_COMPILE_ARM32 ?= $(CONFIG_CROSS_COMPILE_ARM32:"%"=%)
64 # Check that the user has provided a valid prefix for the 32-bit toolchain.
65 # To prevent selecting the system $(cc-name) by default, the prefix is not
66 # allowed to be empty, unlike CROSS_COMPILE. In the unlikely event that the
67 # system $(cc-name) is actually the 32-bit ARM compiler to be used, the
68 # variable can be set to the dirname (e.g. CROSS_COMPILE_ARM32=/usr/bin/).
69 # Note: this Makefile is read both before and after regenerating the config
70 # (if needed). Any warning appearing before the config has been regenerated
71 # should be ignored. If the error is triggered and you set
72 # CONFIG_CROSS_COMPILE_ARM32, set CROSS_COMPILE_ARM32 to an appropriate value
73 # when invoking make and fix CONFIG_CROSS_COMPILE_ARM32.
74 ifeq ($(CROSS_COMPILE_ARM32),)
85e71857 75 $(error CROSS_COMPILE_ARM32 not defined or empty, the compat vDSO will not be built)
3af78e25
KB
76 else ifeq ($(cc-name),clang)
77 export CLANG_TRIPLE_ARM32 ?= $(CROSS_COMPILE_ARM32)
78 export CLANG_TARGET_ARM32 := --target=$(notdir $(CLANG_TRIPLE_ARM32:%-=%))
46d96430
DM
79 export GCC_TOOLCHAIN32_DIR := $(dir $(shell which $(CROSS_COMPILE_ARM32)ld))
80 export GCC_TOOLCHAIN32 := $(realpath $(GCC_TOOLCHAIN32_DIR)/..)
81 export CLANG_PREFIX32 := --prefix=$(GCC_TOOLCHAIN32_DIR)
82 export CLANG_GCC32_TC := --gcc-toolchain=$(GCC_TOOLCHAIN32)
3af78e25
KB
83 export CONFIG_VDSO32 := y
84 vdso32 := -DCONFIG_VDSO32=1
85 else ifeq ($(shell which $(CROSS_COMPILE_ARM32)$(cc-name) 2> /dev/null),)
86 $(error $(CROSS_COMPILE_ARM32)$(cc-name) not found, check CROSS_COMPILE_ARM32)
87 else
88 export CROSS_COMPILE_ARM32
89 export CONFIG_VDSO32 := y
90 vdso32 := -DCONFIG_VDSO32=1
91 endif
92endif
93
94KBUILD_CFLAGS += $(vdso32)
728dabd6 95KBUILD_CFLAGS += -fno-asynchronous-unwind-tables
67dfa175 96KBUILD_CFLAGS += $(call cc-option, -mpc-relative-literal-loads)
a9c2864f 97KBUILD_CFLAGS += -fno-pic
3af78e25 98KBUILD_AFLAGS += $(lseinstr) $(vdso32)
c09d6a04 99
a0974e6e
WD
100ifeq ($(CONFIG_CPU_BIG_ENDIAN), y)
101KBUILD_CPPFLAGS += -mbig-endian
102AS += -EB
c034eae9
OJ
103# Prefer the baremetal ELF build target, but not all toolchains include
104LDFLAGS += -EB $(call ld-option, -maarch64elfb, -maarch64linuxb)
cfa88c79 105UTS_MACHINE := aarch64_be
a0974e6e 106else
8c2c3df3
CM
107KBUILD_CPPFLAGS += -mlittle-endian
108AS += -EL
c034eae9
OJ
109# Same as above, prefer ELF but fall back to linux target if needed.
110LDFLAGS += -EL $(call ld-option, -maarch64elf, -maarch64linux)
cfa88c79 111UTS_MACHINE := aarch64
a0974e6e 112endif
8c2c3df3 113
8c2c3df3
CM
114CHECKFLAGS += -D__aarch64__
115
fd045f6c 116ifeq ($(CONFIG_ARM64_MODULE_CMODEL_LARGE), y)
b6dd8e07 117KBUILD_CFLAGS_MODULE += -mcmodel=large
7e77d5ee
ST
118ifeq ($(CONFIG_LTO_CLANG), y)
119# Code model is not stored in LLVM IR, so we need to pass it also to LLVMgold
35740bcd 120KBUILD_LDFLAGS_MODULE += -plugin-opt=-code-model=large
7e77d5ee 121endif
df057cc7
WD
122endif
123
fd045f6c
AB
124ifeq ($(CONFIG_ARM64_MODULE_PLTS),y)
125KBUILD_LDFLAGS_MODULE += -T $(srctree)/arch/arm64/kernel/module.lds
126endif
127
8c2c3df3
CM
128# Default value
129head-y := arch/arm64/kernel/head.o
130
131# The byte offset of the kernel image in RAM from the start of RAM.
da57a369 132ifeq ($(CONFIG_ARM64_RANDOMIZE_TEXT_OFFSET), y)
aed7eb83
MR
133TEXT_OFFSET := $(shell awk "BEGIN {srand(); printf \"0x%06x\n\", \
134 int(2 * 1024 * 1024 / (2 ^ $(CONFIG_ARM64_PAGE_SHIFT)) * \
135 rand()) * (2 ^ $(CONFIG_ARM64_PAGE_SHIFT))}")
da57a369 136else
bfc0d5ba 137TEXT_OFFSET := 0x01080000
da57a369 138endif
8c2c3df3 139
c3d5669e
MK
140ifeq ($(cc-name),clang)
141KBUILD_CFLAGS += $(call cc-disable-warning, asm-operand-widths)
142endif
143
39d114dd
AR
144# KASAN_SHADOW_OFFSET = VA_START + (1 << (VA_BITS - 3)) - (1 << 61)
145# in 32-bit arithmetic
146KASAN_SHADOW_OFFSET := $(shell printf "0x%08x00000000\n" $$(( \
147 (0xffffffff & (-1 << ($(CONFIG_ARM64_VA_BITS) - 32))) \
148 + (1 << ($(CONFIG_ARM64_VA_BITS) - 32 - 3)) \
149 - (1 << (64 - 32 - 3)) )) )
150
8c2c3df3
CM
151export TEXT_OFFSET GZFLAGS
152
153core-y += arch/arm64/kernel/ arch/arm64/mm/
e54bcde3 154core-$(CONFIG_NET) += arch/arm64/net/
6211753f 155core-$(CONFIG_KVM) += arch/arm64/kvm/
63917f0b 156core-$(CONFIG_XEN) += arch/arm64/xen/
2c98833a 157core-$(CONFIG_CRYPTO) += arch/arm64/crypto/
8c2c3df3 158libs-y := arch/arm64/lib/ $(libs-y)
ad08fd49 159core-$(CONFIG_EFI_STUB) += $(objtree)/drivers/firmware/efi/libstub/lib.a
8c2c3df3
CM
160
161# Default target when executing plain make
911da239 162ifeq ($(CONFIG_BUILD_ARM64_APPENDED_DTB_IMAGE),y)
4bdcc936 163KBUILD_IMAGE := $(subst $\",,$(CONFIG_BUILD_ARM64_APPENDED_KERNEL_IMAGE_NAME))
911da239 164else
70f915a2 165KBUILD_IMAGE := Image.gz
911da239
AR
166endif
167
70f915a2 168KBUILD_DTBS := dtbs
8c2c3df3 169
70f915a2 170all: $(KBUILD_IMAGE) $(KBUILD_DTBS)
8c2c3df3
CM
171
172boot := arch/arm64/boot
173
0723c05f
OJ
174Image: vmlinux
175 $(Q)$(MAKE) $(build)=$(boot) $(boot)/$@
176
9ca4e58c 177Image.%: Image
70f915a2 178 $(Q)$(MAKE) $(build)=$(boot) $(boot)/$@
8c2c3df3 179
8684fa3e 180zinstall install:
70f915a2 181 $(Q)$(MAKE) $(build)=$(boot) $@
8c2c3df3 182
feea4603
HL
183amlogic/%.dtb: scripts
184 $(Q)$(MAKE) $(build)=$(boot)/dts $(boot)/dts/$@
185
70f915a2 186%.dtb: scripts
e655ebfc 187 $(Q)$(MAKE) $(build)=$(boot)/dts/amlogic $(boot)/dts/amlogic/$@
5ff7ef06 188ifeq ($(CONFIG_AMLOGIC_MODIFY),y)
189%.dtbo: scripts
190 $(Q)$(MAKE) $(build)=$(boot)/dts/amlogic $(boot)/dts/amlogic/$@
191endif
70f915a2 192
862f464a 193PHONY += dtbs dtbs_install
9fb5e537
RR
194
195dtbs: prepare scripts
d38726c4 196 $(Q)$(MAKE) $(build)=$(boot)/dts
8c2c3df3 197
9fb5e537
RR
198dtbs_install:
199 $(Q)$(MAKE) $(dtbinst)=$(boot)/dts
200
e23ef5fc 201Image-dtb Image.gz-dtb: vmlinux scripts dtbs
911da239
AR
202 $(Q)$(MAKE) $(build)=$(boot) $(boot)/$@
203
3c01742a
KM
204PHONY += vdso_install
205vdso_install:
206 $(Q)$(MAKE) $(build)=arch/arm64/kernel/vdso $@
207
8c2c3df3
CM
208# We use MRPROPER_FILES and CLEAN_FILES now
209archclean:
210 $(Q)$(MAKE) $(clean)=$(boot)
c7c52e48 211 $(Q)$(MAKE) $(clean)=$(boot)/dts
8c2c3df3 212
b2c50f6f 213ifeq ($(KBUILD_EXTMOD),)
a66649da
KB
214# We need to generate vdso-offsets.h before compiling certain files in kernel/.
215# In order to do that, we should use the archprepare target, but we can't since
216# asm-offsets.h is included in some files used to generate vdso-offsets.h, and
217# asm-offsets.h is built in prepare0, for which archprepare is a dependency.
218# Therefore we need to generate the header after prepare0 has been made, hence
219# this hack.
220prepare: vdso_prepare
221vdso_prepare: prepare0
222 $(Q)$(MAKE) $(build)=arch/arm64/kernel/vdso include/generated/vdso-offsets.h
3af78e25
KB
223 $(if $(CONFIG_VDSO32),$(Q)$(MAKE) $(build)=arch/arm64/kernel/vdso32 \
224 include/generated/vdso32-offsets.h)
b2c50f6f 225endif
a66649da 226
8c2c3df3
CM
227define archhelp
228 echo '* Image.gz - Compressed kernel image (arch/$(ARCH)/boot/Image.gz)'
229 echo ' Image - Uncompressed kernel image (arch/$(ARCH)/boot/Image)'
70f915a2 230 echo '* dtbs - Build device tree blobs for enabled boards'
862f464a 231 echo ' dtbs_install - Install dtbs to $(INSTALL_DTBS_PATH)'
8c2c3df3
CM
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'
237endef