From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-1.mimecast.com (us-smtp-1.mimecast.com [205.139.110.120]) by mx.groups.io with SMTP id smtpd.web10.6730.1583795960145005085 for ; Mon, 09 Mar 2020 16:19:20 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=DRWoIsd9; spf=pass (domain: redhat.com, ip: 205.139.110.120, mailfrom: lersek@redhat.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1583795959; h=from:from:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=vPb8F0pSZ1+BPz5PiPPDd27dFLUzBkqJhLGizyNjcPM=; b=DRWoIsd9eQQ1I2sM8BwfUM+7qoul+gImpS37eJhnVJG16nAHSrbbMZdEnXz6oUFpU/1XBg LpkewLAWAlTmY2C0sFwDSd9ogBNJPN1KT1vW/R5rwjIT+Se8novisuS3G/b6ZKnpjafYL9 XZrgoVkIGMO7ZbkNAY7vly/LdAIzr1M= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-340-vdG8bPLuO3-5K19RQr7xGg-1; Mon, 09 Mar 2020 19:19:13 -0400 X-MC-Unique: vdG8bPLuO3-5K19RQr7xGg-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 676A9100550D; Mon, 9 Mar 2020 23:19:12 +0000 (UTC) Received: from lacos-laptop-7.usersys.redhat.com (ovpn-116-76.ams2.redhat.com [10.36.116.76]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3E80D19C4F; Mon, 9 Mar 2020 23:19:11 +0000 (UTC) Subject: Re: [edk2-devel] [PATCH] OvmfPkg/X86QemuLoadImageLib: fix "unused variable" error in X64 DXE builds From: "Laszlo Ersek" To: edk2-devel-groups-io Cc: Ard Biesheuvel , Jordan Justen , =?UTF-8?Q?Philippe_Mathieu-Daud=c3=a9?= Reply-To: devel@edk2.groups.io, lersek@redhat.com References: <20200306230442.24100-1-lersek@redhat.com> Message-ID: <0448d5e5-9e04-a20f-be35-14c110f4ed8a@redhat.com> Date: Tue, 10 Mar 2020 00:19:10 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: <20200306230442.24100-1-lersek@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 03/07/20 00:04, Laszlo Ersek wrote: > When the MDE_CPU_IA32 macro is not defined, there is no access to the > "KernelImageHandle" local variable in QemuStartKernelImage(). This breaks > the OvmfPkgIa32X64 and OvmfPkgX64 platform builds, at least with gcc-8. >=20 > Move the local variable to the inner scope, where declaration and usage > are inseparable. >=20 > (Note that such inner-scope declarations are frowned upon in the wider > edk2 codebase, but we use them liberally in ArmVirtPkg and OvmfPkg anyway= , > because they help us reason about variable lifetime and visibility.) >=20 > Cc: Ard Biesheuvel > Cc: Jordan Justen > Cc: Philippe Mathieu-Daud=C3=A9 > Fixes: 7c47d89003a6f8f7f6f0ce8ca7d3e87c630d14cc > Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2572 > Signed-off-by: Laszlo Ersek > --- >=20 > Notes: > Ard, if you get to it first, feel free to push this in my stead. Than= ks! > =20 > Repo: https://pagure.io/lersek/edk2.git > Branch: x86qlil_build_fix >=20 > OvmfPkg/Library/X86QemuLoadImageLib/X86QemuLoadImageLib.c | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) >=20 > diff --git a/OvmfPkg/Library/X86QemuLoadImageLib/X86QemuLoadImageLib.c b/= OvmfPkg/Library/X86QemuLoadImageLib/X86QemuLoadImageLib.c > index c5bd6862b265..1868c9fcafdf 100644 > --- a/OvmfPkg/Library/X86QemuLoadImageLib/X86QemuLoadImageLib.c > +++ b/OvmfPkg/Library/X86QemuLoadImageLib/X86QemuLoadImageLib.c > @@ -457,67 +457,68 @@ EFIAPI > QemuStartKernelImage ( > IN OUT EFI_HANDLE *ImageHandle > ) > { > EFI_STATUS Status; > OVMF_LOADED_X86_LINUX_KERNEL *LoadedImage; > - EFI_HANDLE KernelImageHandle; > =20 > Status =3D gBS->OpenProtocol ( > *ImageHandle, > &gOvmfLoadedX86LinuxKernelProtocolGuid, > (VOID **)&LoadedImage, > gImageHandle, // AgentHandle > NULL, // ControllerHandle > EFI_OPEN_PROTOCOL_GET_PROTOCOL > ); > if (!EFI_ERROR (Status)) { > return QemuStartLegacyImage (*ImageHandle); > } > =20 > Status =3D gBS->StartImage ( > *ImageHandle, > NULL, // ExitDataSize > NULL // ExitData > ); > #ifdef MDE_CPU_IA32 > if (Status =3D=3D EFI_UNSUPPORTED) { > + EFI_HANDLE KernelImageHandle; > + > // > // On IA32, EFI_UNSUPPORTED means that the image's machine type is X= 64 while > // we are expecting a IA32 one, and the StartImage () boot service i= s unable > // to handle it, either because the image does not have the special = .compat > // PE/COFF section that Linux specifies for mixed mode capable image= s, or > // because we are running without the support code for that. So load= the > // image again, using the legacy loader, and unload the normally loa= ded > // image before starting the legacy one. > // > Status =3D QemuLoadLegacyImage (&KernelImageHandle); > if (EFI_ERROR (Status)) { > // > // Note: no change to (*ImageHandle), the caller will release it. > // > return Status; > } > // > // Swap in the legacy-loaded image. > // > QemuUnloadKernelImage (*ImageHandle); > *ImageHandle =3D KernelImageHandle; > return QemuStartLegacyImage (KernelImageHandle); > } > #endif > return Status; > } > =20 > /** > Unloads an image loaded with QemuLoadKernelImage (). > =20 > @param ImageHandle Handle that identifies the image to be > unloaded. > =20 > @retval EFI_SUCCESS The image has been unloaded. > @retval EFI_UNSUPPORTED The image has been started, and does n= ot > support unload. > @retval EFI_INVALID_PARAMETER ImageHandle is not a valid image handl= e. > =20 > @return Exit code from the image's unload func= tion. > **/ >=20 Commit a3e25cc8a1dd. Thanks Laszlo