From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 5BC2521C9E7BD for ; Wed, 5 Jul 2017 20:30:30 -0700 (PDT) Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga104.jf.intel.com with ESMTP; 05 Jul 2017 20:32:10 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.40,315,1496127600"; d="scan'208";a="282666607" Received: from fmsmsx103.amr.corp.intel.com ([10.18.124.201]) by fmsmga004.fm.intel.com with ESMTP; 05 Jul 2017 20:32:09 -0700 Received: from fmsmsx118.amr.corp.intel.com (10.18.116.18) by FMSMSX103.amr.corp.intel.com (10.18.124.201) with Microsoft SMTP Server (TLS) id 14.3.319.2; Wed, 5 Jul 2017 20:32:09 -0700 Received: from shsmsx101.ccr.corp.intel.com (10.239.4.153) by fmsmsx118.amr.corp.intel.com (10.18.116.18) with Microsoft SMTP Server (TLS) id 14.3.319.2; Wed, 5 Jul 2017 20:32:09 -0700 Received: from shsmsx102.ccr.corp.intel.com ([169.254.2.146]) by SHSMSX101.ccr.corp.intel.com ([169.254.1.197]) with mapi id 14.03.0319.002; Thu, 6 Jul 2017 11:32:07 +0800 From: "Gao, Liming" To: Ard Biesheuvel , "edk2-devel@lists.01.org" , "lersek@redhat.com" CC: "leif.lindholm@linaro.org" , "Zhu, Yonghong" Thread-Topic: [PATCH] BaseTools/GenFw: disregard payload in PE debug directory entry size Thread-Index: AQHS9b1NLbWAMrCgOUeoQUS3BcYpmKJGJFoA Date: Thu, 6 Jul 2017 03:32:07 +0000 Message-ID: <4A89E2EF3DFEDB4C8BFDE51014F606A14D751DDA@shsmsx102.ccr.corp.intel.com> References: <20170705183359.11970-1-ard.biesheuvel@linaro.org> In-Reply-To: <20170705183359.11970-1-ard.biesheuvel@linaro.org> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.239.127.40] MIME-Version: 1.0 Subject: Re: [PATCH] BaseTools/GenFw: disregard payload in PE debug directory entry size X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 06 Jul 2017 03:30:30 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Ard and Laszlo: Thanks for your quick fix. For my patch, I think it only impacts VS tool = chain. So, I don't verify GCC tool chain. Sorry for it. =20 Reviewed-by: Liming Gao Thanks Liming >-----Original Message----- >From: Ard Biesheuvel [mailto:ard.biesheuvel@linaro.org] >Sent: Thursday, July 06, 2017 2:34 AM >To: edk2-devel@lists.01.org; lersek@redhat.com >Cc: leif.lindholm@linaro.org; Gao, Liming ; Zhu, >Yonghong ; Ard Biesheuvel > >Subject: [PATCH] BaseTools/GenFw: disregard payload in PE debug directory >entry size > >Currently, the PE/COFF conversion routines in GenFw add a so-called >NB10 CodeView debug record to the image, and update the associated >directory entry in the PE/COFF optional header to contain its relative >virtual address (RVA) and size. > >However, there are two levels of indirection at work here: the actual >NB10 CodeView record (which is simply a magic number and some unused >data fields followed by the NUL terminated filename) is emitted >separately, and a separate descriptor is emitted that identifies the >NB10 CodeView record as type EFI_IMAGE_DEBUG_TYPE_CODEVIEW, and >records >its size. The directory entry in the PE/COFF optional header should >refer to this intermediate descriptor's address and size only, but >the WriteDebug## () routines in GenFw erroneously record the size of >both the descriptor and the NB10 CodeView record. > >This problem was exposed by commit e4129b0e5897 ("BaseTools: Update >GenFw to clear unused debug entry generated by VS tool chain", >2017-06-19), and GenFw now crashes when it attempts to iterate over >what it thinks are multiple intermediate descriptors for different >kinds of debug data embedded in the image. > >The error is understandable, given that both are carved out of the >same file space allocation, but this is really an implementation detail >of GenFw, and is not required. (Note that the intermediate descriptor >does not require a RVA and so it does not even need to be inside a >section) > >So omit the size of the NB10 CodeView record from the size recorded >in the optional header. > >Link: https://lists.01.org/pipermail/edk2-devel/2017-July/012181.html >Contributed-under: TianoCore Contribution Agreement 1.0 >Signed-off-by: Ard Biesheuvel >Co-debugged-or-whatever-by: Laszlo Ersek >--- > BaseTools/Source/C/GenFw/Elf32Convert.c | 2 +- > BaseTools/Source/C/GenFw/Elf64Convert.c | 2 +- > 2 files changed, 2 insertions(+), 2 deletions(-) > >diff --git a/BaseTools/Source/C/GenFw/Elf32Convert.c >b/BaseTools/Source/C/GenFw/Elf32Convert.c >index f7b084dc9b84..14fe4a285857 100644 >--- a/BaseTools/Source/C/GenFw/Elf32Convert.c >+++ b/BaseTools/Source/C/GenFw/Elf32Convert.c >@@ -1142,7 +1142,7 @@ WriteDebug32 ( > NtHdr =3D (EFI_IMAGE_OPTIONAL_HEADER_UNION *)(mCoffFile + >mNtHdrOffset); > DataDir =3D &NtHdr- >>Pe32.OptionalHeader.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_DEBUG >]; > DataDir->VirtualAddress =3D mDebugOffset; >- DataDir->Size =3D Dir->SizeOfData + >sizeof(EFI_IMAGE_DEBUG_DIRECTORY_ENTRY); >+ DataDir->Size =3D sizeof(EFI_IMAGE_DEBUG_DIRECTORY_ENTRY); > } > > STATIC >diff --git a/BaseTools/Source/C/GenFw/Elf64Convert.c >b/BaseTools/Source/C/GenFw/Elf64Convert.c >index 7eed7b92d30f..c39bdff063ab 100644 >--- a/BaseTools/Source/C/GenFw/Elf64Convert.c >+++ b/BaseTools/Source/C/GenFw/Elf64Convert.c >@@ -1095,7 +1095,7 @@ WriteDebug64 ( > NtHdr =3D (EFI_IMAGE_OPTIONAL_HEADER_UNION *)(mCoffFile + >mNtHdrOffset); > DataDir =3D &NtHdr- >>Pe32Plus.OptionalHeader.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_DE >BUG]; > DataDir->VirtualAddress =3D mDebugOffset; >- DataDir->Size =3D Dir->SizeOfData + >sizeof(EFI_IMAGE_DEBUG_DIRECTORY_ENTRY); >+ DataDir->Size =3D sizeof(EFI_IMAGE_DEBUG_DIRECTORY_ENTRY); > } > > STATIC >-- >2.9.3