edk2/SecurityPkg/Library
Michael Kubacki 9326c0eb0a SecurityPkg: 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
..
AuthVariableLib SecurityPkg: Replace include guards with #pragma once 2026-02-23 21:01:28 +00:00
DxeImageAuthenticationStatusLib SecurityPkg: Apply uncrustify changes 2021-12-07 17:24:28 +00:00
DxeImageVerificationLib SecurityPkg: Replace include guards with #pragma once 2026-02-23 21:01:28 +00:00
DxeRsa2048Sha256GuidedSectionExtractLib SecurityPkg: Apply uncrustify changes 2021-12-07 17:24:28 +00:00
DxeTcg2PhysicalPresenceLib SecurityPkg: Replace VariableLock with VariablePolicy 2025-11-24 06:23:55 +00:00
DxeTcgPhysicalPresenceLib SecurityPkg: Replace VariableLock with VariablePolicy 2025-11-24 06:23:55 +00:00
DxeTpm2MeasureBootLib SecurityPkg: Replace include guards with #pragma once 2026-02-23 21:01:28 +00:00
DxeTpmMeasureBootLib SecurityPkg: Replace include guards with #pragma once 2026-02-23 21:01:28 +00:00
DxeTpmMeasurementLib SecurityPkg: Support CcMeasurementProtocol in DxeTpmMeasurementLib 2021-12-11 17:00:53 +00:00
FmpAuthenticationLibPkcs7 SecurityPkg: Apply uncrustify changes 2021-12-07 17:24:28 +00:00
FmpAuthenticationLibRsa2048Sha256 SecurityPkg: Apply uncrustify changes 2021-12-07 17:24:28 +00:00
HashInstanceLibSha1 Revert "SecurityPkg: CodeQL Fixes." 2025-08-12 03:50:30 +00:00
HashInstanceLibSha256 Revert "SecurityPkg: CodeQL Fixes." 2025-08-12 03:50:30 +00:00
HashInstanceLibSha384 SecurityPkg: Apply uncrustify changes 2021-12-07 17:24:28 +00:00
HashInstanceLibSha512 SecurityPkg: Apply uncrustify changes 2021-12-07 17:24:28 +00:00
HashInstanceLibSm3 SecurityPkg: Apply uncrustify changes 2021-12-07 17:24:28 +00:00
HashLibBaseCryptoRouter SecurityPkg: Replace include guards with #pragma once 2026-02-23 21:01:28 +00:00
HashLibTpm2 SecurityPkg/HashLibTpm2: Fix unused variable usage 2025-11-29 18:21:50 +01:00
PeiDxeTpmPlatformHierarchyLib SecurityPkg: Update code to be more C11 compliant by using __func__ 2023-04-10 14:19:57 +00:00
PeiDxeTpmPlatformHierarchyLibNull ArmVirtPkg/TPM: Add a NULL implementation of TpmPlatformHierarchyLib 2021-10-05 09:54:11 +00:00
PeilessSecMeasureLib SecurityPkg: rename PeilessSecMeasureNullLib 2025-10-02 15:42:07 +01:00
PeiRsa2048Sha256GuidedSectionExtractLib SecurityPkg: Apply uncrustify changes 2021-12-07 17:24:28 +00:00
PeiTcg2PhysicalPresenceLib SecurityPkg: Apply uncrustify changes 2021-12-07 17:24:28 +00:00
PeiTpmMeasurementLib SecurityPkg/PeiTpmMeasurementLib: Support CC Measurement 2024-12-10 02:09:29 +00:00
PlatformPKProtectionLibVarPolicy SecurityPkg: Update code to be more C11 compliant by using __func__ 2023-04-10 14:19:57 +00:00
PlatformSecureLibNull SecurityPkg: Apply uncrustify changes 2021-12-07 17:24:28 +00:00
SecTpmMeasurementLib SecurityPkg/SecTpmMeasurementLib: Fix OverFlow Coverity issue 2025-07-02 07:41:33 +00:00
SecureBootVariableLib SecurityPkg/Library/SecureBootVariableLib/UnitTest: Cmocka use issues 2026-01-21 09:15:06 +00:00
SecureBootVariableProvisionLib Revert "SecurityPkg: CodeQL Fixes." 2025-08-12 03:50:30 +00:00
SmmTcg2PhysicalPresenceLib SecurityPkg: Replace include guards with #pragma once 2026-02-23 21:01:28 +00:00
Tcg2PpVendorLibNull SecurityPkg: Apply uncrustify changes 2021-12-07 17:24:28 +00:00
TcgEventLogRecordLib Revert "SecurityPkg: CodeQL Fixes." 2025-08-12 03:50:30 +00:00
TcgPpVendorLibNull SecurityPkg: Apply uncrustify changes 2021-12-07 17:24:28 +00:00
TcgStorageCoreLib SecurityPkg: Apply uncrustify changes 2021-12-07 17:24:28 +00:00
TcgStorageOpalLib SecurityPkg: Replace include guards with #pragma once 2026-02-23 21:01:28 +00:00
Tpm2CommandLib SecurityPkg: Remove unused variable 2025-11-22 01:43:26 +00:00
Tpm2DeviceLibDTpm SecurityPkg: Replace include guards with #pragma once 2026-02-23 21:01:28 +00:00
Tpm2DeviceLibFfa SecurityPkg: Replace include guards with #pragma once 2026-02-23 21:01:28 +00:00
Tpm2DeviceLibRouter SecurityPkg: Apply uncrustify changes 2021-12-07 17:24:28 +00:00
Tpm2DeviceLibTcg2 SecurityPkg/Tpm2DeviceLibTcg2: Make mTcg2Protocol static 2023-08-30 00:05:52 +00:00
Tpm12CommandLib SecurityPkg: Apply uncrustify changes 2021-12-07 17:24:28 +00:00
Tpm12DeviceLibDTpm Revert "SecurityPkg: CodeQL Fixes." 2025-08-12 03:50:30 +00:00
Tpm12DeviceLibTcg SecurityPkg: Apply uncrustify changes 2021-12-07 17:24:28 +00:00
TpmCommLib SecurityPkg: Replace include guards with #pragma once 2026-02-23 21:01:28 +00:00