HACK: firmware, LLVMLinux: fix EFI libstub with clang
authorBernhard Rosenkränzer <bero@linaro.org>
Wed, 22 Feb 2017 23:42:02 +0000 (00:42 +0100)
committerStefan Agner <stefan@agner.ch>
Mon, 7 Aug 2017 06:21:11 +0000 (23:21 -0700)
Without any extra guidance, clang will generate libstub with either
absolute or relative ELF relocations.  Use the right combination of
-fpic and -fno-pic on different files to avoid this.

Signed-off-by: Greg Hackmann <ghackmann@google.com>
Forward-ported-by: Bernhard Rosenkränzer <bero@linaro.org>
Signed-off-by: Bernhard Rosenkränzer <bero@linaro.org>
drivers/firmware/efi/libstub/Makefile

index 37e24f525162e10d95e625953773783349ee1316..4b58bd0fafb26b058ff921622a9debd49bf97d51 100644 (file)
@@ -11,6 +11,9 @@ cflags-$(CONFIG_X86)          += -m$(BITS) -D__KERNEL__ -O2 \
                                   -mno-mmx -mno-sse
 
 cflags-$(CONFIG_ARM64)         := $(subst -pg,,$(KBUILD_CFLAGS))
+ifeq ($(cc-name),clang)
+cflags-$(CONFIG_ARM64)         += -fpic
+endif
 cflags-$(CONFIG_ARM)           := $(subst -pg,,$(KBUILD_CFLAGS)) \
                                   -fno-builtin -fpic -mno-single-pic-base
 
@@ -43,6 +46,9 @@ lib-$(CONFIG_EFI_ARMSTUB)     += arm-stub.o fdt.o string.o random.o \
 lib-$(CONFIG_ARM)              += arm32-stub.o
 lib-$(CONFIG_ARM64)            += arm64-stub.o
 CFLAGS_arm64-stub.o            := -DTEXT_OFFSET=$(TEXT_OFFSET)
+ifeq ($(cc-name),clang)
+CFLAGS_arm64-stub.o            += -fno-pic
+endif
 
 #
 # arm64 puts the stub in the kernel proper, which will unnecessarily retain all