With aarch64-gnu-linux-gcc version 6 or later, you can’t use -fPIC and -mcmodel=large at the same time.
I found I needed this patch to be able to build the kernel. This is essentially 6ffe9923f2350c19b95a2c9ebf1b4f5f275986f2 from upstream git.
diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig
index 10a4fd489da0..181786d646d3 100644
--- a/arch/arm64/Kconfig
+++ b/arch/arm64/Kconfig
@@ -360,17 +360,13 @@ config ARM64_ERRATUM_845719
config ARM64_ERRATUM_843419
bool "Cortex-A53: 843419: A load or store might access an incorrect address"
- depends on MODULES
default y
+ select ARM64_MODULE_CMODEL_LARGE if MODULES
help
- This option builds kernel modules using the large memory model in
- order to avoid the use of the ADRP instruction, which can cause
- a subsequent memory access to use an incorrect address on Cortex-A53
- parts up to r0p4.
-
- Note that the kernel itself must be linked with a version of ld
- which fixes potentially affected ADRP instructions through the
- use of veneers.
+ This option links the kernel with '--fix-cortex-a53-843419' and
+ builds modules using the large memory model in order to avoid the use
+ of the ADRP instruction, which can cause a subsequent memory access
+ to use an incorrect address on Cortex-A53 parts up to r0p4.
If unsure, say Y.
diff --git a/arch/arm64/Makefile b/arch/arm64/Makefile
index cf65c159575e..9033ff7e95e2 100644
--- a/arch/arm64/Makefile
+++ b/arch/arm64/Makefile
@@ -15,6 +15,15 @@ CPPFLAGS_vmlinux.lds = -DTEXT_OFFSET=$(TEXT_OFFSET)
OBJCOPYFLAGS :=-O binary -R .note -R .note.gnu.build-id -R .comment -S
GZFLAGS :=-9
+ifeq ($(CONFIG_ARM64_ERRATUM_843419),y)
+ld-843419-workaround := $(call ld-option, --fix-cortex-a53-843419)
+ ifeq ($(ld-843419-workaround),)
+$(warning ld does not support --fix-cortex-a53-843419; kernel may be susceptible to erratum)
+ else
+LDFLAGS_vmlinux += --fix-cortex-a53-843419
+ endif
+endif
+
KBUILD_DEFCONFIG := defconfig
# Check for binutils support for specific extensions
@@ -42,9 +51,6 @@ endif
CHECKFLAGS += -D__aarch64__
-ifeq ($(CONFIG_ARM64_ERRATUM_843419), y)
-KBUILD_CFLAGS_MODULE += -mcmodel=large
-endif
# Default value
head-y := arch/arm64/kernel/head.o