edk2/MdeModulePkg/Library
Michael Kubacki 7a934d0bef MdeModulePkg: Replace include guards with #pragma once
Replace traditional `#ifndef`/`#define`/`#endif` include guards with
`#pragma` once.

`#pragma once` is a widely supported preprocessor directive that
prevents header files from being included multiple times. It is
supported by all toolchains used to build edk2: GCC, Clang/LLVM, and
MSVC.

Compared to macro-based include guards, `#pragma once`:

- Eliminates the risk of macro name collisions or copy/paste errors
  where two headers inadvertently use the same guard macro.
- Eliminate inconsistency in the way include guard macros are named
  (e.g., some files use `__FILE_H__`, others use `FILE_H_`, etc.).
- Reduces boilerplate (three lines replaced by one).
- Avoids polluting the macro namespace with guard symbols.
- Can improve build times as the preprocessor can skip re-opening the
  file entirely, rather than re-reading it to find the matching
  `#endif` ("multiple-include optimization").
  - Note that some compilers may already optimize traditional include
    guards, by recognzining the idiomatic pattern.

This change is made acknowledging that overall portability of the
code will technically be reduced, as `#pragma once` is not part of the
C/C++ standards.

However, this is considered acceptable given:

1. edk2 already defines a subset of supported compilers in
   BaseTools/Conf/tools_def.template, all of which have supported
   `#pragma once` for over two decades.
2. There have been concerns raised to the project about inconsistent
   include guard naming and potential macro collisions.

Approximate compiler support dates:

