From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-io0-x235.google.com (mail-io0-x235.google.com [IPv6:2607:f8b0:4001:c06::235]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 4AAA31A1DF8 for ; Sun, 21 Aug 2016 23:59:33 -0700 (PDT) Received: by mail-io0-x235.google.com with SMTP id m101so101425610ioi.2 for ; Sun, 21 Aug 2016 23:59:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=vMM2tle9uTEc6luu+utCpXW1W/fAxgSe8MWBoNNZb/o=; b=RPy2gilEf5XoWx3kcEC/kzBbsWHz9e5OvZE+JJlaAOd8NeJSedRSDlUxaET2DxgkhM lGHty7HuLXdSZCL6m/e9QZXh7L8xqVRH+dbTt9/ceGE7kySJb6FSIuCxacTPE75hM7P0 oPFarelJcWUAvztYynf0ayJ4xhrN84OjMMv6I= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=vMM2tle9uTEc6luu+utCpXW1W/fAxgSe8MWBoNNZb/o=; b=Ovop0hV8JlQtmsDYAB/eDvIgCmDmwsfOnSjNDcYc2xstniz4Vw+kZGRx4Luwxfl8jA G8kggPuovigPqPtUWQVKpm05mS0GkovcbkDWd1q2K+h5KeUz5kDeVIbxzYLk+LS9aJw5 AVtPLb9TccAuxZDHsRNEnPEwt+fwqsAgUe4/inpqaXFb/Kv+vvsG2sfum43GKeaFK9xV hwczRa9t+3e4khqdWuE363u01QX7GrI8hLr6OuO1HazYZ+WdP5sEX7JWSowqccopPyps bxMGc34FAR2+jjuzDfjU0Ocd6RggLNA+kM9Vu69LAzaMuK90xVs5E2uZerSHkNi620b5 JVxg== X-Gm-Message-State: AEkoouvxu9ugZO3w+CNrEM/LtV+IhSpkFwsTYBHSIzrv0GgQC8ntXB3umolUBO/wAP/H8kqmfrBDIgdRV8eOxp09 X-Received: by 10.107.40.133 with SMTP id o127mr21178249ioo.183.1471849172334; Sun, 21 Aug 2016 23:59:32 -0700 (PDT) MIME-Version: 1.0 Received: by 10.36.204.195 with HTTP; Sun, 21 Aug 2016 23:59:32 -0700 (PDT) In-Reply-To: <1471835341-25516-1-git-send-email-liming.gao@intel.com> References: <1471835341-25516-1-git-send-email-liming.gao@intel.com> From: Ard Biesheuvel Date: Mon, 22 Aug 2016 08:59:32 +0200 Message-ID: To: Liming Gao Cc: edk2-devel-01 , Yonghong Zhu Subject: Re: [Patch] BaseTools PeCoffLib: Fix the issue to get RelocationsStripped from TE image X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 22 Aug 2016 06:59:33 -0000 Content-Type: text/plain; charset=UTF-8 On 22 August 2016 at 05:09, Liming Gao wrote: > If PE image has no relocation section, and has not set RELOCS_STRIPPED, > after it is converted to TE image, GenFw will set its relocation section > VirtualAddress to non-zero address, and keep Size value as Zero. I cannot find this in the code. Instead, I see Elf64Convert.c-1031- Dir->Size = mCoffOffset - mRelocOffset; Elf64Convert.c-1032- if (Dir->Size == 0) { Elf64Convert.c:1033: // If no relocations, null out the directory entry and don't add the .reloc section Elf64Convert.c-1034- Dir->VirtualAddress = 0; Elf64Convert.c-1035- NtHdr->Pe32Plus.FileHeader.NumberOfSections--; Elf64Convert.c-1036- } else { Elf64Convert.c-1037- Dir->VirtualAddress = mRelocOffset; Elf64Convert.c:1038: CreateSectionHeader (".reloc", mRelocOffset, mCoffOffset - mRelocOffset, Elf64Convert.c-1039- EFI_IMAGE_SCN_CNT_INITIALIZED_DATA Elf64Convert.c-1040- | EFI_IMAGE_SCN_MEM_DISCARDABLE Elf64Convert.c-1041- | EFI_IMAGE_SCN_MEM_READ); Elf64Convert.c-1042- } Elf64Convert.c-1043-} so the virtual address is set to zero. I also tried applying the patch, and it does not solve the issue for me. Thanks, Ard. > MdePkg > BasePeCoffLib applied this rule to get RelocationsStripped attribute. But, > it is missing in BaseTools BasePeCoffLib. > > Cc: Ard Biesheuvel > Cc: Yonghong Zhu > Contributed-under: TianoCore Contribution Agreement 1.0 > Signed-off-by: Liming Gao > --- > BaseTools/Source/C/Common/BasePeCoff.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/BaseTools/Source/C/Common/BasePeCoff.c b/BaseTools/Source/C/Common/BasePeCoff.c > index 9652557..d0cc1af 100644 > --- a/BaseTools/Source/C/Common/BasePeCoff.c > +++ b/BaseTools/Source/C/Common/BasePeCoff.c > @@ -2,7 +2,7 @@ > > Functions to get info and load PE/COFF image. > > -Copyright (c) 2004 - 2010, Intel Corporation. All rights reserved.
> +Copyright (c) 2004 - 2016, Intel Corporation. All rights reserved.
> Portions Copyright (c) 2011 - 2013, ARM Ltd. All rights reserved.
> This program and the accompanying materials > are licensed and made available under the terms and conditions of the BSD License > @@ -336,7 +336,7 @@ Returns: > // > if ((!(ImageContext->IsTeImage)) && ((PeHdr->Pe32.FileHeader.Characteristics & EFI_IMAGE_FILE_RELOCS_STRIPPED) != 0)) { > ImageContext->RelocationsStripped = TRUE; > - } else if ((ImageContext->IsTeImage) && (TeHdr->DataDirectory[0].Size == 0)) { > + } else if ((ImageContext->IsTeImage) && (TeHdr->DataDirectory[0].Size == 0) && (TeHdr->DataDirectory[0].VirtualAddress == 0)) { > ImageContext->RelocationsStripped = TRUE; > } else { > ImageContext->RelocationsStripped = FALSE; > -- > 2.8.0.windows.1 >