From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by mx.groups.io with SMTP id smtpd.web11.3551.1571300276725803264 for ; Thu, 17 Oct 2019 01:17:56 -0700 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: intel.com, ip: 192.55.52.115, mailfrom: bob.c.feng@intel.com) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 17 Oct 2019 01:17:56 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.67,307,1566889200"; d="scan'208";a="347687345" Received: from fmsmsx104.amr.corp.intel.com ([10.18.124.202]) by orsmga004.jf.intel.com with ESMTP; 17 Oct 2019 01:17:55 -0700 Received: from fmsmsx604.amr.corp.intel.com (10.18.126.84) by fmsmsx104.amr.corp.intel.com (10.18.124.202) with Microsoft SMTP Server (TLS) id 14.3.439.0; Thu, 17 Oct 2019 01:17:55 -0700 Received: from fmsmsx604.amr.corp.intel.com (10.18.126.84) by fmsmsx604.amr.corp.intel.com (10.18.126.84) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1713.5; Thu, 17 Oct 2019 01:17:54 -0700 Received: from shsmsx107.ccr.corp.intel.com (10.239.4.96) by fmsmsx604.amr.corp.intel.com (10.18.126.84) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.1.1713.5 via Frontend Transport; Thu, 17 Oct 2019 01:17:54 -0700 Received: from shsmsx104.ccr.corp.intel.com ([169.254.5.166]) by SHSMSX107.ccr.corp.intel.com ([169.254.9.33]) with mapi id 14.03.0439.000; Thu, 17 Oct 2019 16:17:52 +0800 From: "Bob Feng" To: "Gao, Liming" , "devel@edk2.groups.io" Subject: Re: [Patch v3 03/11] BaseTools GenFw: Fix the issue to update the wrong size as SectionSize Thread-Topic: [Patch v3 03/11] BaseTools GenFw: Fix the issue to update the wrong size as SectionSize Thread-Index: AQHVhLf87y7FvLG25kaYRXsMUU+d+adefTSg Date: Thu, 17 Oct 2019 08:17:52 +0000 Message-ID: <08650203BA1BD64D8AD9B6D5D74A85D16154BC27@SHSMSX104.ccr.corp.intel.com> References: <1571295356-11608-1-git-send-email-liming.gao@intel.com> <1571295356-11608-4-git-send-email-liming.gao@intel.com> In-Reply-To: <1571295356-11608-4-git-send-email-liming.gao@intel.com> Accept-Language: zh-CN, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.239.127.40] MIME-Version: 1.0 Return-Path: bob.c.feng@intel.com Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Reviewed-by: Bob Feng -----Original Message----- From: Gao, Liming=20 Sent: Thursday, October 17, 2019 2:56 PM To: devel@edk2.groups.io Cc: Feng, Bob C Subject: [Patch v3 03/11] BaseTools GenFw: Fix the issue to update the wron= g size as SectionSize BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D1603 CLANG9 generated PE image exposes below two issues. 1. SectionSize is used to copy PE section data. It should be smaller than s= ection raw size. 2. The real data is required to be copied. So, copy the min size of Virtual= Size and SizeOfRawData. Signed-off-by: Liming Gao Cc: Bob Feng Reviewed-by: Philippe Mathieu-Daude --- BaseTools/Source/C/GenFw/GenFw.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/BaseTools/Source/C/GenFw/GenFw.c b/BaseTools/Source/C/GenFw/Ge= nFw.c index c99782b78e..8cab70ba4d 100644 --- a/BaseTools/Source/C/GenFw/GenFw.c +++ b/BaseTools/Source/C/GenFw/GenFw.c @@ -653,7 +653,11 @@ PeCoffConvertImageToXip ( // // Make the size of raw data in section header alignment. // - SectionHeader->SizeOfRawData =3D (SectionHeader->Misc.VirtualSize + Pe= Hdr->Pe32.OptionalHeader.FileAlignment - 1) & (~(PeHdr->Pe32.OptionalHeader= .FileAlignment - 1)); + SectionSize =3D (SectionHeader->Misc.VirtualSize + PeHdr->Pe32.Optiona= lHeader.FileAlignment - 1) & (~(PeHdr->Pe32.OptionalHeader.FileAlignment - = 1)); + if (SectionSize < SectionHeader->SizeOfRawData) { + SectionHeader->SizeOfRawData =3D SectionSize; + } + SectionHeader->PointerToRawData =3D SectionHeader->VirtualAddress; } =20 @@ -999,7 +1003,7 @@ Returns: CopyMem ( FileBuffer + SectionHeader->PointerToRawData, (VOID*) (UINTN) (ImageContext.ImageAddress + SectionHeader->VirtualA= ddress), - SectionHeader->SizeOfRawData + SectionHeader->SizeOfRawData < SectionHeader->Misc.VirtualSize ?=20 + SectionHeader->SizeOfRawData : SectionHeader->Misc.VirtualSize ); } =20 -- 2.13.0.windows.1