From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) (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 CA55521DF968C for ; Mon, 7 Aug 2017 18:11:58 -0700 (PDT) Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 07 Aug 2017 18:14:15 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.41,340,1498546800"; d="scan'208,217";a="1001125115" Received: from fmsmsx107.amr.corp.intel.com ([10.18.124.205]) by orsmga003.jf.intel.com with ESMTP; 07 Aug 2017 18:14:15 -0700 Received: from fmsmsx116.amr.corp.intel.com (10.18.116.20) by fmsmsx107.amr.corp.intel.com (10.18.124.205) with Microsoft SMTP Server (TLS) id 14.3.319.2; Mon, 7 Aug 2017 18:14:14 -0700 Received: from shsmsx152.ccr.corp.intel.com (10.239.6.52) by fmsmsx116.amr.corp.intel.com (10.18.116.20) with Microsoft SMTP Server (TLS) id 14.3.319.2; Mon, 7 Aug 2017 18:14:14 -0700 Received: from shsmsx103.ccr.corp.intel.com ([169.254.4.116]) by SHSMSX152.ccr.corp.intel.com ([169.254.6.122]) with mapi id 14.03.0319.002; Tue, 8 Aug 2017 09:14:12 +0800 From: "Zhu, Yonghong" To: "afish@apple.com" CC: "edk2-devel@lists.01.org" , "Gao, Liming" , "Kinney, Michael D" , "Zhu, Yonghong" Thread-Topic: [Patch] BaseTools: Fix Segmentation fault: 11 when build AppPkg with XCODE5 Thread-Index: AQHTD5n1yOvTdKm2lEu1GVOxFYp8IaJ5mopw Date: Tue, 8 Aug 2017 01:14:12 +0000 Message-ID: References: <1502078429-13340-1-git-send-email-yonghong.zhu@intel.com> <5BC1C303-CE42-4DAD-91EB-F4BB327DE88A@apple.com> In-Reply-To: <5BC1C303-CE42-4DAD-91EB-F4BB327DE88A@apple.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-titus-metadata-40: eyJDYXRlZ29yeUxhYmVscyI6IiIsIk1ldGFkYXRhIjp7Im5zIjoiaHR0cDpcL1wvd3d3LnRpdHVzLmNvbVwvbnNcL0ludGVsMyIsImlkIjoiZGU4NTBlZWMtMzRmNS00MTEzLWE0ZWUtMDYzZTQ4ZjcyNTcxIiwicHJvcHMiOlt7Im4iOiJDVFBDbGFzc2lmaWNhdGlvbiIsInZhbHMiOlt7InZhbHVlIjoiQ1RQX0lDIn1dfV19LCJTdWJqZWN0TGFiZWxzIjpbXSwiVE1DVmVyc2lvbiI6IjE2LjUuOS4zIiwiVHJ1c3RlZExhYmVsSGFzaCI6IkQxekVwVEVuWnI2NlQrbWdWMjFldFwvaGxLOUNcL25WYWdxNk5cL0xnMTJUeFU9In0= x-ctpclassification: CTP_IC dlp-product: dlpe-windows dlp-version: 10.0.102.7 dlp-reaction: no-action x-originating-ip: [10.239.127.40] MIME-Version: 1.0 X-Content-Filtered-By: Mailman/MimeDel 2.1.22 Subject: Re: [Patch] BaseTools: Fix Segmentation fault: 11 when build AppPkg with XCODE5 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: Tue, 08 Aug 2017 01:11:59 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable When push this GenFw fix, I will update the Agreement to 1.1. I also help to send out PeCoff lib 's patch. Best Regards, Zhu Yonghong From: afish@apple.com [mailto:afish@apple.com] Sent: Tuesday, August 8, 2017 12:26 AM To: Zhu, Yonghong Cc: edk2-devel@lists.01.org; Gao, Liming ; Kinney, Mi= chael D Subject: Re: [Patch] BaseTools: Fix Segmentation fault: 11 when build AppPk= g with XCODE5 Should that be: Contributed-under: TianoCore Contribution Agreement 1.1 I also noticed the PeCoff lib is going to loop and reload the .debug suctio= n due to this mtoc bug, so it would be good to harden that code too. git diff MdePkg/Library/BasePeCoffLib/BasePeCoff.c diff --git a/MdePkg/Library/BasePeCoffLib/BasePeCoff.c b/MdePkg/Library/Bas= ePeCoffLib/BasePeCoff.c index 8d1daba..1e4c67e 100644 --- a/MdePkg/Library/BasePeCoffLib/BasePeCoff.c +++ b/MdePkg/Library/BasePeCoffLib/BasePeCoff.c @@ -771,6 +771,8 @@ PeCoffLoaderGetImageInfo ( } return RETURN_SUCCESS; + } else if (DebugEntry.Type =3D=3D CODEVIEW_SIGNATURE_MTOC) { + return RETURN_SUCCESS; } } } @@ -862,6 +864,8 @@ PeCoffLoaderGetImageInfo ( if (DebugEntry.Type =3D=3D EFI_IMAGE_DEBUG_TYPE_CODEVIEW) { ImageContext->DebugDirectoryEntryRva =3D (UINT32) (DebugDirector= yEntryRva + Index); return RETURN_SUCCESS; + } else if (DebugEntry.Type =3D=3D CODEVIEW_SIGNATURE_MTOC) { + return RETURN_SUCCESS; } } } https://bugzilla.tianocore.org/show_bug.cgi?id=3D663 Contributed-under: TianoCore Contribution Agreement 1.1 Thanks, Andrew Fish On Aug 6, 2017, at 9:00 PM, Yonghong Zhu > wrote: it is a bug in mtoc setting the size of the debug directory entry to the size of the .debug section, not the size of the EFI_IMAGE_DEBUG_DIRECTORY_ENTRY. It was causing a loop to iterate and get bogus EFI_IMAGE_DEBUG_DIRECTORY_ENTRY data and pass that to memset() and boom. Cc: Liming Gao > Cc: Michael D Kinney > Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Andrew Fish > --- BaseTools/Source/C/GenFw/GenFw.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/BaseTools/Source/C/GenFw/GenFw.c b/BaseTools/Source/C/GenFw/Ge= nFw.c index 246deb0..af60c92 100644 --- a/BaseTools/Source/C/GenFw/GenFw.c +++ b/BaseTools/Source/C/GenFw/GenFw.c @@ -2813,10 +2813,11 @@ Returns: // // Get Debug, Export and Resource EntryTable RVA address. // Resource Directory entry need to review. // Optional32Hdr =3D (EFI_IMAGE_OPTIONAL_HEADER32 *) ((UINT8*) FileHdr + siz= eof (EFI_IMAGE_FILE_HEADER)); + Optional64Hdr =3D (EFI_IMAGE_OPTIONAL_HEADER64 *) ((UINT8*) FileHdr + si= zeof (EFI_IMAGE_FILE_HEADER)); if (Optional32Hdr->Magic =3D=3D EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) { SectionHeader =3D (EFI_IMAGE_SECTION_HEADER *) ((UINT8 *) Optional32Hdr= + FileHdr->SizeOfOptionalHeader); if (Optional32Hdr->NumberOfRvaAndSizes > EFI_IMAGE_DIRECTORY_ENTRY_EXPO= RT && \ Optional32Hdr->DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_EXPORT].Size= !=3D 0) { ExportDirectoryEntryRva =3D Optional32Hdr->DataDirectory[EFI_IMAGE_DI= RECTORY_ENTRY_EXPORT].VirtualAddress; @@ -2833,11 +2834,10 @@ Returns: Optional32Hdr->DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_DEBUG].Size = =3D 0; Optional32Hdr->DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_DEBUG].Virtu= alAddress =3D 0; } } } else { - Optional64Hdr =3D (EFI_IMAGE_OPTIONAL_HEADER64 *) ((UINT8*) FileHdr + = sizeof (EFI_IMAGE_FILE_HEADER)); SectionHeader =3D (EFI_IMAGE_SECTION_HEADER *) ((UINT8 *) Optional64Hdr= + FileHdr->SizeOfOptionalHeader); if (Optional64Hdr->NumberOfRvaAndSizes > EFI_IMAGE_DIRECTORY_ENTRY_EXPO= RT && \ Optional64Hdr->DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_EXPORT].Size= !=3D 0) { ExportDirectoryEntryRva =3D Optional64Hdr->DataDirectory[EFI_IMAGE_DI= RECTORY_ENTRY_EXPORT].VirtualAddress; } @@ -2907,10 +2907,20 @@ Returns: RsdsEntry->Unknown =3D 0; RsdsEntry->Unknown2 =3D 0; RsdsEntry->Unknown3 =3D 0; RsdsEntry->Unknown4 =3D 0; RsdsEntry->Unknown5 =3D 0; + } else if (RsdsEntry->Signature =3D=3D CODEVIEW_SIGNATURE_MTOC) { + // MTOC sets DebugDirectoryEntrySize to size of the .debug secti= on, so fix it. + if (!ZeroDebugFlag) { + if (Optional32Hdr->Magic =3D=3D EFI_IMAGE_NT_OPTIONAL_HDR32_MA= GIC) { + Optional32Hdr->DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_DEBUG= ].Size =3D sizeof (EFI_IMAGE_DEBUG_DIRECTORY_ENTRY); + } else { + Optional64Hdr->DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_DEBUG= ].Size =3D sizeof (EFI_IMAGE_DEBUG_DIRECTORY_ENTRY); + } + } + break; } } } } -- 2.6.1.windows.1