From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.61]) by mx.groups.io with SMTP id smtpd.web12.2261.1591897864126795342 for ; Thu, 11 Jun 2020 10:51:04 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=iZeDqdPx; spf=pass (domain: redhat.com, ip: 205.139.110.61, mailfrom: lersek@redhat.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1591897863; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=EzqtWf9DR9PAqHchFIITyuL7iTolHoMCTOzVYe/u358=; b=iZeDqdPx+tQ2BG5aaYplTq3y74sjXVKJHE217VJgLr9xH4usvAnTm2JJlKn4WorW4t/iCT lxeD6Qd2Of/Wk+9V7FP639/K6WG9OhcR0uFlYrs8sfcSSgKqxe9KoncyfljWLdUZdTUywg f4xH9sTnIfColkn8vW912WMQz8++FaE= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-438-_wy5Ig4BPZuu2aXuP3u2ng-1; Thu, 11 Jun 2020 13:50:55 -0400 X-MC-Unique: _wy5Ig4BPZuu2aXuP3u2ng-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id ECBC68018A2; Thu, 11 Jun 2020 17:50:53 +0000 (UTC) Received: from lacos-laptop-7.usersys.redhat.com (ovpn-114-21.ams2.redhat.com [10.36.114.21]) by smtp.corp.redhat.com (Postfix) with ESMTP id 164308929A; Thu, 11 Jun 2020 17:50:51 +0000 (UTC) Subject: Re: [PATCH v2 0/3] ArmVirtPkg: use PE/COFF metadata for self relocation To: Ard Biesheuvel , devel@edk2.groups.io Cc: Leif Lindholm , Ilias Apalodimas , Julien Grall , Jiewen Yao , Sami Mujawar References: <20200611125228.252500-1-ard.biesheuvel@arm.com> From: "Laszlo Ersek" Message-ID: Date: Thu, 11 Jun 2020 19:50:50 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Firefox/52.0 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: <20200611125228.252500-1-ard.biesheuvel@arm.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit On 06/11/20 14:52, Ard Biesheuvel wrote: > As suggested by Jiewen in response to Ilias RFC [0], it is better to use > the PE/COFF metadata for self-relocating executables than to rely on ELF > metadata, given how the latter is only available when using ELF based > toolchains. Also, we have had some maintenance issues with this code in > the past, as PIE linking of non-position independent objects is not a well > tested code path in toolchains in general. > > So implement this for the self-relocating PrePi in ArmVirtPkg first. > > First, we need to ensure that the module in question is emitted with its > PE/COFF relocation metadata preserved, by creating a special FDF rule. > > We also need to provide a way for the code to refer to the start of the > image directly, by adding it to the linker script. > > Then, it is simply a matter of swapping out the two assembly routines, > and adding the C code that serves the same purpose but based on PE/COFF > base relocations. > > Note that PE/COFF relocations are considerably more compact than ELF RELA > relocations, so this does not impact the memory footprint of the resulting > image adversely. > > [0] https://edk2.groups.io/g/devel/message/60835 > > Changes since v1: > - Drop change to linker script, and instead, use the existing FV parsing code > (which is already incorporated into PrePi to load other modules), to find > the start address of the image before relocation. This way, we can support > TE images as well as PE32 images naturally, and not rely on GCC/binutils > specific artifacts that make porting to a native PE/COFF toolchain more > difficult > - Switch to TE format in the SELF_RELOC FDF rule - this is not terribly > likely to matter in practice, but since PrePi is the only module that > is incorporated in uncompressed form, and given that we used TE format > before these changes, it is a more appropriate default. Right, I noticed that when I compared the new rule in v1 against the pre-existent SEC rule. I'm happy to see my feedback tags carried forward. Thanks Laszlo > - Add acks from Jiewen, Laszlo and Sami. Note that I have dropped the > Tested-bys - apologies for wasting anyone's time, but they could not > be carried over due to the changes. > > Cc: Laszlo Ersek > Cc: Leif Lindholm > Cc: Ilias Apalodimas > Cc: Julien Grall > Cc: Jiewen Yao > Cc: Sami Mujawar > > Ard Biesheuvel (3): > ArmVirtPkg: add FDF rule for self-relocating PrePi > ArmVirtPkg/PrePi: use standard PeCoff routines for self-relocation > ArmVirtPkg: remove unused files > > ArmVirtPkg/ArmVirtQemuKernel.dsc | 10 ++-- > ArmVirtPkg/ArmVirtXen.dsc | 10 ++-- > ArmVirtPkg/ArmVirtQemuKernel.fdf | 2 +- > ArmVirtPkg/ArmVirtXen.fdf | 2 +- > ArmVirtPkg/PrePi/ArmVirtPrePiUniCoreRelocatable.inf | 4 +- > ArmVirtPkg/Include/Platform/Hidden.h | 22 --------- > ArmVirtPkg/PrePi/PrePi.c | 35 ++++++++++++++ > ArmVirtPkg/ArmVirtRules.fdf.inc | 5 ++ > ArmVirtPkg/PrePi/AArch64/ModuleEntryPoint.S | 49 +++++--------------- > ArmVirtPkg/PrePi/Arm/ModuleEntryPoint.S | 47 +++++-------------- > ArmVirtPkg/PrePi/Scripts/PrePi-PIE.lds | 41 ---------------- > 11 files changed, 75 insertions(+), 152 deletions(-) > delete mode 100644 ArmVirtPkg/Include/Platform/Hidden.h > delete mode 100644 ArmVirtPkg/PrePi/Scripts/PrePi-PIE.lds >