From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=209.132.183.28; helo=mx1.redhat.com; envelope-from=lersek@redhat.com; receiver=edk2-devel@lists.01.org Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 78E7521199279 for ; Tue, 11 Dec 2018 07:57:14 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E0DA73091743; Tue, 11 Dec 2018 15:57:13 +0000 (UTC) Received: from lacos-laptop-7.usersys.redhat.com (ovpn-120-134.rdu2.redhat.com [10.10.120.134]) by smtp.corp.redhat.com (Postfix) with ESMTP id AD9E81059580; Tue, 11 Dec 2018 15:57:12 +0000 (UTC) To: Ard Biesheuvel , edk2-devel@lists.01.org Cc: Bob Feng , Liming Gao , Leif Lindholm References: <20181211093715.6048-1-ard.biesheuvel@linaro.org> From: Laszlo Ersek Message-ID: <2ed27ba2-eb09-0921-4024-e2f1a7ce87cc@redhat.com> Date: Tue, 11 Dec 2018 16:57:11 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: <20181211093715.6048-1-ard.biesheuvel@linaro.org> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Tue, 11 Dec 2018 15:57:14 +0000 (UTC) Subject: Re: [PATCH] BaseTools/GenFw ARM: don't permit R_ARM_GOT_PREL relocations X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 11 Dec 2018 15:57:14 -0000 Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit On 12/11/18 10:37, Ard Biesheuvel wrote: > We currently permit R_ARM_GOT_PREL relocations in the ELF32 conversion > routines, under the assumption that relative relocations are fine as > long as the section layout is the same between ELF and PE/COFF. > > However, as is the case with any proxy generating relocation, it is > up to the linker to emit an entry in the GOT table and populate it > with the correct absolute address, which should also be fixed up at > PE/COFF load time. Unfortunately, the relocations covering the GOT > section are not emitted into the static relocation sections processed > by GenFw, but only in the dynamic relocation section as a R_ARM_RELATIVE > relocation, and so GenFw fails to emit the correct PE/COFF relocation > data for GOT entries. > > Since GOT indirection is pointless anyway for PE/COFF modules running > in UEFI context, let's just drop the references to R_ARM_GOT_PREL from > GenFw, resulting in a build time failure rather than a runtime failure > if such relocations do occur. > > Cc: Bob Feng > Cc: Liming Gao > Cc: Leif Lindholm > Contributed-under: TianoCore Contribution Agreement 1.1 > Signed-off-by: Ard Biesheuvel > --- > > Without this patch, CLANG38 builds of ArmVirtQemuKernel-ARM (in LTO mode) > succeed, but the resulting binaries are broken. This is due to the fact that > the PIE linker running in LTO mode insists on emitting GOT based relocations, > while we don't have the code to fix up the contents of the GOT. This change > puts it in line with the AARCH64 build of the same platform/toolchains, > which chokes on GOT based relocations as well. Since the use of the PIE > linker is a peculiarity of ArmVirtQemuKernel/ArmVirtXen, and the fact that > it is impossible to prevent the linker from emitting GOT based relocations, > let's not go out of our way to fix it in the tools, but just drop CLANG38 > support from those platforms. > > BaseTools/Source/C/GenFw/Elf32Convert.c | 2 -- > 1 file changed, 2 deletions(-) > > diff --git a/BaseTools/Source/C/GenFw/Elf32Convert.c b/BaseTools/Source/C/GenFw/Elf32Convert.c > index 3d7de6d5c123..23e8065756e6 100644 > --- a/BaseTools/Source/C/GenFw/Elf32Convert.c > +++ b/BaseTools/Source/C/GenFw/Elf32Convert.c > @@ -837,7 +837,6 @@ WriteSections32 ( > case R_ARM_LDC_PC_G0: > case R_ARM_LDC_PC_G1: > case R_ARM_LDC_PC_G2: > - case R_ARM_GOT_PREL: > case R_ARM_THM_JUMP11: > case R_ARM_THM_JUMP8: > case R_ARM_TLS_GD32: > @@ -964,7 +963,6 @@ WriteRelocations32 ( > case R_ARM_LDC_PC_G0: > case R_ARM_LDC_PC_G1: > case R_ARM_LDC_PC_G2: > - case R_ARM_GOT_PREL: > case R_ARM_THM_JUMP11: > case R_ARM_THM_JUMP8: > case R_ARM_TLS_GD32: > Acked-by: Laszlo Ersek