From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web11.144.1591637664005982080 for ; Mon, 08 Jun 2020 10:34:24 -0700 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: arm.com, ip: 217.140.110.172, mailfrom: ard.biesheuvel@arm.com) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 9C48C1FB; Mon, 8 Jun 2020 10:34:23 -0700 (PDT) Received: from localhost.localdomain (unknown [10.37.8.184]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id B1EBF3F73D; Mon, 8 Jun 2020 10:34:21 -0700 (PDT) From: "Ard Biesheuvel" To: devel@edk2.groups.io Cc: Ard Biesheuvel , Bob Feng , Liming Gao , Laszlo Ersek , Leif Lindholm , Ilias Apalodimas , Julien Grall , Jiewen Yao Subject: [PATCH 0/4] ArmVirtPkg: use PE/COFF metadata for self relocation Date: Mon, 8 Jun 2020 19:34:09 +0200 Message-Id: <20200608173413.1100679-1-ard.biesheuvel@arm.com> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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 wel= l 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 resultin= g image adversely. [0] https://edk2.groups.io/g/devel/message/60835 Cc: Bob Feng Cc: Liming Gao Cc: Laszlo Ersek Cc: Leif Lindholm Cc: Ilias Apalodimas Cc: Julien Grall Cc: Jiewen Yao Ard Biesheuvel (4): ArmVirtPkg: add FDF rule for self-relocating PrePi BaseTools/Scripts/GccBase.lds: export image base symbol 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 | 21 +++++++++ ArmVirtPkg/ArmVirtRules.fdf.inc | 5 ++ ArmVirtPkg/PrePi/AArch64/ModuleEntryPoint.S | 49 +++++----------= ----- ArmVirtPkg/PrePi/Arm/ModuleEntryPoint.S | 47 +++++----------= ---- ArmVirtPkg/PrePi/Scripts/PrePi-PIE.lds | 41 ---------------= - BaseTools/Scripts/GccBase.lds | 2 + 12 files changed, 63 insertions(+), 152 deletions(-) delete mode 100644 ArmVirtPkg/Include/Platform/Hidden.h delete mode 100644 ArmVirtPkg/PrePi/Scripts/PrePi-PIE.lds --=20 2.26.2