From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by mx.groups.io with SMTP id smtpd.web11.50282.1680254094977224397 for ; Fri, 31 Mar 2023 02:14:55 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=c0M+bzgX; spf=pass (domain: kernel.org, ip: 145.40.68.75, 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 ams.source.kernel.org (Postfix) with ESMTPS id 5DDF4B82D7E; Fri, 31 Mar 2023 09:14:52 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4D453C433EF; Fri, 31 Mar 2023 09:14:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1680254091; bh=+aBPP+nNMWTLmuynoDgRqjcpeljLntByQqVGJY0NMUE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=c0M+bzgXGMlatEFOZZxCysgY9bBO7XcDg5rbehWKrnNpLWBSv7NcamxKTj+lRwq3j Q1fSt2CMEo6ZGJ9BLWJZkcjsy8gbX+19Jz16Dn+xeMcTWA8tuHUs1FaqwSpIvNCony sy2kmYWCXAl8j90pn9OWpFQYZapD2zza4xbsnydOa1kmg+aM8PXKZN9hvdm0R1e8fy cnn4mVvoseaDpjrifaWkiEMv0GgZe40jBfIgcIoD0dNO2ke6+o97tWFBqsy3CAqUOF /yaW5aqWCtBYVCXJ/nKBR13r43SQ0WTRV90KDpRPNI+ad5XSQhocuDaiE/hU0yUOHG pDCvrsKdlcB6Q== 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: [RFT PATCH v3 1/5] BaseTools/tools_def CLANGDWARF: Permit text relocations Date: Fri, 31 Mar 2023 11:14:33 +0200 Message-Id: <20230331091437.1593337-2-ardb@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230331091437.1593337-1-ardb@kernel.org> References: <20230331091437.1593337-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