From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by mx.groups.io with SMTP id smtpd.web10.22690.1682606845260675375 for ; Thu, 27 Apr 2023 07:47:25 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=RRcNVJlH; spf=pass (domain: kernel.org, ip: 139.178.84.217, mailfrom: ardb@kernel.org) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 98C5563897 for ; Thu, 27 Apr 2023 14:47:24 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 10498C433D2 for ; Thu, 27 Apr 2023 14:47:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1682606844; bh=1H7YCM3Cl0bekFudiHz/1oQOUz8Tvy4AFWpz434vWd8=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=RRcNVJlHCtCQEnvZ/I8HV3lT4a/PxOgJC0vmmbzlqqcfALsEgVtANB1KFvDeJ2npI Y22f6hJgSsqYLP7/RTcA4QOW+RTW7jBdQKyShCZpHdVOc5/+I0hNg7QrKW+xjGqLlD c0nXmIVTfKXkTJj9+n935pDJEM/ziJ7qcGk3bXA5WTvArz9qTp9HjOz8kR1NuOcBLT 3a6+b26QneuZnMJKXuaXDhBS1kqrVa1+vzGo3xVJHWEvd6K/wTQZIbMJgYud2K/iVN g/Szy89XmbrCZsP5VXy2Fwwn3VRKplJqvqgr3tZNofoEcjN2pMTSeCbQBNDZMCTGOG HFa301oHIxU9w== Received: by mail-lf1-f42.google.com with SMTP id 2adb3069b0e04-4f001a2f3aeso3471413e87.2 for ; Thu, 27 Apr 2023 07:47:23 -0700 (PDT) X-Gm-Message-State: AC+VfDx6Jo6RDep1QAXSDPkc7m/KTPsYXdltxjDUMPoBfceXSHevam54 7ua1RBiHyJx7VrqaR1zSEvcaNt2xW++2IT3al7g= X-Google-Smtp-Source: ACHHUZ7D35ivTBPVq+j1SMexSX0wZ/tyVloqp5htlt4SlHKoZxSGFfMsP7iLfJ9YGeDKfpqVifoOm10CCdVOTX8hB9I= X-Received: by 2002:ac2:520f:0:b0:4ea:f6d7:2293 with SMTP id a15-20020ac2520f000000b004eaf6d72293mr674731lfl.55.1682606842081; Thu, 27 Apr 2023 07:47:22 -0700 (PDT) MIME-Version: 1.0 References: <20230427061714.510-1-gaoliming@byosoft.com.cn> In-Reply-To: <20230427061714.510-1-gaoliming@byosoft.com.cn> From: "Ard Biesheuvel" Date: Thu, 27 Apr 2023 15:47:11 +0100 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [edk2-devel] [PATCH] MdePkg BasePeCoffLib: Ignore the debug entry read error after it is found To: devel@edk2.groups.io, gaoliming@byosoft.com.cn Cc: Michael Kubacki Content-Type: text/plain; charset="UTF-8" On Thu, 27 Apr 2023 at 07:17, gaoliming via groups.io wrote: > > BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=4425 > > This change is to support the pre-built EFI image on the old Edk2 code. > Old Edk2 GenFw tool generates the wrong debug entry in EFI image. > Those pre-built images can be loaded before d6457b309. > > Signed-off-by: Liming Gao > Cc: Ard Biesheuvel > Cc: Michael Kubacki > --- > MdePkg/Library/BasePeCoffLib/BasePeCoff.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/MdePkg/Library/BasePeCoffLib/BasePeCoff.c b/MdePkg/Library/BasePeCoffLib/BasePeCoff.c > index 4b71176a0c..4636842eeb 100644 > --- a/MdePkg/Library/BasePeCoffLib/BasePeCoff.c > +++ b/MdePkg/Library/BasePeCoffLib/BasePeCoff.c > @@ -735,7 +735,7 @@ PeCoffLoaderGetImageInfo ( > &Size, > &DebugEntry > ); > - if (RETURN_ERROR (Status) || (Size != ReadSize)) { > + if ((ImageContext->DebugDirectoryEntryRva == 0) && (RETURN_ERROR (Status) || (Size != ReadSize))) { I'm not sure I understand how this fixes anything. Why is the condition 'RVA == 0' significant here? Would something like the below perhaps work as well? --- a/MdePkg/Library/BasePeCoffLib/BasePeCoff.c +++ b/MdePkg/Library/BasePeCoffLib/BasePeCoff.c @@ -755,6 +755,17 @@ PeCoffLoaderGetImageInfo ( ImageContext->ImageSize += DebugEntry.SizeOfData; } + // + // Implementations of GenFw before commit 60e85a39fe49071 will + // concatenate the debug directory entry and the codeview entry, + // and erroneously put the combined size into the debug directory + // entry's size field. If this is the case, no other relevant + // directory entries can exist, and we can terminate here. + // + if (DebugEntry.FileOffset == (DebugDirectoryEntryFileOffset + Index)) { + break; + } + continue; }