Skip to content

Global: Fix the issue that Depex sections exist in the INF files of UEFI_DRIVER or UEFI_APPLICATION#12343

Open
EricGao2015 wants to merge 5 commits intotianocore:masterfrom
EricGao2015:depex_in_uefi_driver_issue
Open

Global: Fix the issue that Depex sections exist in the INF files of UEFI_DRIVER or UEFI_APPLICATION#12343
EricGao2015 wants to merge 5 commits intotianocore:masterfrom
EricGao2015:depex_in_uefi_driver_issue

Conversation

@EricGao2015
Copy link
Copy Markdown
Contributor

@EricGao2015 EricGao2015 commented Mar 26, 2026

Description

Fixes #12276

The INF specification said:

If the module is not a library (no LIBRARY_CLASS in the [Defines] section) and the MODULE_TYPE is SEC, SMM_CORE, DXE_CORE, PEI_CORE, UEFI_DRIVER, UEFI_APPLICATION or HOST_APPLICATION a Depex section is not permitted.

Thus, this series of patches does the following:

  • Remove improper Depex section in UEFI_DRIVER and UEFI_APPLICATION. If the driver really depends on certain protocol, use notify function to handle the dependency.

  • Adds a check when retrieving dependency expression in BaseTools. If the module has [Depex] section but it's not permitted by INF specification, just throw warning message t instead of break the building proccess.

  • Breaking change?

    • Breaking change - Does this PR cause a break in build or boot behavior?
    • Examples: Does it add a new library class or move a module to a different repo.
  • Impacts security?

    • Security - Does this PR have a direct security impact?
    • Examples: Crypto algorithm change or buffer overflow fix.
  • Includes tests?

    • Tests - Does this PR include any explicit test code?
    • Examples: Unit tests or integration tests.

How This Was Tested

  • github CI check is passed.
  • Build every platform, check if there is building failure. Run the following commands for instance:
    build -a X64 -t GCC -p RedfishPkg/RedfishPkg.dsc
    build -a X64 -t GCC -p NetworkPkg/NetworkPkg.dsc
    build -a X64 -t GCC -p MdeModulePkg/MdeModulePkg.dsc
    build -a X64 -t GCC -p MdePkg/MdePkg.dsc
    build -a X64 -t GCC -p ShellPkg/ShellPkg.dsc
    ...
  • Add [Depex] in UEFI_DRIVER or UEFI_APPLICATION, building process will not be breaken in BaseTools and a warning message will be throwed when build the driver:
    [Depex] section is not permitted for UEFI_DRIVER/UEFI_APPLICATION module

Integration Instructions

Once the PR is merged, all UEFI drivers and uefi applications with [Depex] section will not be blocked by BaseTools when building but only warning message is throwed. If the driver is UEFI driver, remove Depex from INF file and check dependent protocol in driver binding Start() function or notify function if necessary.

@github-actions github-actions bot added the impact:breaking-change This change breaks existing APIs impacting build or boot. label Mar 26, 2026
@tianocore-assign-reviewers
Copy link
Copy Markdown

WARNING: Cannot add some reviewers: A user specified as a reviewer for this PR is not a collaborator of the repository. Please add them as a collaborator to the repository so they can be requested in the future.

Non-collaborators requested:

Attn Admins:


Admin Instructions:

  • Add the non-collaborators as collaborators to the appropriate team(s) listed in teams
  • If they are no longer needed as reviewers, remove them from Maintainers.txt

@EricGao2015 EricGao2015 changed the title Depex in uefi driver issue Global: Fix the issue that Depex sections exist in the INF files of UEFI_DRIVER or UEFI_APPLICATION Mar 26, 2026
@EricGao2015 EricGao2015 force-pushed the depex_in_uefi_driver_issue branch from 173e305 to 1cbe903 Compare March 26, 2026 06:35
@leiflindholm
Copy link
Copy Markdown
Member

Since it's a breaking change, PR description should have Integration Instructions.

BASE_NAME = TcpDxe
FILE_GUID = 1A7E4468-2F55-4a56-903C-01265EB7622B
MODULE_TYPE = UEFI_DRIVER
MODULE_TYPE = DXE_DRIVER
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the intent of all the network stack drivers is to be UEFI Drivers. Converting to DXE_DRIVER does not lool right. I think the bug may be that there is a depex for gEfiHash2ServiceBindingProtocolGuid. There are ways for a UEFI Driver to be notified when a dependent protocol is available or it can fail a driver binding start if its dependent services are not available.

