From nobody Tue May 7 00:18:35 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+60892+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+60892+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1591637667; cv=none; d=zohomail.com; s=zohoarc; b=d+ThGZCRkR5OhYrp6fXgZrqoT2X1yAexfS+8NIr2CLKdX3aRErwlw2azdRkux4vyRrlE0VW3QeWoGY2FI+6QAMaffvLtM/jdqcRwvj+fdcglMG/hAzAGiOAP/6cJUdxXUh6faW6YPXoEqNCZ9o42vVa0l0Vk7qzo8hAC2UeWMSY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1591637667; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=UCEoT5Pbpr6VpaTp9BdNzCSYEDdbxYdpJxOHotgQiFw=; b=fsH3inL1RKOGQpZD90vjtuK+yfm+PPXTnFSK1aCGxxQfL9fd3dHChYC495jmxXbmrcpqcNPr+q/yUL0HjR2tFSAQc3jqBxR+npHzrGTFCDr4ZEVRVey6xJWSGXaYT4On7Oaqbc7U5ocz3KUVV+xQv3cbaaiARCd3/pq465q9ccs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+60892+1787277+3901457@groups.io Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1591637667388295.9059446126789; Mon, 8 Jun 2020 10:34:27 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id me8tYY1788612xgNHMQdTmOy; Mon, 08 Jun 2020 10:34:27 -0700 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web10.154.1591637666245193644 for ; Mon, 08 Jun 2020 10:34:26 -0700 X-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 D515C101E; Mon, 8 Jun 2020 10:34:25 -0700 (PDT) X-Received: from localhost.localdomain (unknown [10.37.8.184]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id EDC8F3F73D; Mon, 8 Jun 2020 10:34:23 -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: [edk2-devel] [PATCH 1/4] ArmVirtPkg: add FDF rule for self-relocating PrePi Date: Mon, 8 Jun 2020 19:34:10 +0200 Message-Id: <20200608173413.1100679-2-ard.biesheuvel@arm.com> In-Reply-To: <20200608173413.1100679-1-ard.biesheuvel@arm.com> References: <20200608173413.1100679-1-ard.biesheuvel@arm.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,ard.biesheuvel@arm.com X-Gm-Message-State: K5Ah0Td6XDLeMqYgrfaqiMLMx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1591637667; bh=srX/yXXVw7/8A+rpBxfEjVyia+7VvmSNeFxrHI7FRyk=; h=Cc:Date:From:Reply-To:Subject:To; b=cjr5QzIEIVK7MrB3bKchErUEhIJIr0CrmjB+a+3mLDloCye1lxdMFagfvZii6UFrswI 0DTPjvxjj6HJcCY3UJmu+mpIt04ozFTwD7TlrHzbppgmOe972sgQIffYkqL5tz7J9Qo04 YqcR+YHCCZ062T/zkW/fQ10EpI5OsRRufcQ= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" In preparation for making the self-relocating PrePi use the ordinary BasePeCoffLib routines for relocating the image in place in memory at start, add a special FDF rule that builds SEC modules as PE32 images with the relocation metadata preserved. Signed-off-by: Ard Biesheuvel Acked-by: Jiewen Yao Acked-by: Sami Mujawar Reviewed-by: Laszlo Ersek Tested-by: Julien Grall Tested-by: Sami Mujawar --- ArmVirtPkg/ArmVirtQemuKernel.fdf | 2 +- ArmVirtPkg/ArmVirtXen.fdf | 2 +- ArmVirtPkg/ArmVirtRules.fdf.inc | 5 +++++ 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/ArmVirtPkg/ArmVirtQemuKernel.fdf b/ArmVirtPkg/ArmVirtQemuKerne= l.fdf index 72fc8dd698f8..55e33aba0d55 100644 --- a/ArmVirtPkg/ArmVirtQemuKernel.fdf +++ b/ArmVirtPkg/ArmVirtQemuKernel.fdf @@ -136,7 +136,7 @@ [FV.FVMAIN_COMPACT] READ_LOCK_CAP =3D TRUE READ_LOCK_STATUS =3D TRUE =20 - INF ArmVirtPkg/PrePi/ArmVirtPrePiUniCoreRelocatable.inf + INF RuleOverride =3D SELF_RELOC ArmVirtPkg/PrePi/ArmVirtPrePiUniCoreRelo= catable.inf =20 FILE FV_IMAGE =3D 9E21FD93-9C72-4c15-8C4B-E77F1DB2D792 { SECTION GUIDED EE4E5898-3914-4259-9D6E-DC7BD79403CF PROCESSING_REQUIRE= D =3D TRUE { diff --git a/ArmVirtPkg/ArmVirtXen.fdf b/ArmVirtPkg/ArmVirtXen.fdf index 6a97bceeacbc..f708878f4965 100644 --- a/ArmVirtPkg/ArmVirtXen.fdf +++ b/ArmVirtPkg/ArmVirtXen.fdf @@ -233,7 +233,7 @@ [FV.FVMAIN_COMPACT] READ_LOCK_CAP =3D TRUE READ_LOCK_STATUS =3D TRUE =20 - INF ArmVirtPkg/PrePi/ArmVirtPrePiUniCoreRelocatable.inf + INF RuleOverride =3D SELF_RELOC ArmVirtPkg/PrePi/ArmVirtPrePiUniCoreRelo= catable.inf =20 FILE FV_IMAGE =3D 9E21FD93-9C72-4c15-8C4B-E77F1DB2D792 { SECTION GUIDED EE4E5898-3914-4259-9D6E-DC7BD79403CF PROCESSING_REQUIRE= D =3D TRUE { diff --git a/ArmVirtPkg/ArmVirtRules.fdf.inc b/ArmVirtPkg/ArmVirtRules.fdf.= inc index 63de26abe056..8496767c718e 100644 --- a/ArmVirtPkg/ArmVirtRules.fdf.inc +++ b/ArmVirtPkg/ArmVirtRules.fdf.inc @@ -39,6 +39,11 @@ [Rule.Common.SEC] TE TE Align =3D Auto $(INF_OUTPUT)/$(MODULE_NAME).efi } =20 +[Rule.Common.SEC.SELF_RELOC] + FILE SEC =3D $(NAMED_GUID) { + PE32 PE32 Align =3D Auto $(INF_OUTPUT)/$(MODULE_NAME).efi + } + [Rule.Common.PEI_CORE] FILE PEI_CORE =3D $(NAMED_GUID) FIXED { TE TE Align =3D Auto $(INF_OUTPUT)/$(MODULE_NAME).efi --=20 2.26.2 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#60892): https://edk2.groups.io/g/devel/message/60892 Mute This Topic: https://groups.io/mt/74757208/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Tue May 7 00:18:35 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+60893+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+60893+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1591637669; cv=none; d=zohomail.com; s=zohoarc; b=ke0r3YgR8aw/7lLKt1SK8LkrKXwejv5FwUMyGe/0rvXdDGq0nGA+lwZlhgh1fwWD1IwFETF9TkHpnF5girMKszWXRtd2mUEfPlcipngWedPeW0f19km1THofrm7iTd26N6szZSO72zQWcC7iiRwJ45XR+Nev06OXb9bOgcF3BRg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1591637669; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=deSxfnz0+DvK2QlOWurzZjKRqpf6SatWk/SvRE70G4w=; b=UtelERLyIQPpLp4WdreBguaywep8QoHf3QKWwf5oscBOgmf1gTxocqgN8Ac1468agtZ0ZfX/IX5ipDLmJs3tKcM+uSLDi0MTi7wBEMxjy4kdHHG7ynevSIyl4UqVbfJKInMWfyD+2BaZZeBad12Hhl55bKmEYsSB5E42lopEgTw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+60893+1787277+3901457@groups.io Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1591637669242580.4695504868286; Mon, 8 Jun 2020 10:34:29 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id VxHJYY1788612x1TvueZh3wF; Mon, 08 Jun 2020 10:34:28 -0700 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web11.145.1591637668433236023 for ; Mon, 08 Jun 2020 10:34:28 -0700 X-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 1C8021FB; Mon, 8 Jun 2020 10:34:28 -0700 (PDT) X-Received: from localhost.localdomain (unknown [10.37.8.184]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 33B093F73D; Mon, 8 Jun 2020 10:34:26 -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: [edk2-devel] [PATCH 2/4] BaseTools/Scripts/GccBase.lds: export image base symbol Date: Mon, 8 Jun 2020 19:34:11 +0200 Message-Id: <20200608173413.1100679-3-ard.biesheuvel@arm.com> In-Reply-To: <20200608173413.1100679-1-ard.biesheuvel@arm.com> References: <20200608173413.1100679-1-ard.biesheuvel@arm.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,ard.biesheuvel@arm.com X-Gm-Message-State: QfewgbG1NCKbSjcZBkewCUIbx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1591637668; bh=7g1l4JJrWLqWHtZbx+xdCvnHJu4EjtACuWUgLTIZcB8=; h=Cc:Date:From:Reply-To:Subject:To; b=WzlqS1r+v1CORa2zuLFJKlP13sRJj767HtwVJbGJa6uUHMofzwKWrdL4GwR3odJ3rXZ 8Qx6XZcTIzvCLIoyySwFwWRVIAeVRlpNvgSe1Seoblh17zD7sHeRR5gs+Zpr3/KbjITlU mxTwpGY7NHrmxvFA97TlFC0T/zp5ZRZ15DQ= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" To help converted ELF images perform self-relocation, export a symbol 'ElfImageBase' that can be used in the code to discover the start of the image in memory. Note the use of PROVIDE() - this ensures that the symbol is only emitted if a reference to it exists in the code being linked, but no definition. This means the symbol is never emitted in a way that can conflict with existing code. Signed-off-by: Ard Biesheuvel Acked-by: Jiewen Yao Acked-by: Sami Mujawar Reviewed-by: Bob Feng Tested-by: Julien Grall Tested-by: Sami Mujawar --- BaseTools/Scripts/GccBase.lds | 2 ++ 1 file changed, 2 insertions(+) diff --git a/BaseTools/Scripts/GccBase.lds b/BaseTools/Scripts/GccBase.lds index a9dd2138d4b5..e73c1206a2e2 100644 --- a/BaseTools/Scripts/GccBase.lds +++ b/BaseTools/Scripts/GccBase.lds @@ -12,6 +12,8 @@ =20 SECTIONS { =20 + PROVIDE(ElfImageBase =3D .); + /* * The PE/COFF binary consists of DOS and PE/COFF headers, and a sequenc= e of * section headers adding up to PECOFF_HEADER_SIZE bytes (which differs --=20 2.26.2 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#60893): https://edk2.groups.io/g/devel/message/60893 Mute This Topic: https://groups.io/mt/74757210/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Tue May 7 00:18:35 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+60894+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+60894+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1591637671; cv=none; d=zohomail.com; s=zohoarc; b=hRLWoT4UGKT54tBZQppaH88KWOVw9a5Z1JNX16HBsZSDLTE+lWPo4rNB0EAnETQENcq0oCT31LvF+fiQzKDbQdlzhCaPm7J6b0PhPh1tJcX+CjF1J7Q6scfkE9lYvl1xzETal03ZwUMG9nw3o6ZVV+MHPTCLB7Npznx+QiAOwpA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1591637671; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=dsU2/dDCM3CBGxmHEOEi1wn3AkFLVjM7zJAtCX0IVp4=; b=L0AfkoTSYBkL6lz6qZmgJQoWERrwODCCbt2fDzNcimstFxFGtwcq/PKTsEDq8PsMMx9gGoFMvvM5nxixwZskTvBaI77PWivOJ29jwlzwl00DDjzwb0Qf28Sm2zIq+GJQ5OssMuikg8qEpamjB/jnxwFKTJuY5H8UujuVwZ697ug= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+60894+1787277+3901457@groups.io Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1591637671775226.8538078900193; Mon, 8 Jun 2020 10:34:31 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id CJNAYY1788612xqssNjF57Kh; Mon, 08 Jun 2020 10:34:31 -0700 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web12.161.1591637670639967750 for ; Mon, 08 Jun 2020 10:34:30 -0700 X-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 5FBD81042; Mon, 8 Jun 2020 10:34:30 -0700 (PDT) X-Received: from localhost.localdomain (unknown [10.37.8.184]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 6F1DD3F73D; Mon, 8 Jun 2020 10:34:28 -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: [edk2-devel] [PATCH 3/4] ArmVirtPkg/PrePi: use standard PeCoff routines for self-relocation Date: Mon, 8 Jun 2020 19:34:12 +0200 Message-Id: <20200608173413.1100679-4-ard.biesheuvel@arm.com> In-Reply-To: <20200608173413.1100679-1-ard.biesheuvel@arm.com> References: <20200608173413.1100679-1-ard.biesheuvel@arm.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,ard.biesheuvel@arm.com X-Gm-Message-State: Nacgh7Fh6NF6mIPaU5ugVHqpx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1591637671; bh=87Ci+kQ2ibeHMPgSc7M9FzdjyY5NEBtKcHQy7Ihx3Sc=; h=Cc:Date:From:Reply-To:Subject:To; b=UqMQFHM282utbWS8SSnCh6M+woPwkx/abZkbCAM1qCYHUZzqP95TIYc0ERxYjgJepuE OV7Wvw+ewAplou1GzgMejlnYSM1Pzj1pRZz2NDBJjUjxzyq/YX9C9q2faUGbO/sMng9Qt QbQ1AYQZCM0e8EQON1Hk+vOnR3pNjmEqrnM= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" Instead of having a GCC specific routine to perform self-relocation based on ELF metadata, use the PE/COFF metadata and the existing PeCoff library routines. This reduces the amount of bespoke assembler code that is a burden to maintain, and is not portable across the set of toolchains we support. This does require some special care, as we have no control over how the C code references global symbols, so we need to emit these references from the calling assembler code. Otherwise, they may be emitted as absolute references, in which case they need to be fixed up themselves, leading to a circular dependency. Signed-off-by: Ard Biesheuvel Acked-by: Jiewen Yao Acked-by: Laszlo Ersek Acked-by: Sami Mujawar Tested-by: Julien Grall Tested-by: Sami Mujawar --- ArmVirtPkg/ArmVirtQemuKernel.dsc | 10 ++-- ArmVirtPkg/ArmVirtXen.dsc | 10 ++-- ArmVirtPkg/PrePi/ArmVirtPrePiUniCoreRelocatable.inf | 4 +- ArmVirtPkg/PrePi/PrePi.c | 21 +++++++++ ArmVirtPkg/PrePi/AArch64/ModuleEntryPoint.S | 49 +++++------------= --- ArmVirtPkg/PrePi/Arm/ModuleEntryPoint.S | 47 +++++------------= -- 6 files changed, 54 insertions(+), 87 deletions(-) diff --git a/ArmVirtPkg/ArmVirtQemuKernel.dsc b/ArmVirtPkg/ArmVirtQemuKerne= l.dsc index 2a6fd6bc06be..9449a01d6e40 100644 --- a/ArmVirtPkg/ArmVirtQemuKernel.dsc +++ b/ArmVirtPkg/ArmVirtQemuKernel.dsc @@ -83,14 +83,12 @@ [LibraryClasses.common.DXE_DRIVER] [LibraryClasses.common.UEFI_DRIVER] UefiScsiLib|MdePkg/Library/UefiScsiLib/UefiScsiLib.inf =20 -[BuildOptions.common.EDKII.SEC, BuildOptions.common.EDKII.BASE] +[BuildOptions] # - # CLANG38 with LTO support enabled uses the GNU GOLD linker, which insis= ts - # on emitting GOT based symbol references when running in shared mode, u= nless - # we override visibility to 'hidden' in all modules that make up the Pre= Pi - # build. + # We need to avoid jump tables in SEC modules, so that the PE/COFF + # self-relocation code itself is guaranteed to be position independent. # - GCC:*_CLANG38_*_CC_FLAGS =3D -include $(WORKSPACE)/ArmVirtPkg/Include/Pl= atform/Hidden.h + GCC:*_*_*_CC_FLAGS =3D -fno-jump-tables =20 ##########################################################################= ###### # diff --git a/ArmVirtPkg/ArmVirtXen.dsc b/ArmVirtPkg/ArmVirtXen.dsc index 8a489b253684..278f5d3828ce 100644 --- a/ArmVirtPkg/ArmVirtXen.dsc +++ b/ArmVirtPkg/ArmVirtXen.dsc @@ -52,14 +52,12 @@ [LibraryClasses] [LibraryClasses.common.UEFI_DRIVER] UefiScsiLib|MdePkg/Library/UefiScsiLib/UefiScsiLib.inf =20 -[BuildOptions.common.EDKII.SEC, BuildOptions.common.EDKII.BASE] +[BuildOptions] # - # CLANG38 with LTO support enabled uses the GNU GOLD linker, which insis= ts - # on emitting GOT based symbol references when running in shared mode, u= nless - # we override visibility to 'hidden' in all modules that make up the Pre= Pi - # build. + # We need to avoid jump tables in SEC modules, so that the PE/COFF + # self-relocation code itself is guaranteed to be position independent. # - GCC:*_CLANG38_*_CC_FLAGS =3D -include $(WORKSPACE)/ArmVirtPkg/Include/Pl= atform/Hidden.h + GCC:*_*_*_CC_FLAGS =3D -fno-jump-tables =20 ##########################################################################= ###### # diff --git a/ArmVirtPkg/PrePi/ArmVirtPrePiUniCoreRelocatable.inf b/ArmVirtP= kg/PrePi/ArmVirtPrePiUniCoreRelocatable.inf index 9e58e56fce09..7edf5018089d 100755 --- a/ArmVirtPkg/PrePi/ArmVirtPrePiUniCoreRelocatable.inf +++ b/ArmVirtPkg/PrePi/ArmVirtPrePiUniCoreRelocatable.inf @@ -46,6 +46,7 @@ [LibraryClasses] SerialPortLib ExtractGuidedSectionLib LzmaDecompressLib + PeCoffLib PrePiLib MemoryAllocationLib HobLib @@ -95,6 +96,3 @@ [Pcd] gArmVirtTokenSpaceGuid.PcdDeviceTreeInitialBaseAddress gArmTokenSpaceGuid.PcdFdBaseAddress gArmTokenSpaceGuid.PcdFvBaseAddress - -[BuildOptions] - GCC:*_*_*_DLINK_FLAGS =3D -Wl,-Bsymbolic,-pie,-T,$(MODULE_DIR)/Scripts/P= rePi-PIE.lds diff --git a/ArmVirtPkg/PrePi/PrePi.c b/ArmVirtPkg/PrePi/PrePi.c index 72e35028c5bb..0cb064419759 100755 --- a/ArmVirtPkg/PrePi/PrePi.c +++ b/ArmVirtPkg/PrePi/PrePi.c @@ -9,6 +9,7 @@ #include #include =20 +#include #include #include #include @@ -128,3 +129,23 @@ CEntryPoint ( // DXE Core should always load and never return ASSERT (FALSE); } + +VOID +RelocatePeCoffImage ( + IN UINTN ImageBase, + IN PE_COFF_LOADER_READ_FILE ImageRead + ) +{ + PE_COFF_LOADER_IMAGE_CONTEXT ImageContext; + + ZeroMem (&ImageContext, sizeof ImageContext); + + ImageContext.Handle =3D (EFI_HANDLE)ImageBase; + ImageContext.ImageRead =3D ImageRead; + PeCoffLoaderGetImageInfo (&ImageContext); + + if (ImageContext.ImageAddress !=3D ImageBase) { + ImageContext.ImageAddress =3D ImageBase; + PeCoffLoaderRelocateImage (&ImageContext); + } +} diff --git a/ArmVirtPkg/PrePi/AArch64/ModuleEntryPoint.S b/ArmVirtPkg/PrePi= /AArch64/ModuleEntryPoint.S index 34d6abecb0ac..7c5592b11a46 100644 --- a/ArmVirtPkg/PrePi/AArch64/ModuleEntryPoint.S +++ b/ArmVirtPkg/PrePi/AArch64/ModuleEntryPoint.S @@ -9,40 +9,6 @@ #include =20 ASM_FUNC(_ModuleEntryPoint) - // - // We are built as a ET_DYN PIE executable, so we need to process all - // relative relocations regardless of whether or not we are executing fr= om - // the same offset we were linked at. This is only possible if we are - // running from RAM. - // - adr x8, __reloc_base - adr x9, __reloc_start - adr x10, __reloc_end - -.Lreloc_loop: - cmp x9, x10 - bhs .Lreloc_done - - // - // AArch64 uses the ELF64 RELA format, which means each entry in the - // relocation table consists of - // - // UINT64 offset : the relative offset of the value that need= s to - // be relocated - // UINT64 info : relocation type and symbol index (the latt= er is - // not used for R_AARCH64_RELATIVE relocation= s) - // UINT64 addend : value to be added to the value being reloc= ated - // - ldp x11, x12, [x9], #24 // read offset into x11 and info into x12 - cmp x12, #0x403 // check info =3D=3D R_AARCH64_RELATIVE? - bne .Lreloc_loop // not a relative relocation? then skip - - ldr x12, [x9, #-8] // read addend into x12 - add x12, x12, x8 // add reloc base to addend to get relocated= value - str x12, [x11, x8] // write relocated value at offset - b .Lreloc_loop -.Lreloc_done: - bl ASM_PFX(DiscoverDramFromDt) =20 // Get ID of this CPU in Multicore system @@ -170,15 +136,24 @@ ASM_PFX(DiscoverDramFromDt): str x1, [x8] str x7, [x9] =20 + // + // The runtime address may be different from the link time address so fix + // up the PE/COFF relocations. Since we are calling a C function, use the + // window at the beginning of the FD image as a temp stack. + // + adr x0, ElfImageBase + adr x1, PeCoffLoaderImageReadFromMemory + mov sp, x7 + bl RelocatePeCoffImage + // // Discover the memory size and offset from the DTB, and record in the // respective PCDs. This will also return false if a corrupt DTB is - // encountered. Since we are calling a C function, use the window at the - // beginning of the FD image as a temp stack. + // encountered. // + mov x0, x28 adr x1, PcdGet64 (PcdSystemMemoryBase) adr x2, PcdGet64 (PcdSystemMemorySize) - mov sp, x7 bl FindMemnode cbz x0, .Lout =20 diff --git a/ArmVirtPkg/PrePi/Arm/ModuleEntryPoint.S b/ArmVirtPkg/PrePi/Arm= /ModuleEntryPoint.S index 72d756fdb571..bf39de86e7d0 100644 --- a/ArmVirtPkg/PrePi/Arm/ModuleEntryPoint.S +++ b/ArmVirtPkg/PrePi/Arm/ModuleEntryPoint.S @@ -9,38 +9,6 @@ #include =20 ASM_FUNC(_ModuleEntryPoint) - // - // We are built as a ET_DYN PIE executable, so we need to process all - // relative relocations if we are executing from a different offset than= we - // were linked at. This is only possible if we are running from RAM. - // - ADRL (r4, __reloc_base) - ADRL (r5, __reloc_start) - ADRL (r6, __reloc_end) - -.Lreloc_loop: - cmp r5, r6 - bhs .Lreloc_done - - // - // AArch32 uses the ELF32 REL format, which means each entry in the - // relocation table consists of - // - // UINT32 offset : the relative offset of the value that need= s to - // be relocated - // UINT32 info : relocation type and symbol index (the latt= er is - // not used for R_ARM_RELATIVE relocations) - // - ldrd r8, r9, [r5], #8 // read offset into r8 and info into r9 - cmp r9, #23 // check info =3D=3D R_ARM_RELATIVE? - bne .Lreloc_loop // not a relative relocation? then skip - - ldr r9, [r8, r4] // read addend into r9 - add r9, r9, r1 // add image base to addend to get relocated= value - str r9, [r8, r4] // write relocated value at offset - b .Lreloc_loop -.Lreloc_done: - // Do early platform specific actions bl ASM_PFX(ArmPlatformPeiBootAction) =20 @@ -172,15 +140,24 @@ ASM_PFX(ArmPlatformPeiBootAction): str r1, [r8] str r5, [r7] =20 + // + // The runtime address may be different from the link time address so fix + // up the PE/COFF relocations. Since we are calling a C function, use the + // window at the beginning of the FD image as a temp stack. + // + ADRL (r0, ElfImageBase) + ADRL (r1, PeCoffLoaderImageReadFromMemory) + mov sp, r5 + bl RelocatePeCoffImage + // // Discover the memory size and offset from the DTB, and record in the // respective PCDs. This will also return false if a corrupt DTB is - // encountered. Since we are calling a C function, use the window at the - // beginning of the FD image as a temp stack. + // encountered. // + mov r0, r10 ADRL (r1, PcdGet64 (PcdSystemMemoryBase)) ADRL (r2, PcdGet64 (PcdSystemMemorySize)) - mov sp, r5 bl FindMemnode teq r0, #0 beq .Lout --=20 2.26.2 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#60894): https://edk2.groups.io/g/devel/message/60894 Mute This Topic: https://groups.io/mt/74757213/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Tue May 7 00:18:35 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+60895+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+60895+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1591637673; cv=none; d=zohomail.com; s=zohoarc; b=RBQg9Zw+cfg7RNDm2wm++fJvEmA9b/dgJmO/43y6cn46/SUyPISLnFbgFv/9Qj0hxDPVr3X5ImOM5NvF2WTnj2Ipp5I6LYiv8gXf/W2to7DusHCJ6+S4XtvM7RL1aEJRzKKp7QT4fDtAd684Yggdq6RsmBUT2IvYyXNlttQKrDI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1591637673; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=PmdEEK/n4QDijVc39Aq0UmO3hNtUXiApuX08BWEjQwk=; b=FSCL632tApuDEqJMg0jlL57O/ERaUn19XbuS79ZOtLWUvrOBcJV4j+wZkoNuLGaa5EX5uG3yQrILhWJ5bSMACVsk8DHf+RAY8V+SW964ZoS+tfu6i9nKMAXubvIBHJJDRPuSUQiGCO4bDtMbedjkuROLOKRgDJxgo9JXSf0ps+Q= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+60895+1787277+3901457@groups.io Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1591637673793699.8840755285345; Mon, 8 Jun 2020 10:34:33 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id xEzuYY1788612xz6MW1E4D8G; Mon, 08 Jun 2020 10:34:33 -0700 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web11.148.1591637672938329769 for ; Mon, 08 Jun 2020 10:34:33 -0700 X-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 9B7101FB; Mon, 8 Jun 2020 10:34:32 -0700 (PDT) X-Received: from localhost.localdomain (unknown [10.37.8.184]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id B22BB3F73D; Mon, 8 Jun 2020 10:34:30 -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: [edk2-devel] [PATCH 4/4] ArmVirtPkg: remove unused files Date: Mon, 8 Jun 2020 19:34:13 +0200 Message-Id: <20200608173413.1100679-5-ard.biesheuvel@arm.com> In-Reply-To: <20200608173413.1100679-1-ard.biesheuvel@arm.com> References: <20200608173413.1100679-1-ard.biesheuvel@arm.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,ard.biesheuvel@arm.com X-Gm-Message-State: i78fJ2CssM41gdjSbjqBxGrex1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1591637673; bh=f1VZWa7DXtBcFnGFSpHcN1Ob9dEPDYAJGBgf02d8SFk=; h=Cc:Date:From:Reply-To:Subject:To; b=KMuX6Mz00P45T7oMpLl7oR3xaNdsiTRlAGn0IZOdmsHzQ0QGu6lzbwhpFfty5tEDxnv aY5S71ftEMC451h79VnpC5o5PTK1amLXFPbCBFOXGFha8F15laI4nhJsvKL1LhWT+ry2N KZBRBsDWWdggX5SyPC7G6JC1iqd/JgTPoKg= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" We no longer use ELF PIE executables to implement the self-relocating PrePi so drop the custom linker script and visibility override header file. Signed-off-by: Ard Biesheuvel Acked-by: Jiewen Yao Acked-by: Sami Mujawar Reviewed-by: Laszlo Ersek Tested-by: Julien Grall Tested-by: Sami Mujawar --- ArmVirtPkg/Include/Platform/Hidden.h | 22 ----------- ArmVirtPkg/PrePi/Scripts/PrePi-PIE.lds | 41 -------------------- 2 files changed, 63 deletions(-) diff --git a/ArmVirtPkg/Include/Platform/Hidden.h b/ArmVirtPkg/Include/Plat= form/Hidden.h deleted file mode 100644 index 7a7bdb42b8bd..000000000000 --- a/ArmVirtPkg/Include/Platform/Hidden.h +++ /dev/null @@ -1,22 +0,0 @@ -/** @file - - Copyright (c) 2018, Linaro Limited. All rights reserved. - - SPDX-License-Identifier: BSD-2-Clause-Patent - -**/ - -#ifndef __PLATFORM_HIDDEN_H -#define __PLATFORM_HIDDEN_H - -// -// Setting the GCC -fvisibility=3Dhidden command line option is not quite = the same -// as setting the pragma below: the former only affects definitions, where= as the -// pragma affects extern declarations as well. So if we want to ensure tha= t no -// GOT indirected symbol references are emitted, we need to use the pragma= , or -// GOT based cross object references could be emitted, e.g., in libraries,= and -// these cannot be relaxed to ordinary symbol references at link time. -// -#pragma GCC visibility push (hidden) - -#endif diff --git a/ArmVirtPkg/PrePi/Scripts/PrePi-PIE.lds b/ArmVirtPkg/PrePi/Scri= pts/PrePi-PIE.lds deleted file mode 100644 index c9a15ca3493a..000000000000 --- a/ArmVirtPkg/PrePi/Scripts/PrePi-PIE.lds +++ /dev/null @@ -1,41 +0,0 @@ -/** @file - - Copyright (c) 2015, Linaro Ltd. All rights reserved.
- - SPDX-License-Identifier: BSD-2-Clause-Patent - -**/ - -SECTIONS -{ - PROVIDE(__reloc_base =3D .); - - . =3D PECOFF_HEADER_SIZE; - .text : ALIGN(CONSTANT(COMMONPAGESIZE)) { - *(.text .text*) - *(.got .got*) - *(.rodata .rodata*) - *(.data .data*) - *(.bss .bss*) - - . =3D ALIGN(0x20); - PROVIDE(__reloc_start =3D .); - *(.rel .rel.*) - *(.rela .rela.*) - PROVIDE(__reloc_end =3D .); - } - - .note (INFO) : { *(.note.gnu.build-id) } - - /DISCARD/ : { - *(.note.GNU-stack) - *(.gnu.hash) - *(.gnu_debuglink) - *(.interp) - *(.dynamic) - *(.dynsym) - *(.dynstr) - *(.hash) - *(.comment) - } -} --=20 2.26.2 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#60895): https://edk2.groups.io/g/devel/message/60895 Mute This Topic: https://groups.io/mt/74757214/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-