From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by mx.groups.io with SMTP id smtpd.web11.72008.1680532173250362636 for ; Mon, 03 Apr 2023 07:29:33 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=KNW8cEL0; spf=pass (domain: kernel.org, ip: 139.178.84.217, mailfrom: ardb@kernel.org) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id C9A9961DEA; Mon, 3 Apr 2023 14:29:32 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5AA80C4339B; Mon, 3 Apr 2023 14:29:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1680532172; bh=+aBPP+nNMWTLmuynoDgRqjcpeljLntByQqVGJY0NMUE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KNW8cEL0Lcfl6XJkPVJZgoGyOrBhtzjCjoEIS9yyX3IUNQpgRM/Je8ouGcFnlYV4n LHtbrNpHXhZB0+2HBlZ2rLrucbx15UuS7ppZEBywV7jUzfOx+YGy5bDtGGEV1HgvD9 b90y5g0cqLvnxcQGdXrnvPuK1E/MwWrxHLyO5qp8UrQYigt2NfYKEYCAfoW0i1M8oo 2CwKz7vHn0m7Cfmxbb3XXnslmghTphpTwAZzijhCthHhqYZvAGecyQZPfTx4b1UdvR vsOPi/arMI+R41HG8EniHbxUSwnssRnBRNU+ATcpmifui7fUtYXo7XvhafAXkGIXlz xKlGlwAncN1Aw== From: "Ard Biesheuvel" To: devel@edk2.groups.io Cc: Ard Biesheuvel , "Ni, Ray" , Andrew Fish , "Kinney, Michael D" , "Liu, Zhiguang" , Rebecca Cran , Tom Lendacky , =?UTF-8?q?Marvin=20H=C3=A4user?= Subject: [PATCH v4 1/6] BaseTools/tools_def CLANGDWARF: Permit text relocations Date: Mon, 3 Apr 2023 16:29:15 +0200 Message-Id: <20230403142920.1921619-2-ardb@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230403142920.1921619-1-ardb@kernel.org> References: <20230403142920.1921619-1-ardb@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable We rely on PIE executables to get the codegen that is suitable for PE/COFF conversion where the resulting executables can be loaded anywhere in the address space. However, ELF linkers may default to disallowing text relocations in PIE executables, as this would require text segments to be updated at runtime, which is bad for security and increases the copy-on-write footprint of ELF executables and shared libraries. However, none of those concerns apply to PE/COFF executables in the context of EFI, which are copied into memory rather than mmap()'ed, and fixed up by the loader before launch. So pass -z notext to the LLD linker to permit runtime relocations in read-only sections. Signed-off-by: Ard Biesheuvel --- BaseTools/Conf/tools_def.template | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BaseTools/Conf/tools_def.template b/BaseTools/Conf/tools_def.t= emplate index ae43101853870c6d..5a3af55bfb09d753 100755 --- a/BaseTools/Conf/tools_def.template +++ b/BaseTools/Conf/tools_def.template @@ -2870,7 +2870,7 @@ DEFINE CLANGDWARF_X64_PREFIX =3D ENV(CLANG_BIN) DEFINE CLANGDWARF_IA32_X64_DLINK_COMMON =3D -nostdlib -Wl,-q,--gc-sectio= ns -z max-page-size=3D0x40=0D DEFINE CLANGDWARF_DLINK2_FLAGS_COMMON =3D -Wl,--script=3D$(EDK_TOOLS_P= ATH)/Scripts/ClangBase.lds=0D DEFINE CLANGDWARF_IA32_X64_ASLDLINK_FLAGS =3D DEF(CLANGDWARF_IA32_X64_DLIN= K_COMMON) -Wl,--defsym=3DPECOFF_HEADER_SIZE=3D0 DEF(CLANGDWARF_DLINK2_FLAGS= _COMMON) -Wl,--entry,ReferenceAcpiTable -u ReferenceAcpiTable=0D -DEFINE CLANGDWARF_IA32_X64_DLINK_FLAGS =3D DEF(CLANGDWARF_IA32_X64_DLIN= K_COMMON) -Wl,--entry,$(IMAGE_ENTRY_POINT) -u $(IMAGE_ENTRY_POINT) -Wl,-Map= ,$(DEST_DIR_DEBUG)/$(BASE_NAME).map,--whole-archive=0D +DEFINE CLANGDWARF_IA32_X64_DLINK_FLAGS =3D DEF(CLANGDWARF_IA32_X64_DLIN= K_COMMON) -Wl,--entry,$(IMAGE_ENTRY_POINT) -u $(IMAGE_ENTRY_POINT) -Wl,-Map= ,$(DEST_DIR_DEBUG)/$(BASE_NAME).map,--whole-archive -Wl,-z,notext=0D DEFINE CLANGDWARF_IA32_DLINK2_FLAGS =3D -Wl,--defsym=3DPECOFF_HEADER= _SIZE=3D0x220 DEF(CLANGDWARF_DLINK2_FLAGS_COMMON)=0D DEFINE CLANGDWARF_X64_DLINK2_FLAGS =3D -Wl,--defsym=3DPECOFF_HEADER= _SIZE=3D0x228 DEF(CLANGDWARF_DLINK2_FLAGS_COMMON)=0D =0D --=20 2.39.2