BASE_NAME = RedfishConfigHandlerDriver
FILE_GUID = 6e881000-5749-11e8-9bf0-8cdcd426c973
MODULE_TYPE = UEFI_DRIVER
MODULE_TYPE = DXE_DRIVER
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment as TcpDxe. Need input from @AbnerChang to know if this is intended to be a UEFI Driver or if it should be a DXE Driver. If UEFI Driver, then Depex need to be removed and instead, the driver implementation needs to handle cases where dependent services are available or not.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment as TcpDxe. Need input from @AbnerChang to know if this is intended to be a UEFI Driver or if it should be a DXE Driver. If UEFI Driver, then Depex need to be removed and instead, the driver implementation needs to handle cases where dependent services are available or not.

@changab Hi Abner, please help to confirm this issue, thanks.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an UEFI driver, we have to remove the DEPEX. Let me confirm this.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an UEFI driver, we have to remove the DEPEX. Let me confirm this.

Hi Anber, I have removed Depex from RedfishConfigHandler driver and use notify function to handle the dependency. Please review it again. Thank you.

Copy link
Copy Markdown
Member

@changab changab Apr 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@EricGao2015, I didn't know you were working on this. Please refer to #12395, I have tested my fix on AMD platform. We don't need the notification for this driver, because the Redfish credential driver is a DXE driver. The Redfish credential must be ready before the ConnectController(). You can update your PR, remove the changes for Redfish, and resend the PR once 12395 gets merged. Thanks.

@EricGao2015
Copy link
Copy Markdown
Contributor Author

Since it's a breaking change, PR description should have Integration Instructions.

Updated, please check again. It's my understand for Integration Instructions.

@niruiyu
Copy link
Copy Markdown
Member

niruiyu commented Mar 30, 2026

I think it may cause combability issue as some downstream usages may already there.

@EricGao2015
Copy link
Copy Markdown
Contributor Author

I think it may cause combability issue as some downstream usages may already there.

Yes, this is also the aspect that I conern about. This issue has persisted for more than a decade, the PR will cause breaking change to downstream. So I would like to know the opinions of all stewards and reviewers.

@mdkinney
Copy link
Copy Markdown
Member

I have 2 open comments above that need to be addressed before this PR can be completed.

For the INFs that have a [Depex] of TRUE for module types that do not support [Depex]. I agree those are incorrect, but are effectively harmless. For example a UEFI Driver has an implied depex of all PI Arch Protocols. ANDing in an additional TRUE does not change the depex. I would like to see those cleaned up. So the patch to remove [Depex] TRUE for those cases looks correct.

The BaseTools change to raise this to an error may be good long term. Short term, raising it to a WARNING so downstream consumers can have a chance to clean up the warnings is likely a better first step. The challenge is deciding when it can be promoted from a WARNING to an ERROR.

@EricGao2015 EricGao2015 force-pushed the depex_in_uefi_driver_issue branch from 1cbe903 to 4fa189b Compare March 31, 2026 12:54
@EricGao2015
Copy link
Copy Markdown
Contributor Author

I have 2 open comments above that need to be addressed before this PR can be completed.

I will handle the 2 comments after getting Anber's ack.

For the INFs that have a [Depex] of TRUE for module types that do not support [Depex]. I agree those are incorrect, but are effectively harmless. For example a UEFI Driver has an implied depex of all PI Arch Protocols. ANDing in an additional TRUE does not change the depex. I would like to see those cleaned up. So the patch to remove [Depex] TRUE for those cases looks correct.

The BaseTools change to raise this to an error may be good long term. Short term, raising it to a WARNING so downstream consumers can have a chance to clean up the warnings is likely a better first step. The challenge is deciding when it can be promoted from a WARNING to an ERROR.

I agree with the gentle approach that raises warning instead of error. I have changed the print level form EdkLogger.error() to EdkLogger.warn(), so that the building will not be breaken.

@felixpgithub
Copy link
Copy Markdown
Contributor

The PR does not produce warnings on transitive dependencies (UEF driver uses a library instance with [Depex]). Is this intentional?

According to INF specification, UEFI_APPLICATION cannot have Depex
section. So remove it.

Signed-off-by: Qihang Gao <gaoqihang@loongson.cn>
According to INF specification, UEFI_DRIVER and UEFI_APPLICATION
cannot have Depex section. So remove it.

Signed-off-by: Qihang Gao <gaoqihang@loongson.cn>
According to INF specification, UEFI_DRIVER cannot have Depex section.
RedfishConfigHandlerDriver is a UEFI_DRIVER, so the Depex section must
be removed. But this driver really depends on
gEdkIIRedfishCredentialProtocol. In order to handle the dependency,
register a notify function once the protocol is failed to be located.

