From 94327aacda6585fbf2c747bfc861cd297d7a0eb5 Mon Sep 17 00:00:00 2001
From: Vitaly Cheptsov <cheptsov@ispras.ru>
Date: Sat, 5 Mar 2022 19:28:53 +0300
Subject: [PATCH] OvmfPkg/DxePciLibI440FxQ34: Add UefiBootServicesTableLib
 dependency

In case PlatformBootManagerLib does not have PciLib dependency,
we need to explicitly depend on UefiBootServicesTableLib.
Otherwise UefiBootServicesTableLib may not be constructed before
DxePciLibI440FxQ35, which uses a constructor-less PcdLib that directly
accesses gBS.

This can be viewed as a bug in the current implementation of BaseTools,
namely GetModuleLibInstances. This function drops all constructor-less
dependencies from the dependency resolution list to avoid dependency
cycles, which at the same time causes issues like above.

To properly fix the issue one should go over each library with
constructors and for each its dependency without constructors add all
the secondary dependencies that do have constructors. While doable,
it may cause considerable performance issues and is thus not done
in this patch.

Signed-off-by: Vitaly Cheptsov <cheptsov@ispras.ru>
---
 OvmfPkg/Library/DxePciLibI440FxQ35/DxePciLibI440FxQ35.inf | 1 +
 1 file changed, 1 insertion(+)

diff --git a/OvmfPkg/Library/DxePciLibI440FxQ35/DxePciLibI440FxQ35.inf b/OvmfPkg/Library/DxePciLibI440FxQ35/DxePciLibI440FxQ35.inf
index 4a8c0bac23..a9b712afb8 100644
--- a/OvmfPkg/Library/DxePciLibI440FxQ35/DxePciLibI440FxQ35.inf
+++ b/OvmfPkg/Library/DxePciLibI440FxQ35/DxePciLibI440FxQ35.inf
@@ -35,6 +35,7 @@
   PcdLib
   PciCf8Lib
   PciExpressLib
+  UefiBootServicesTableLib
 
 [Pcd]
   gUefiOvmfPkgTokenSpaceGuid.PcdOvmfHostBridgePciDevId