From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754182AbdEIUul (ORCPT ); Tue, 9 May 2017 16:50:41 -0400 Received: from mail-pg0-f54.google.com ([74.125.83.54]:35683 "EHLO mail-pg0-f54.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751883AbdEIUuj (ORCPT ); Tue, 9 May 2017 16:50:39 -0400 Subject: Re: [PATCH] efi/libstub: Indicate clang the relocation mode for arm64 To: Matthias Kaehlcke , Matt Fleming , Ard Biesheuvel References: <20170509193612.64105-1-mka@chromium.org> Cc: linux-efi@vger.kernel.org, linux-kernel@vger.kernel.org, Grant Grundler , Michael Davidson , =?UTF-8?Q?Bernhard_Rosenkr=c3=a4nzer?= From: Greg Hackmann Message-ID: <25d94b46-765e-f12f-a287-853c76782143@google.com> Date: Tue, 9 May 2017 13:50:36 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 MIME-Version: 1.0 In-Reply-To: <20170509193612.64105-1-mka@chromium.org> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 05/09/2017 12:36 PM, Matthias Kaehlcke wrote: > From: Greg Hackmann > > 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 > Signed-off-by: Bernhard Rosenkränzer > Signed-off-by: Matthias Kaehlcke > --- > drivers/firmware/efi/libstub/Makefile | 6 ++++++ > 1 file changed, 6 insertions(+) > > diff --git a/drivers/firmware/efi/libstub/Makefile b/drivers/firmware/efi/libstub/Makefile > index f7425960f6a5..ccbaaf4d8650 100644 > --- a/drivers/firmware/efi/libstub/Makefile > +++ b/drivers/firmware/efi/libstub/Makefile > @@ -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 > > @@ -38,6 +41,9 @@ $(obj)/lib-%.o: $(srctree)/lib/%.c FORCE > > lib-$(CONFIG_EFI_ARMSTUB) += arm-stub.o fdt.o string.o random.o \ > $(patsubst %.c,lib-%.o,$(arm-deps)) > +ifeq ($(cc-name),clang) > +CFLAGS_arm64-stub.o += -fno-pic > +endif > > lib-$(CONFIG_ARM) += arm32-stub.o > lib-$(CONFIG_ARM64) += arm64-stub.o > NAK. This patch was labeled "HACK:" in our experimental tree. There's no rhyme or reason to why this combination of -f[no-]pic flags generates code without problematic relocations. It's inherently fragile, and was only intended as a temporary workaround until I (or someone more familiar with EFI) got a chance to revisit the problem. Unless the gcc CFLAGS are also an artifact of "mess with -f[no-]pic until the compiler generates what you want", this doesn't belong upstream.