Signed-off-by: Qihang Gao <gaoqihang@loongson.cn>
According to INF specification, UEFI_DRIVER cannot have Depex section.
So remove Depex section from TcpDxe driver INF file.
The dependency has been guaranteed. In Tcp6DriverBindingStart() and
Tcp4DriverBindingStart() function, gEfiHash2ServiceBindingProtocol
has been checked if it is available by gBS->LocateProtocol().

Signed-off-by: Qihang Gao <gaoqihang@loongson.cn>
According to INF specification, if the module is not a library (no
LIBRARY_CLASS in the [Defines] section) and the MODULE_TYPE is SEC,
SMM_CORE, DXE_CORE, PEI_CORE, UEFI_DRIVER, UEFI_APPLICATION or
HOST_APPLICATION a Depex section is not permitted. Thus, this patch
adds a check when retrieving dependency expression. If the module
has [Depex] section but it's not permitted by INF specification,
just throw warning message to warn.

Signed-off-by: Qihang Gao <gaoqihang@loongson.cn>
@EricGao2015 EricGao2015 force-pushed the depex_in_uefi_driver_issue branch from 4fa189b to 08e5d3b Compare April 3, 2026 06:57
@EricGao2015
Copy link
Copy Markdown
Contributor Author

EricGao2015 commented Apr 3, 2026

The PR does not produce warnings on transitive dependencies (UEF driver uses a library instance with [Depex]). Is this intentional?

Yes. This patch only handles the case that Depex in INF file which MODULE_TYPE is UEFI_DRIVER or UEFI_APPLICATION, because this constitutes a clear violation of the INF specification.
I think the case you mentioned is valid because the INF specification does not forbid this behavior. Actually, if transitive dependencies really exist in UEFI_DRIVER, the driver may be treated as a DXE_DRIVER in BaseTools AutoGen code:

ModuleType = SUP_MODULE_DXE_DRIVER if self.ModuleType == SUP_MODULE_UEFI_DRIVER and self.DepexGenerated else self.ModuleType

One example is: NetworkPkg/Ip4Dxe/Ip4Dxe.inf is a UEFI_DRIVER without Depex, but this driver uses IoLib(NetworkPkg/Library/DxeNetLib/DxeNetLib.inf) which has dependency on gEfiRngProtocolGuid. After processing by AutoGen, the MODULE_TYPE becomes DXE_DRIVER in Build/NetworkPkg/DEBUG_GCC/X64/NetworkPkg/Ip4Dxe/Ip4Dxe/OUTPUT/Ip4Dxe.inf.

@mdkinney
Copy link
Copy Markdown
Member

mdkinney commented Apr 3, 2026

The PR does not produce warnings on transitive dependencies (UEF driver uses a library instance with [Depex]). Is this intentional?

Yes. This patch only handles the case that Depex in INF file which MODULE_TYPE is UEFI_DRIVER or UEFI_APPLICATION, because this constitutes a clear violation of the INF specification. I think the case you mentioned is valid because the INF specification does not forbid this behavior. Actually, if transitive dependencies really exist in UEFI_DRIVER, the driver may be treated as a DXE_DRIVER in BaseTools AutoGen code:

ModuleType = SUP_MODULE_DXE_DRIVER if self.ModuleType == SUP_MODULE_UEFI_DRIVER and self.DepexGenerated else self.ModuleType

One example is: NetworkPkg/Ip4Dxe/Ip4Dxe.inf is a UEFI_DRIVER without Depex, but this driver uses IoLib(NetworkPkg/Library/DxeNetLib/DxeNetLib.inf) which has dependency on gEfiRngProtocolGuid. After processing by AutoGen, the MODULE_TYPE becomes DXE_DRIVER in Build/NetworkPkg/DEBUG_GCC/X64/NetworkPkg/Ip4Dxe/Ip4Dxe/OUTPUT/Ip4Dxe.inf.

Library INFs that support multiple module types and Depex need to make sure their [Depex] section is correct. The [Depex] section does allow syntax to provide a module type specific depex such as:

[Depex.common.DXE_DRIVER, Depex.common.DXE_RUNTIME_DRIVER, Depex.common.DXE_SMM_DRIVER]
  gEfiFileExplorerProtocolGuid

The DxeNetLib lists the following module compatibiliy:

  LIBRARY_CLASS                  = NetLib|DXE_CORE DXE_DRIVER DXE_RUNTIME_DRIVER DXE_SMM_DRIVER UEFI_APPLICATION UEFI_DRIVER

But has a depex section that is applied to all module types the library supports

[Depex]
  gEfiRngProtocolGuid

So either DxeNetLib is listing extra module types that need to be removed or the [Depex] statement needs to be updated. I do not think that DXE_CORE or DXE_RUNTIME_DRIVER or DXE_SMM_DRIVER make much sense for this library. It would help to remove ones that can never be used.

