From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id DB5A2C433FE for ; Sun, 6 Nov 2022 22:02:26 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 3F71084380; Sun, 6 Nov 2022 23:02:24 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmx.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; secure) header.d=gmx.de header.i=@gmx.de header.b="O3AnqXUc"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id CAEC284C36; Sun, 6 Nov 2022 23:02:22 +0100 (CET) Received: from mout.gmx.net (mout.gmx.net [212.227.17.20]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id CC12884198 for ; Sun, 6 Nov 2022 23:02:19 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmx.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=xypron.glpk@gmx.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1667772139; bh=2yHJx/s/ijowr7DjVwsWLZjjduiNlpmpQnan8fPP700=; h=X-UI-Sender-Class:Date:From:To:CC:Subject:In-Reply-To:References; b=O3AnqXUcSpZuVQRB/PGdQkpkOcl3Y9QVQmwS3gQkixoLRTchEFmw3zHyOjrDNQRsc EDG9EuSnX5bkMy73n6C6cRZ5jc9jq1YgfFOzM3HRfDuUGf5ckVZp1VQTqBHjSCSnxm Bcw1xQYW4vR3fKHsWOYet0oHTSuz8RkxMe+ggO7PHV5t7HlH+PnAZeslflVlr73BZV Yj7Zc7LhoNkn36J6Izr/KIvxGM/w93AC5lDiPnY6sfZGzyujVUzqBqxwweMIg0j1xG vEO1ap+h/+7AoIcTwZD8OEGYfDESn221A+LBYH1W4+xK45fLYpBfql8xOobKxEiZbM 98KOwFgYkNNHQ== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from [127.0.0.1] ([84.118.157.2]) by mail.gmx.net (mrgmx105 [212.227.17.168]) with ESMTPSA (Nemesis) id 1MNbkp-1odIq93PGl-00P7dI; Sun, 06 Nov 2022 23:02:18 +0100 Date: Sun, 06 Nov 2022 23:02:22 +0100 From: Heinrich Schuchardt To: Patrick Zacharias CC: u-boot@lists.denx.de, Ilias Apalodimas Subject: Re: [PATCH] efi: arm,arm64: Fix relocations from not being loaded User-Agent: K-9 Mail for Android In-Reply-To: <6a50005e-0e8f-b489-874f-993953916193@web.de> References: <7eeee0cc-2652-83d1-149e-6b5c0eb3b3ef@web.de> <6f2b45fb-8b2e-e1cf-e3f5-5a30f0cefe39@gmx.de> <6a50005e-0e8f-b489-874f-993953916193@web.de> Message-ID: <79106978-6B80-461E-9B39-9970A42F0859@gmx.de> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Provags-ID: V03:K1:TVhoPadZEEGDZ80rp/RLZds7ypzVfvYpCFO9AFcqES6xEP4BHPF xTcJovrJJ7SwzV2Wd/DE1vQkhPpS3C3J04XieO8PS4D9C94bL9ZHb9CZf8XUk5Dh8MZBy06 H8NOGGlZ+IndJ9SxtObM+Z5kxzOSy+ute/B23TQ5MvkNWp8Lb2CO5W52wwp9/0xmrNF+Wmf aO1huIHZKOq/DhJZYTeng== UI-OutboundReport: notjunk:1;M01:P0:JZGmvgtdh/M=;tgsebMTZ4JeTj2ZdAz2Q+j6FAQl j/BjPqMJjC/aZ8R2QhYp8h5SolqrZItkgVoG/BG+pgFz/MG2sLvSIDAJxcKANkNI8TvtBj6eA 5ZurU6FfR7QjChgpVA5yNixbq/t3fjtDoeJOcQCnrHapFu5ZPFcRp1cwzOetsMciUvuz8mFvY 4UQDKb+rYu019u9JkUwPzwaquIQaJ89PsOHB4/zFquESUuEW6A6rGuPdDdHYph0UXfR/4OcNK UtWuegdzaEF9GuudVI/Qi9N9pVluEhrInMVmbCSfhir5Shq9n6hE4AQ8pW63BkCMRywbB/67f eDQJYLvdYVP3yFBnpj8cbEuY2+8HneBS0ySmSWCX52SNOIfrRWR8xFZB7c5u92R1VFt2GvJfu 1KZXrljouSGzCGHbARYrZaltO0acbv4F1PkXKN4oEth0NLgEdNDY9foDVn2OcswBELJPcMsRt T+CYFjHbRpwmxUqlqIAhPMU2sTds0rFNW9rG6ImIxsOyhQqOyhR058froSbr4GUs4L53/l28O SKTvmGd+3gdRXrRJzXb5GcIRJJr8XLbJvLPH3o9YjHcJ42iZ77gSe2vzeEGHwBn8505lCDV6v IdmwrtXRLP/Q2fnze6wyRvqOq+N1RIVQCSrclmzGqlKBKHIlmtx0NrZlaNAvFadiO5HEfuYwh XT372GQ0CevVAs9sIX6Et5xf/jrrrjjgc9voLyDbtqR1MMdVQImz2VriQ0nofBxrtV8VtGzh2 dkOLhlDSlLylKk9WgUJW67cJcE2O21xwMNgVl49elNhgHs4w2LaGVcJ0TJG2wTwIwGbZQQB0X mh/lyAkB+2PfuT9MC6lTLUWvqmtiRFkTzT46KkAwn5mFmgChGjMGqDsVPSIesuFx5Pw/N2aMk F54exDnk+qxsuzjINQyntfWZwX5fGNu8B3Ac2Vvr18LcQOw33tEd30z/VfrcPyujAkLp7py/f e4Ztow== X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.6 at phobos.denx.de X-Virus-Status: Clean Am 6=2E November 2022 19:36:15 MEZ schrieb Patrick Zacharias : >I created a GitHub repository demonstrating the issue, together with inst= ructions on how to build it=2E > >https://github=2Ecom/Fighter19/hello-world-arm-efi Please, check the instructions in https://doc=2Erust-lang=2Eorg/rustc/platform-support/unknown-uefi=2Ehtml Best regards Heinrich > >Currently, when using the old linker file, it will crash=2E >Personally, to test it, I built U-Boot for QEMU and loaded the EFI file v= ia TFTP=2E > >Am 06=2E11=2E22 um 18:03 schrieb Patrick Zacharias: >> Hi Heinrich, >>=20 >> Thanks for the information, I'll make sure to use it for future contrib= utions=2E >>=20 >> I encountered this issue, while building a custom EFI application using= Rust by linking >> the following files: >>=20 >> =2E/arch/arm/lib/reloc_arm_efi=2Ec >> =2E/arch/arm/lib/crt0_arm_efi=2ES >> =2E/arch/arm/lib/elf_arm_efi=2Elds >>=20 >> As well as the custom application built as a library, that exports "efi= _main"=2E >>=20 >> Thus, the relocations were caused by the "write_fmt" functions that Rus= t provides=2E >> I encountered it, when concatenating two strings=2E >> format!("Test {}", "Test2"); >>=20 >> The relocation was not applied and therefor lead to a crash=2E >>=20 >> From my understanding these relocations are ELF relocations and are the= refor applied by the _relocate function (inside the built application) >> and not by the EFI loader=2E This is why I assumed, that it's fine for = these relocations to reside in the data section=2E >>=20 >> I noticed, that in the _relocate function in =2E/arch/arm/lib/reloc_arm= _efi=2Ec, that the case R_ARM_RELATIVE was never entered, >> even though the generated shared object included them=2E >> I then looked at the EFI header file (crt0_arm_efi=2ES) and noticed, th= at it specifies only up to _edata to be loaded=2E >>=20 >> I concluded that _edata needs to be extended to include the ELF relocat= ions as well=2E >>=20 >> After I decided to place it after the relocations, I noticed, that _eda= ta is already specified at the same (new position) in gnu-efi=2E >> This reaffirmed me to contribute the patch as it currently is=2E >>=20 >> I assumed, that on x86, that the linker treats the ELF relocations (=2E= rela=2E*) as if it was part of the data section=2E >> From my understanding the EFI relocations are in =2Ereloc while the ELF= relocations are in =2Erela=2E*=2E >> I might be mistaken, however=2E >>=20 >> Greetings, >> Patrick >>=20 >> Am 06=2E11=2E22 um 10:20 schrieb Heinrich Schuchardt: >>> On 10/31/22 21:01, Patrick Zacharias wrote: >>>> Prior to this commit, the relocations would not get loaded by the efi >>>> loader=2E >>>>=20 >>>> This lead to none of the relocations being applied=2E >>>>=20 >>>> Signed-off-by: Fighter19 <1475802+Fighter19@users=2Enoreply=2Egithub= =2Ecom> >>>=20 >>> Thanks Patrick for your contribution=2E >>>=20 >>> You can use scripts/get_maintainer=2Epl to determine to whom a patch >>> should be sent=2E >>>=20 >>> Where did you actually see relocations? >>> Which code is not position independent? >>>=20 >>>> --- >>>> =C2=A0=C2=A0arch/arm/lib/elf_aarch64_efi=2Elds | 2 +- >>>> =C2=A0=C2=A0arch/arm/lib/elf_arm_efi=2Elds=C2=A0=C2=A0=C2=A0=C2=A0 | = 2 +- >>>> =C2=A0=C2=A02 files changed, 2 insertions(+), 2 deletions(-) >>>>=20 >>>> diff --git a/arch/arm/lib/elf_aarch64_efi=2Elds >>>> b/arch/arm/lib/elf_aarch64_efi=2Elds >>>> index c0604dad46=2E=2E1982864d17 100644 >>>> --- a/arch/arm/lib/elf_aarch64_efi=2Elds >>>> +++ b/arch/arm/lib/elf_aarch64_efi=2Elds >>>> @@ -46,12 +46,12 @@ SECTIONS >>>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 *(COMMON) >>>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =2E =3D ALIGN(512); >>>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 _bss_end =3D =2E; >>>> -=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 _edata =3D =2E; >>>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 } >>>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 =2Erela=2Edyn : { *(=2Erela=2Edyn) } >>>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 =2Erela=2Eplt : { *(=2Erela=2Eplt) } >>>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 =2Erela=2Egot : { *(=2Erela=2Egot) } >>>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 =2Erela=2Edata : { *(=2Erela=2Edata) *= (=2Erela=2Edata*) } >>>> +=C2=A0=C2=A0=C2=A0 _edata =3D =2E; >>>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 _data_size =3D =2E - _etext; >>>>=20 >>>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 =2E =3D ALIGN(4096); >>>> diff --git a/arch/arm/lib/elf_arm_efi=2Elds b/arch/arm/lib/elf_arm_ef= i=2Elds >>>> index 767ebda635=2E=2Ec1b58a8033 100644 >>>> --- a/arch/arm/lib/elf_arm_efi=2Elds >>>> +++ b/arch/arm/lib/elf_arm_efi=2Elds >>>> @@ -46,12 +46,12 @@ SECTIONS >>>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 *(COMMON) >>>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =2E =3D ALIGN(512); >>>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 _bss_end =3D =2E; >>>> -=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 _edata =3D =2E; >>>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 } >>>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 =2Erel=2Edyn : { *(=2Erel=2Edyn) } >>>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 =2Erel=2Eplt : { *(=2Erel=2Eplt) } >>>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 =2Erel=2Egot : { *(=2Erel=2Egot) } >>>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 =2Erel=2Edata : { *(=2Erel=2Edata) *(= =2Erel=2Edata*) } >>>> +=C2=A0=C2=A0=C2=A0 _edata =3D =2E; >>>=20 >>> Relocations (if they exist) should be in the =2Ereloc section, not in = the >>> =2Edata section=2E >>>=20 >>> If we want to create a =2Ereloc section, we have to change >>> arch/arm/lib/crt0_*_efi=2ES too=2E Furthermore the relocation section = must >>> be pointed to by field BaseRelocationTable of the Optional Header Data >>> Directories (see PE-COFF specification)=2E >>>=20 >>> Please, consider the other UEFI architectures (x86 and RISC-V) too=2E >>>=20 >>> Best regards >>>=20 >>> Heinrich >>>=20 >>>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 _data_size =3D =2E - _etext; >>>>=20 >>>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 /DISCARD/ : { >>>=20 >