From 963162cab093fe5aad5aed59edfb0f9a33bc602f Mon Sep 17 00:00:00 2001 From: Michael Kubacki Date: Tue, 3 Feb 2026 14:16:31 -0500 Subject: [PATCH] PrmPkg: 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 --- PrmPkg/Application/PrmInfo/PrmInfo.h | 5 +---- PrmPkg/Include/Library/PrmContextBufferLib.h | 5 +---- PrmPkg/Include/Library/PrmModuleDiscoveryLib.h | 5 +---- PrmPkg/Include/Library/PrmPeCoffLib.h | 5 +---- PrmPkg/Include/Prm.h | 5 +---- PrmPkg/Include/PrmContextBuffer.h | 5 +---- PrmPkg/Include/PrmDataBuffer.h | 5 +---- PrmPkg/Include/PrmExportDescriptor.h | 4 +--- PrmPkg/Include/PrmMmio.h | 5 +---- PrmPkg/Include/PrmModule.h | 4 +--- PrmPkg/Include/PrmModuleImageContext.h | 5 +---- PrmPkg/Include/Protocol/PrmConfig.h | 5 +---- PrmPkg/Library/DxePrmModuleDiscoveryLib/PrmModuleDiscovery.h | 5 +---- PrmPkg/PrmLoaderDxe/PrmAcpiTable.h | 5 +---- .../PrmSampleContextBufferModule/Include/StaticData.h | 5 +---- PrmPkg/Samples/PrmSampleHardwareAccessModule/Hpet.h | 5 +---- 16 files changed, 16 insertions(+), 62 deletions(-) diff --git a/PrmPkg/Application/PrmInfo/PrmInfo.h b/PrmPkg/Application/PrmInfo/PrmInfo.h index 3813998e96..5f8cf9dc0e 100644 --- a/PrmPkg/Application/PrmInfo/PrmInfo.h +++ b/PrmPkg/Application/PrmInfo/PrmInfo.h @@ -6,8 +6,7 @@ **/ -#ifndef PRM_INFO_H_ -#define PRM_INFO_H_ +#pragma once #include #include @@ -45,5 +44,3 @@ typedef struct { #define ONE_MICROSECOND (1000) #define ONE_MILLISECOND (1000 * ONE_MICROSECOND) #define ONE_SECOND (1000 * ONE_MILLISECOND) - -#endif diff --git a/PrmPkg/Include/Library/PrmContextBufferLib.h b/PrmPkg/Include/Library/PrmContextBufferLib.h index 8416b6a6c2..59e2788491 100644 --- a/PrmPkg/Include/Library/PrmContextBufferLib.h +++ b/PrmPkg/Include/Library/PrmContextBufferLib.h @@ -7,8 +7,7 @@ **/ -#ifndef PRM_CONTEXT_BUFFER_LIB_H_ -#define PRM_CONTEXT_BUFFER_LIB_H_ +#pragma once #include #include @@ -95,5 +94,3 @@ GetContextBuffer ( IN CONST PRM_MODULE_CONTEXT_BUFFERS *PrmModuleContextBuffers OPTIONAL, OUT CONST PRM_CONTEXT_BUFFER **PrmContextBuffer ); - -#endif diff --git a/PrmPkg/Include/Library/PrmModuleDiscoveryLib.h b/PrmPkg/Include/Library/PrmModuleDiscoveryLib.h index 341b9b26a0..1a9a273aae 100644 --- a/PrmPkg/Include/Library/PrmModuleDiscoveryLib.h +++ b/PrmPkg/Include/Library/PrmModuleDiscoveryLib.h @@ -7,8 +7,7 @@ **/ -#ifndef PRM_MODULE_DISCOVERY_LIB_H_ -#define PRM_MODULE_DISCOVERY_LIB_H_ +#pragma once #include #include @@ -56,5 +55,3 @@ DiscoverPrmModules ( OUT UINTN *ModuleCount OPTIONAL, OUT UINTN *HandlerCount OPTIONAL ); - -#endif diff --git a/PrmPkg/Include/Library/PrmPeCoffLib.h b/PrmPkg/Include/Library/PrmPeCoffLib.h index a3cbeba007..57d857d812 100644 --- a/PrmPkg/Include/Library/PrmPeCoffLib.h +++ b/PrmPkg/Include/Library/PrmPeCoffLib.h @@ -8,8 +8,7 @@ **/ -#ifndef PRM_PECOFF_LIB_H_ -#define PRM_PECOFF_LIB_H_ +#pragma once #include #include @@ -107,5 +106,3 @@ GetExportEntryAddress ( IN EFI_IMAGE_EXPORT_DIRECTORY *ImageExportDirectory, OUT EFI_PHYSICAL_ADDRESS *ExportPhysicalAddress ); - -#endif diff --git a/PrmPkg/Include/Prm.h b/PrmPkg/Include/Prm.h index 563c7430ab..12fad99527 100644 --- a/PrmPkg/Include/Prm.h +++ b/PrmPkg/Include/Prm.h @@ -8,8 +8,7 @@ **/ -#ifndef PRM_H_ -#define PRM_H_ +#pragma once #include #include @@ -48,5 +47,3 @@ EFI_STATUS IN VOID *ParameterBuffer OPTIONAL, IN PRM_CONTEXT_BUFFER *ContextBuffer OPTIONAL ); - -#endif diff --git a/PrmPkg/Include/PrmContextBuffer.h b/PrmPkg/Include/PrmContextBuffer.h index 781910d67e..b8fd1239f5 100644 --- a/PrmPkg/Include/PrmContextBuffer.h +++ b/PrmPkg/Include/PrmContextBuffer.h @@ -7,8 +7,7 @@ **/ -#ifndef PRM_CONTEXT_BUFFER_H_ -#define PRM_CONTEXT_BUFFER_H_ +#pragma once #include #include @@ -167,5 +166,3 @@ typedef struct { } PRM_MODULE_CONTEXT_BUFFERS; #pragma pack(pop) - -#endif diff --git a/PrmPkg/Include/PrmDataBuffer.h b/PrmPkg/Include/PrmDataBuffer.h index 4613f57cae..6e70dbdd69 100644 --- a/PrmPkg/Include/PrmDataBuffer.h +++ b/PrmPkg/Include/PrmDataBuffer.h @@ -7,8 +7,7 @@ **/ -#ifndef PRM_DATA_BUFFER_H_ -#define PRM_DATA_BUFFER_H_ +#pragma once #include @@ -47,5 +46,3 @@ typedef struct { } PRM_DATA_BUFFER; #pragma pack(pop) - -#endif diff --git a/PrmPkg/Include/PrmExportDescriptor.h b/PrmPkg/Include/PrmExportDescriptor.h index 8131b5ade9..6cf979bcfe 100644 --- a/PrmPkg/Include/PrmExportDescriptor.h +++ b/PrmPkg/Include/PrmExportDescriptor.h @@ -7,8 +7,7 @@ **/ -#ifndef PRM_EXPORT_DESCRIPTOR_H_ -#define PRM_EXPORT_DESCRIPTOR_H_ +#pragma once #include @@ -106,4 +105,3 @@ typedef struct { { __VA_ARGS__ } \ } \ -#endif diff --git a/PrmPkg/Include/PrmMmio.h b/PrmPkg/Include/PrmMmio.h index 6aca19f912..2122a8caa8 100644 --- a/PrmPkg/Include/PrmMmio.h +++ b/PrmPkg/Include/PrmMmio.h @@ -7,8 +7,7 @@ **/ -#ifndef PRM_MMIO_H_ -#define PRM_MMIO_H_ +#pragma once #include @@ -41,5 +40,3 @@ typedef struct { } PRM_RUNTIME_MMIO_RANGES; #pragma pack(pop) - -#endif diff --git a/PrmPkg/Include/PrmModule.h b/PrmPkg/Include/PrmModule.h index 094f7d1226..290ebfb384 100644 --- a/PrmPkg/Include/PrmModule.h +++ b/PrmPkg/Include/PrmModule.h @@ -7,8 +7,7 @@ **/ -#ifndef PRM_MODULE_H_ -#define PRM_MODULE_H_ +#pragma once #include #include @@ -44,4 +43,3 @@ IN PRM_CONTEXT_BUFFER *ContextBuffer \ ) \ -#endif diff --git a/PrmPkg/Include/PrmModuleImageContext.h b/PrmPkg/Include/PrmModuleImageContext.h index 0e381442e1..fd2bff9b90 100644 --- a/PrmPkg/Include/PrmModuleImageContext.h +++ b/PrmPkg/Include/PrmModuleImageContext.h @@ -7,8 +7,7 @@ **/ -#ifndef PRM_MODULE_IMAGE_CONTEXT_H_ -#define PRM_MODULE_IMAGE_CONTEXT_H_ +#pragma once #include #include @@ -24,5 +23,3 @@ typedef struct { } PRM_MODULE_IMAGE_CONTEXT; #pragma pack(pop) - -#endif diff --git a/PrmPkg/Include/Protocol/PrmConfig.h b/PrmPkg/Include/Protocol/PrmConfig.h index 4cce6b3c2c..729cd1d578 100644 --- a/PrmPkg/Include/Protocol/PrmConfig.h +++ b/PrmPkg/Include/Protocol/PrmConfig.h @@ -11,8 +11,7 @@ **/ -#ifndef PRM_CONFIG_H_ -#define PRM_CONFIG_H_ +#pragma once #include #include @@ -27,5 +26,3 @@ struct _PRM_CONFIG_PROTOCOL { }; extern EFI_GUID gPrmConfigProtocolGuid; - -#endif diff --git a/PrmPkg/Library/DxePrmModuleDiscoveryLib/PrmModuleDiscovery.h b/PrmPkg/Library/DxePrmModuleDiscoveryLib/PrmModuleDiscovery.h index f6b8962605..227879fe00 100644 --- a/PrmPkg/Library/DxePrmModuleDiscoveryLib/PrmModuleDiscovery.h +++ b/PrmPkg/Library/DxePrmModuleDiscoveryLib/PrmModuleDiscovery.h @@ -7,8 +7,7 @@ **/ -#ifndef PRM_MODULE_DISCOVERY_H_ -#define PRM_MODULE_DISCOVERY_H_ +#pragma once #include @@ -35,5 +34,3 @@ PRM_MODULE_IMAGE_CONTEXT_LIST_ENTRY * CreateNewPrmModuleImageContextListEntry ( VOID ); - -#endif diff --git a/PrmPkg/PrmLoaderDxe/PrmAcpiTable.h b/PrmPkg/PrmLoaderDxe/PrmAcpiTable.h index e2034d4738..e4d336eb66 100644 --- a/PrmPkg/PrmLoaderDxe/PrmAcpiTable.h +++ b/PrmPkg/PrmLoaderDxe/PrmAcpiTable.h @@ -8,8 +8,7 @@ **/ -#ifndef PRMT_ACPI_TABLE_H_ -#define PRMT_ACPI_TABLE_H_ +#pragma once #include #include @@ -92,5 +91,3 @@ typedef struct { PhysicalAddress, /* UINT64 PhysicalAddress */ \ } \ } - -#endif // _PRMT_ACPI_TABLE_H_ diff --git a/PrmPkg/Samples/PrmSampleContextBufferModule/Include/StaticData.h b/PrmPkg/Samples/PrmSampleContextBufferModule/Include/StaticData.h index c3a5067c55..4fade3c364 100644 --- a/PrmPkg/Samples/PrmSampleContextBufferModule/Include/StaticData.h +++ b/PrmPkg/Samples/PrmSampleContextBufferModule/Include/StaticData.h @@ -8,8 +8,7 @@ **/ -#ifndef PRM_STATIC_DATA_SAMPLE_CONTEXT_BUFFER_MODULE_H_ -#define PRM_STATIC_DATA_SAMPLE_CONTEXT_BUFFER_MODULE_H_ +#pragma once #include @@ -20,5 +19,3 @@ typedef struct { BOOLEAN Policy2Enabled; UINT8 SomeValueArray[SOME_VALUE_ARRAY_MAX_VALUES]; } STATIC_DATA_SAMPLE_CONTEXT_BUFFER_MODULE; - -#endif diff --git a/PrmPkg/Samples/PrmSampleHardwareAccessModule/Hpet.h b/PrmPkg/Samples/PrmSampleHardwareAccessModule/Hpet.h index d7298859f6..16364e77a3 100644 --- a/PrmPkg/Samples/PrmSampleHardwareAccessModule/Hpet.h +++ b/PrmPkg/Samples/PrmSampleHardwareAccessModule/Hpet.h @@ -12,8 +12,7 @@ **/ -#ifndef HPET_REGISTER_H_ -#define HPET_REGISTER_H_ +#pragma once #define HPET_BASE_ADDRESS 0xFED00000 #define HPET_RANGE_LENGTH 0x1000 @@ -104,5 +103,3 @@ typedef union { } HPET_TIMER_MSI_ROUTE_REGISTER; #pragma pack() - -#endif