Also, the dependency on The RNG Protocol can be handled differently for DXE_DRIVER and UEFI_DRIVER and UEFI_APPLICATION. For UEFI_DRIVER and UEFI_APPLICATION, the depex must be empty and the constructor can look for the RNG Protocol or use a RegisterProtocolNotify(). Only DXE_DRIVER can use a direct [Depex] on RNG Protocol. The most compatible lib would be to remove the [Depex] all together and use RegisterProtocolNotify() and have services that do not work until the RNG Protocol is available.

In general, the mix of UEFI_DRIVER and DXE_DRIVER in the network stack does not make sense. The network stack should be pure UEFI Drivers that can be loaded from Boot Manager or the Shell as well as embedded in platform FW.

@EricGao2015
Copy link
Copy Markdown
Contributor Author

The PR does not produce warnings on transitive dependencies (UEF driver uses a library instance with [Depex]). Is this intentional?

Yes. This patch only handles the case that Depex in INF file which MODULE_TYPE is UEFI_DRIVER or UEFI_APPLICATION, because this constitutes a clear violation of the INF specification. I think the case you mentioned is valid because the INF specification does not forbid this behavior. Actually, if transitive dependencies really exist in UEFI_DRIVER, the driver may be treated as a DXE_DRIVER in BaseTools AutoGen code:

ModuleType = SUP_MODULE_DXE_DRIVER if self.ModuleType == SUP_MODULE_UEFI_DRIVER and self.DepexGenerated else self.ModuleType

One example is: NetworkPkg/Ip4Dxe/Ip4Dxe.inf is a UEFI_DRIVER without Depex, but this driver uses IoLib(NetworkPkg/Library/DxeNetLib/DxeNetLib.inf) which has dependency on gEfiRngProtocolGuid. After processing by AutoGen, the MODULE_TYPE becomes DXE_DRIVER in Build/NetworkPkg/DEBUG_GCC/X64/NetworkPkg/Ip4Dxe/Ip4Dxe/OUTPUT/Ip4Dxe.inf.

Library INFs that support multiple module types and Depex need to make sure their [Depex] section is correct. The [Depex] section does allow syntax to provide a module type specific depex such as:

[Depex.common.DXE_DRIVER, Depex.common.DXE_RUNTIME_DRIVER, Depex.common.DXE_SMM_DRIVER]
  gEfiFileExplorerProtocolGuid

The DxeNetLib lists the following module compatibiliy:

  LIBRARY_CLASS                  = NetLib|DXE_CORE DXE_DRIVER DXE_RUNTIME_DRIVER DXE_SMM_DRIVER UEFI_APPLICATION UEFI_DRIVER

But has a depex section that is applied to all module types the library supports

[Depex]
  gEfiRngProtocolGuid

So either DxeNetLib is listing extra module types that need to be removed or the [Depex] statement needs to be updated. I do not think that DXE_CORE or DXE_RUNTIME_DRIVER or DXE_SMM_DRIVER make much sense for this library. It would help to remove ones that can never be used.

Also, the dependency on The RNG Protocol can be handled differently for DXE_DRIVER and UEFI_DRIVER and UEFI_APPLICATION. For UEFI_DRIVER and UEFI_APPLICATION, the depex must be empty and the constructor can look for the RNG Protocol or use a RegisterProtocolNotify(). Only DXE_DRIVER can use a direct [Depex] on RNG Protocol. The most compatible lib would be to remove the [Depex] all together and use RegisterProtocolNotify() and have services that do not work until the RNG Protocol is available.

In general, the mix of UEFI_DRIVER and DXE_DRIVER in the network stack does not make sense. The network stack should be pure UEFI Drivers that can be loaded from Boot Manager or the Shell as well as embedded in platform FW.

Thanks for your explanation, I understood your thought. The DxeNetLib issue is different with the subject of this PR, so I'll submit another PR to fix the issue later.

@mikebeaton
Copy link
Copy Markdown
Member

In general, the mix of UEFI_DRIVER and DXE_DRIVER in the network stack does not make sense. The network stack should be pure UEFI Drivers that can be loaded from Boot Manager or the Shell as well as embedded in platform FW.

@mdkinney - Hi. I'm not sure what should happen, but if not for your comment I would have said I am almost certain that DXE Drivers can be loaded from the Shell. A quick Google seems to confirm, though I haven't had a chance to retest what I thought I knew.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

impact:breaking-change This change breaks existing APIs impacting build or boot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: [Depex] sections exist in the INF files of UEFI_DRIVER or UEFI_APPLICATION

7 participants