- MSVC: Supported since Visual C++ 4.2 (1996)
- GCC: Supported since 3.4 (2004)
  (http://gnu.ist.utl.pt/software/gcc/gcc-3.4/changes.html)
- Clang (LLVM based): Since initial release in 2007

Signed-off-by: Michael Kubacki <michael.kubacki@microsoft.com>
2026-02-23 21:01:28 +00:00
..
ArmFfaLib MdeModulePkg: Replace include guards with #pragma once 2026-02-23 21:01:28 +00:00
AuthVariableLibNull MdeModulePkg: Apply uncrustify changes 2021-12-07 17:24:28 +00:00
BaseBmpSupportLib MdeModulePkg: Apply uncrustify changes 2021-12-07 17:24:28 +00:00
BaseHobLibNull MdeModulePkg: Remove ARM32 Support 2025-09-25 22:04:10 +00:00
BaseIpmiCommandLibNull MdeModulePkg/IpmiCommandLib: Add NULL instance library 2023-01-19 03:57:32 +00:00
BaseIpmiLibNull MdeModulePkg: Apply uncrustify changes 2021-12-07 17:24:28 +00:00
BaseMemoryAllocationLibNull MdeModulePkg: Remove ARM32 Support 2025-09-25 22:04:10 +00:00
BasePlatformHookLibNull MdeModulePkg: Apply uncrustify changes 2021-12-07 17:24:28 +00:00
BaseResetSystemLibNull MdeModulePkg: Apply uncrustify changes 2021-12-07 17:24:28 +00:00
BaseRngLibTimerLib MdePkg/Rng: Add GetRngGuid() to RngLib 2023-09-08 09:48:55 +00:00
BaseSerialPortLib16550 MdeModulePkg: Fix definition typos 2025-06-11 17:20:20 +00:00
BaseSortLib MdeModulePkg: Apply uncrustify changes 2021-12-07 17:24:28 +00:00
BaseSpiHcPlatformLibNull MdeModulePkg:BaseSpiHcPlatformLib: Adding NULL lib instance 2024-05-08 04:43:58 +00:00
BaseVariableFlashInfoLib MdeModulePkg/VariableFlashInfoLib: Add initial library 2022-05-19 06:11:20 +00:00
BootDiscoveryPolicyUiLib MdeModulePkg: Apply uncrustify changes 2021-12-07 17:24:28 +00:00
BootLogoLib MdeModulePkg: Remove UGA support 2025-07-08 15:42:03 +00:00
BootMaintenanceManagerUiLib MdeModulePkg: Replace include guards with #pragma once 2026-02-23 21:01:28 +00:00
BootManagerUiLib MdeModulePkg: Replace include guards with #pragma once 2026-02-23 21:01:28 +00:00
BrotliCustomDecompressLib MdeModulePkg: Replace include guards with #pragma once 2026-02-23 21:01:28 +00:00
CpuExceptionHandlerLibNull MdeModulePkg: CpuExceptionHandlerLibNull: Return Success On Null Func 2025-10-23 00:57:59 +00:00
CustomizedDisplayLib MdeModulePkg: Replace include guards with #pragma once 2026-02-23 21:01:28 +00:00
DebugAgentLibNull MdeModulePkg/DebugAgentLibNull: Indicate SMM Debug Agent support or not 2023-12-26 07:18:26 +00:00
DeviceManagerUiLib MdeModulePkg: Replace include guards with #pragma once 2026-02-23 21:01:28 +00:00
DisplayUpdateProgressLibGraphics MdeModulePkg: Fix imbalanced debug macros 2022-09-09 01:42:39 +00:00
DisplayUpdateProgressLibText MdeModulePkg: Apply uncrustify changes 2021-12-07 17:24:28 +00:00
DxeCapsuleLibFmp MdeModulePkg: Replace include guards with #pragma once 2026-02-23 21:01:28 +00:00
DxeCapsuleLibNull MdeModulePkg: Apply uncrustify changes 2021-12-07 17:24:28 +00:00
DxeCoreMemoryAllocationLib MdeModulePkg: Replace include guards with #pragma once 2026-02-23 21:01:28 +00:00
DxeCorePerformanceLib MdeModulePkg: Replace include guards with #pragma once 2026-02-23 21:01:28 +00:00
DxeCrc32GuidedSectionExtractLib MdeModulePkg: Apply uncrustify changes 2021-12-07 17:24:28 +00:00
DxeDebugPrintErrorLevelLib MdeModulePkg: Apply uncrustify changes 2021-12-07 17:24:28 +00:00
DxeFileExplorerProtocol MdeModulePkg: Remove DXE_SAL_DRIVER 2025-10-30 10:00:32 +00:00
DxeIpmiLibIpmiProtocol MdeModulePkg: Apply uncrustify changes 2021-12-07 17:24:28 +00:00
DxePerformanceLib MdeModulePkg: Apply uncrustify changes 2021-12-07 17:24:28 +00:00
DxePrintLibPrint2Protocol MdeModulePkg: Remove DXE_SAL_DRIVER 2025-10-30 10:00:32 +00:00
DxeReportStatusCodeLib MdeModulePkg/Library: Fix property typos 2026-01-26 08:44:12 +00:00
DxeResetSystemLib MdeModulePkg: HOST_APPLICATION IA32/X64 only 2023-04-10 05:59:02 +00:00
DxeSecurityManagementLib MdeModulePkg: Apply uncrustify changes 2021-12-07 17:24:28 +00:00
FileExplorerLib MdeModulePkg: Replace include guards with #pragma once 2026-02-23 21:01:28 +00:00
FmpAuthenticationLibNull MdeModulePkg: Apply uncrustify changes 2021-12-07 17:24:28 +00:00
FrameBufferBltLib MdeModulePkg: Apply uncrustify changes 2021-12-07 17:24:28 +00:00
HobPrintLib MdeModulePkg HobPrintLib: Add Guid to Guids section. 2024-11-22 18:16:56 +00:00
ImagePropertiesRecordLib MdeModulePkg/ImagePropertiesRecordLib: Reduce debug level 2024-06-26 12:40:30 +00:00
LockBoxNullLib MdeModulePkg: Apply uncrustify changes 2021-12-07 17:24:28 +00:00
LzmaCustomDecompressLib MdeModulePkg: Replace include guards with #pragma once 2026-02-23 21:01:28 +00:00
NonDiscoverableDeviceRegistrationLib MdeModulePkg: Apply uncrustify changes 2021-12-07 17:24:28 +00:00
OemHookStatusCodeLibNull MdeModulePkg: Apply uncrustify changes 2021-12-07 17:24:28 +00:00
PciHostBridgeLibNull MdeModulePkg: Apply uncrustify changes 2021-12-07 17:24:28 +00:00
PeiCrc32GuidedSectionExtractLib MdeModulePkg: Apply uncrustify changes 2021-12-07 17:24:28 +00:00
PeiDebugLibDebugPpi MdeModulePkg/Library: Fix property typos 2026-01-26 08:44:12 +00:00
PeiDebugPrintHobLib MdeModulePkg: Apply uncrustify changes 2021-12-07 17:24:28 +00:00
PeiDxeDebugLibReportStatusCode MdeModulePkg/Library: Fix property typos 2026-01-26 08:44:12 +00:00
PeiIpmiLibIpmiPpi MdeModulePkg: Apply uncrustify changes 2021-12-07 17:24:28 +00:00
PeiPerformanceLib MdeModulePkg: Apply uncrustify changes 2021-12-07 17:24:28 +00:00
PeiReportStatusCodeLib MdeModulePkg/Library: Fix property typos 2026-01-26 08:44:12 +00:00
PeiResetSystemLib MdeModulePkg: Apply uncrustify changes 2021-12-07 17:24:28 +00:00
PiDxeS3BootScriptLib MdeModulePkg: Replace include guards with #pragma once 2026-02-23 21:01:28 +00:00
PiSmmCoreMemoryAllocationLib MdeModulePkg: Replace include guards with #pragma once 2026-02-23 21:01:28 +00:00
PiSmmCoreSmmServicesTableLib MdeModulePkg: Replace BSD License with BSD+Patent License 2019-04-09 10:58:08 -07:00
PlatformBootManagerLibNull MdeModulePkg: Apply uncrustify changes 2021-12-07 17:24:28 +00:00
PlatformHookLibSerialPortPpi MdeModulePkg: Replace BSD License with BSD+Patent License 2019-04-09 10:58:08 -07:00
PlatformVarCleanupLib MdeModulePkg: Replace include guards with #pragma once 2026-02-23 21:01:28 +00:00
ResetUtilityLib MdeModulePkg: Update code to be more C11 compliant by using __func__ 2023-04-10 14:19:57 +00:00
RuntimeDxeReportStatusCodeLib MdeModulePkg/Library: Fix property typos 2026-01-26 08:44:12 +00:00
RuntimeResetSystemLib MdeModulePkg/RuntimeResetSystemLib: Make global static 2024-07-12 02:03:12 +00:00
SmmCorePerformanceLib MdeModulePkg: Replace include guards with #pragma once 2026-02-23 21:01:28 +00:00
SmmCorePlatformHookLibNull MdeModulePkg: Apply uncrustify changes 2021-12-07 17:24:28 +00:00
SmmIpmiLibSmmIpmiProtocol MdeModulePkg: Apply uncrustify changes 2021-12-07 17:24:28 +00:00
SmmLockBoxLib MdeModulePkg: Replace include guards with #pragma once 2026-02-23 21:01:28 +00:00
SmmMemoryAllocationProfileLib MdeModulePkg: Apply uncrustify changes 2021-12-07 17:24:28 +00:00
SmmPerformanceLib MdeModulePkg: Replace include guards with #pragma once 2026-02-23 21:01:28 +00:00
SmmReportStatusCodeLib MdeModulePkg: Replace include guards with #pragma once 2026-02-23 21:01:28 +00:00
SmmSmiHandlerProfileLib MdeModulePkg: Replace include guards with #pragma once 2026-02-23 21:01:28 +00:00
TdxMeasurementLibNull MdeModulePkg: Move TdxMeasurementLib from UefiCpuPkg 2025-03-18 17:57:40 +00:00
TpmMeasurementLibNull MdeModulePkg/TpmMeasurementLibNull: Allow broader linking 2025-06-05 10:05:24 +08:00
TraceHubDebugSysTLib MdeModulePkg: Replace include guards with #pragma once 2026-02-23 21:01:28 +00:00
UefiBootManagerLib MdeModulePkg: Replace include guards with #pragma once 2026-02-23 21:01:28 +00:00
UefiHiiLib MdeModulePkg: Replace include guards with #pragma once 2026-02-23 21:01:28 +00:00
UefiHiiServicesLib MdeModulePkg: Remove DXE_SAL_DRIVER 2025-10-30 10:00:32 +00:00
UefiMemoryAllocationProfileLib MdeModulePkg: Apply uncrustify changes 2021-12-07 17:24:28 +00:00
UefiSortLib MdeModulePkg: Apply uncrustify formatting to relevant files. 2023-10-27 00:50:49 +00:00
VarCheckHiiLib MdeModulePkg: Replace include guards with #pragma once 2026-02-23 21:01:28 +00:00
VarCheckLib MdeModulePkg: Apply uncrustify changes 2021-12-07 17:24:28 +00:00
VarCheckPcdLib MdeModulePkg: Replace include guards with #pragma once 2026-02-23 21:01:28 +00:00
VarCheckPolicyLib MdeModulePkg: Replace include guards with #pragma once 2026-02-23 21:01:28 +00:00
VarCheckUefiLib MdeModulePkg/Library: Fix property typos 2026-01-26 08:44:12 +00:00
VariablePolicyHelperLib MdeModulePkg: Apply uncrustify changes 2021-12-07 17:24:28 +00:00
VariablePolicyLib MdeModulePkg: Correct spelling errors and typos 2025-07-04 09:41:47 +08:00