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.39162.1680211280116326233 for ; Thu, 30 Mar 2023 14:21:20 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=T9YbhOQO; 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 AD9B2621A8; Thu, 30 Mar 2023 21:21:19 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4E474C4339B; Thu, 30 Mar 2023 21:21:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1680211279; bh=CboUk1fGg3dKt4ztrwo+MpEGagsHtzBmwoFYTuokVdw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=T9YbhOQO+MnGDg6ERby8frcwEhsgIipyaunfuYN9cf1Kc6z4r6I5tqyMCtL22li4v RAomTteOBKX5DYx6SEcqvqIR71bUgisoo9WSGIO+tps0PsDxEsQgnmBiwPDeBHBcxo JJjay5KNrZgeDjlCFsMvIvxNS5fJTB8DXmZmVxUAmeyYise9dwnmw3WCZOo6LBP0L7 d9L0g/o5vFzcovYyw+5xPzl7l6IM3UlQAOQCksy0zq7RyIoRMRfMdbvkRQQGVnqJx7 nMYkG++T1XA0kaYytQHjOPplR8gvQ4bLnAmpsjl0k81AGwg5gKqoYEYDBOm1o2X3EF i7v7qSjbb+mKg== From: "Ard Biesheuvel" To: devel@edk2.groups.io Cc: Ard Biesheuvel , Ni, Ray , Andrew Fish , "Kinney, Michael D" , "Liu, Zhiguang" , Rebecca Cran , Tom Lendacky Subject: [RFT PATCH v2 2/6] BaseTools/tools_def CLANGDWARF: Permit text relocations Date: Thu, 30 Mar 2023 23:20:57 +0200 Message-Id: <20230330212101.1566931-3-ardb@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230330212101.1566931-1-ardb@kernel.org> References: <20230330212101.1566931-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 1855f1038b1571e4..0c6fc4a3011c8d5c 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