From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) (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 2EFFC2095896D for ; Wed, 5 Jul 2017 10:31:44 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 40D9FC04B94A; Wed, 5 Jul 2017 17:33:23 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 40D9FC04B94A Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=lersek@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 40D9FC04B94A Received: from lacos-laptop-7.usersys.redhat.com (ovpn-116-25.phx2.redhat.com [10.3.116.25]) by smtp.corp.redhat.com (Postfix) with ESMTP id 06FBA1712E; Wed, 5 Jul 2017 17:33:19 +0000 (UTC) To: Ard Biesheuvel Cc: edk2-devel-01 , Gerd Hoffmann , Leif Lindholm , Liming Gao , Yonghong Zhu References: <20170705164218.25814-1-lersek@redhat.com> From: Laszlo Ersek Message-ID: Date: Wed, 5 Jul 2017 19:33:19 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 MIME-Version: 1.0 In-Reply-To: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Wed, 05 Jul 2017 17:33:23 +0000 (UTC) Subject: Re: [PATCH] BaseTools/GenFw: work around GNU Binutils bug wrt. DebugDirectoryEntrySize 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: Wed, 05 Jul 2017 17:31:44 -0000 Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit On 07/05/17 18:45, Ard Biesheuvel wrote: > On 5 July 2017 at 17:42, Laszlo Ersek wrote: >> GNU Binutils produce a PE debug directory with one > > This sentence already confuses me. This crash is reproducible on ARM, > but the ARM toolchains are strictly ELF based, and all PE/COFF data > structures are created by GenFw itself, never by binutils. So I don't > see how this could be a binutils bug. Geez, you are totally right. From "BaseTools/Source/C/GenFw/Elf64Convert.c": > STATIC > VOID > WriteDebug64 ( > VOID > ) > { > UINT32 Len; > EFI_IMAGE_OPTIONAL_HEADER_UNION *NtHdr; > EFI_IMAGE_DATA_DIRECTORY *DataDir; > EFI_IMAGE_DEBUG_DIRECTORY_ENTRY *Dir; > EFI_IMAGE_DEBUG_CODEVIEW_NB10_ENTRY *Nb10; > > Len = strlen(mInImageName) + 1; > > Dir = (EFI_IMAGE_DEBUG_DIRECTORY_ENTRY*)(mCoffFile + mDebugOffset); > Dir->Type = EFI_IMAGE_DEBUG_TYPE_CODEVIEW; > Dir->SizeOfData = sizeof(EFI_IMAGE_DEBUG_CODEVIEW_NB10_ENTRY) + Len; > Dir->RVA = mDebugOffset + sizeof(EFI_IMAGE_DEBUG_DIRECTORY_ENTRY); > Dir->FileOffset = mDebugOffset + sizeof(EFI_IMAGE_DEBUG_DIRECTORY_ENTRY); > > Nb10 = (EFI_IMAGE_DEBUG_CODEVIEW_NB10_ENTRY*)(Dir + 1); > Nb10->Signature = CODEVIEW_SIGNATURE_NB10; > strcpy ((char *)(Nb10 + 1), mInImageName); > > > NtHdr = (EFI_IMAGE_OPTIONAL_HEADER_UNION *)(mCoffFile + mNtHdrOffset); > DataDir = &NtHdr->Pe32Plus.OptionalHeader.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_DEBUG]; > DataDir->VirtualAddress = mDebugOffset; > DataDir->Size = Dir->SizeOfData + sizeof(EFI_IMAGE_DEBUG_DIRECTORY_ENTRY); > } The last assignment has the bug. It should be DataDir->Size = sizeof(EFI_IMAGE_DEBUG_DIRECTORY_ENTRY); Laszlo