From nobody Mon Feb 9 23:39:23 2026 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+61039+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+61039+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1591777072; cv=none; d=zohomail.com; s=zohoarc; b=d+fud/YXs9o3qSGqmlKu70G8JR6Z3lwlLrQOiUN1aUPrSNgBtsAf8xRvTzmripHd8jrsRCHrYQjtGe7fk/ucjxKY29t02HpdglkuN4u+QXJWlYtINXyeX0rqltme0aVyL0+wsdokKTWy3O1mghACkovfyVCodfAl+t9TfgAk7O8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1591777072; 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=IsAwvLEEZMfSrlCe8SPtz/TsAezC61lNbyGj0ykxx2E=; b=mHsIGPGfejrYWNalxA+S0b5/Wnx+wJV7/OXYuOoaVw9Un9nnoZ/mAYdLLrDdnNnx+M8XLtr+/uhcmUBXG2c2fkMsua6TqUcprhrgaLS+dsA+ubHEGb+7Xkm7RgVqkbpk1x9PnLXwNUrRdJOkCX4Q2l4YMCNHYsVYSYZEdMZof6k= 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+61039+1787277+3901457@groups.io Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1591777072849791.5123334988925; Wed, 10 Jun 2020 01:17:52 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id aOqxYY1788612xYKce9cIGie; Wed, 10 Jun 2020 01:17:52 -0700 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web10.6037.1591777071280815162 for ; Wed, 10 Jun 2020 01:17:51 -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 D195C31B; Wed, 10 Jun 2020 01:17:50 -0700 (PDT) X-Received: from localhost.localdomain (unknown [10.37.8.184]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 3F5A73F6CF; Wed, 10 Jun 2020 01:17:49 -0700 (PDT) From: "Ard Biesheuvel" To: devel@edk2.groups.io Cc: Ard Biesheuvel , Michael D Kinney , Liming Gao , Jiewen Yao , Sami Mujawar , Ilias Apalodimas Subject: [edk2-devel] [PATCH 1/5] MdePkg/BasePrintLib: avoid absolute addresses for error strings Date: Wed, 10 Jun 2020 10:17:36 +0200 Message-Id: <20200610081740.54581-2-ard.biesheuvel@arm.com> In-Reply-To: <20200610081740.54581-1-ard.biesheuvel@arm.com> References: <20200610081740.54581-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: yLGadosLfQpPdmFJXpCPJAEex1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1591777072; bh=XlOdwPesJKBlMfp7NyfR2baHxDsPoR5yH5EMyw9lWfI=; h=Cc:Date:From:Reply-To:Subject:To; b=xZ5fAEQFKdfGaT8Paqb8lEECAlTsA5qsdLQOrtliThRzFpk/l1b8v3J8oMd07G9mATT 3VNytCtfmplHUbKN3e4K7hnErXP3vkd9r3gOcwPyXrxJVZ4tvzROZBRNXFZNIj6BKJ7+S QwDGdfDk3cj8/RyTlhEz2AXb52HUqfWLkiY= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" The mStatusString[] is constructed as an array of pointer-to-char, which means that on X64 or AARCH64, it is emitted as a single linear list of 64-bit quantities, each containing the absolute address of one of the string literals in memory. This means that each string takes up 8 bytes of additional space, along with 2 bytes of relocation data. It also means that the array cannot be used until PE/COFF relocation has completed, and so the following invocation Status =3D PeCoffLoaderRelocateImage (&ImageContext); ASSERT_EFI_ERROR (Status); that we will be introducing into StandaloneMmCore entrypoint for AARCH64 to relocate the executable on the fly is guaranteed to return bogus output or crash, which is less than helpful. So fix both issues, by emitting mStatusString as an array of char arrays instead. The memory footprint increases from 955 to 975 bytes, but given that in the latter case, the overhead consists of 410 NUL characters rather than 390 bytes worth of absolute addresses and relocation records, the impact on a compressed image is actually positive. For example, when building ArmVirtQemu.dsc in RELEASE mode for AARCH64 with the GCC5 profile, I get: Before FV Space Information FVMAIN [99%Full] 4784768 total, 4784720 used, 48 free FVMAIN_COMPACT [38%Full] 2093056 total, 811560 used, 1281496 free After FV Space Information FVMAIN [99%Full] 4780672 total, 4780624 used, 48 free FVMAIN_COMPACT [38%Full] 2093056 total, 813488 used, 1279568 free So the compressed image is 4 KB smaller, whereas the entire image is < 2 KB larger, which is in the order of 0.2 % Signed-off-by: Ard Biesheuvel --- MdePkg/Library/BasePrintLib/PrintLibInternal.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MdePkg/Library/BasePrintLib/PrintLibInternal.c b/MdePkg/Librar= y/BasePrintLib/PrintLibInternal.c index b6ec5ac4fbb9..c8b932c7e07a 100644 --- a/MdePkg/Library/BasePrintLib/PrintLibInternal.c +++ b/MdePkg/Library/BasePrintLib/PrintLibInternal.c @@ -27,7 +27,7 @@ =20 GLOBAL_REMOVE_IF_UNREFERENCED CONST CHAR8 mHexStr[] =3D {'0','1','2','3','= 4','5','6','7','8','9','A','B','C','D','E','F'}; =20 -GLOBAL_REMOVE_IF_UNREFERENCED CONST CHAR8 * CONST mStatusString[] =3D { +GLOBAL_REMOVE_IF_UNREFERENCED CONST CHAR8 mStatusString[][25] =3D { "Success", // RETURN_SUCCESS =3D 0 "Warning Unknown Glyph", // RETURN_WARN_UNKNOWN_GLYPH =3D 1 "Warning Delete Failure", // RETURN_WARN_DELETE_FAILURE =3D 2 --=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 (#61039): https://edk2.groups.io/g/devel/message/61039 Mute This Topic: https://groups.io/mt/74792288/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-