From a3e25cc8a1dd3d1ea24ed02f90c44221e015e965 Mon Sep 17 00:00:00 2001 From: Laszlo Ersek Date: Sat, 7 Mar 2020 00:04:42 +0100 Subject: [PATCH] OvmfPkg/X86QemuLoadImageLib: fix "unused variable" error in X64 DXE builds MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. Move the local variable to the inner scope, where declaration and usage are inseparable. (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.) Cc: Ard Biesheuvel Cc: Jordan Justen Cc: Philippe Mathieu-Daudé Fixes: 7c47d89003a6f8f7f6f0ce8ca7d3e87c630d14cc Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=2572 Signed-off-by: Laszlo Ersek Reviewed-by: Ard Biesheuvel --- OvmfPkg/Library/X86QemuLoadImageLib/X86QemuLoadImageLib.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/OvmfPkg/Library/X86QemuLoadImageLib/X86QemuLoadImageLib.c b/OvmfPkg/Library/X86QemuLoadImageLib/X86QemuLoadImageLib.c index c5bd6862b2..1868c9fcaf 100644 --- a/OvmfPkg/Library/X86QemuLoadImageLib/X86QemuLoadImageLib.c +++ b/OvmfPkg/Library/X86QemuLoadImageLib/X86QemuLoadImageLib.c @@ -460,7 +460,6 @@ QemuStartKernelImage ( { EFI_STATUS Status; OVMF_LOADED_X86_LINUX_KERNEL *LoadedImage; - EFI_HANDLE KernelImageHandle; Status = gBS->OpenProtocol ( *ImageHandle, @@ -481,6 +480,8 @@ QemuStartKernelImage ( ); #ifdef MDE_CPU_IA32 if (Status == EFI_UNSUPPORTED) { + EFI_HANDLE KernelImageHandle; + // // On IA32, EFI_UNSUPPORTED means that the image's machine type is X64 while // we are expecting a IA32 one, and the StartImage () boot service is unable