From 86047d47423134a74cad7da53c8dbc06fccb0f20 Mon Sep 17 00:00:00 2001 From: Michael Kubacki Date: Tue, 3 Feb 2026 13:35:59 -0500 Subject: [PATCH] IntelFsp2Pkg: 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 --- IntelFsp2Pkg/FspNotifyPhase/FspNotifyPhasePeim.h | 4 +--- IntelFsp2Pkg/FspSecCore/SecFsp.h | 5 +---- IntelFsp2Pkg/FspSecCore/SecMain.h | 5 +---- IntelFsp2Pkg/Include/FspEas.h | 5 +---- IntelFsp2Pkg/Include/FspEas/FspApi.h | 5 +---- IntelFsp2Pkg/Include/FspGlobalData.h | 5 +---- IntelFsp2Pkg/Include/FspMeasurePointId.h | 5 +---- IntelFsp2Pkg/Include/FspStatusCode.h | 5 +---- IntelFsp2Pkg/Include/Guid/FspNonVolatileStorageHob2.h | 5 +---- IntelFsp2Pkg/Include/Guid/GuidHobFspEas.h | 5 +---- IntelFsp2Pkg/Include/Library/CacheAsRamLib.h | 5 +---- IntelFsp2Pkg/Include/Library/CacheLib.h | 5 +---- IntelFsp2Pkg/Include/Library/DebugDeviceLib.h | 5 +---- IntelFsp2Pkg/Include/Library/FspCommonLib.h | 5 +---- IntelFsp2Pkg/Include/Library/FspMultiPhaseLib.h | 5 +---- IntelFsp2Pkg/Include/Library/FspPlatformLib.h | 5 +---- IntelFsp2Pkg/Include/Library/FspSecPlatformLib.h | 5 +---- IntelFsp2Pkg/Include/Library/FspSwitchStackLib.h | 5 +---- IntelFsp2Pkg/Include/Ppi/FspiArchConfigPpi.h | 5 +---- IntelFsp2Pkg/Include/Ppi/FspmArchConfigPpi.h | 5 +---- IntelFsp2Pkg/Include/Ppi/TempRamExitPpi.h | 5 +---- IntelFsp2Pkg/Include/Ppi/Variable.h | 5 +---- IntelFsp2Pkg/Library/BaseCacheLib/CacheLibInternal.h | 5 +---- IntelFsp2Pkg/Tools/Tests/ExpectedFspUpd.h | 5 +---- IntelFsp2Pkg/Tools/Tests/ExpectedFspmUpd.h | 5 +---- IntelFsp2Pkg/Tools/Tests/ExpectedFspsUpd.h | 5 +---- IntelFsp2Pkg/Tools/Tests/ExpectedFsptUpd.h | 5 +---- 27 files changed, 27 insertions(+), 107 deletions(-) diff --git a/IntelFsp2Pkg/FspNotifyPhase/FspNotifyPhasePeim.h b/IntelFsp2Pkg/FspNotifyPhase/FspNotifyPhasePeim.h index 0b4dd8bb6d..3d4fd37524 100644 --- a/IntelFsp2Pkg/FspNotifyPhase/FspNotifyPhasePeim.h +++ b/IntelFsp2Pkg/FspNotifyPhase/FspNotifyPhasePeim.h @@ -5,8 +5,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent **/ -#ifndef _FSP_NOTIFY_PHASE_PEIM_H_ -#define _FSP_NOTIFY_PHASE_PEIM_H_ +#pragma once #include #include @@ -14,4 +13,3 @@ #include #include #include -#endif diff --git a/IntelFsp2Pkg/FspSecCore/SecFsp.h b/IntelFsp2Pkg/FspSecCore/SecFsp.h index c05b46c750..acb59f9005 100644 --- a/IntelFsp2Pkg/FspSecCore/SecFsp.h +++ b/IntelFsp2Pkg/FspSecCore/SecFsp.h @@ -5,8 +5,7 @@ **/ -#ifndef _SEC_FSP_H_ -#define _SEC_FSP_H_ +#pragma once #include #include @@ -88,5 +87,3 @@ EFIAPI AsmGetFspInfoHeader ( VOID ); - -#endif diff --git a/IntelFsp2Pkg/FspSecCore/SecMain.h b/IntelFsp2Pkg/FspSecCore/SecMain.h index eb1458d197..09d7832ed5 100644 --- a/IntelFsp2Pkg/FspSecCore/SecMain.h +++ b/IntelFsp2Pkg/FspSecCore/SecMain.h @@ -5,8 +5,7 @@ **/ -#ifndef _SEC_CORE_H_ -#define _SEC_CORE_H_ +#pragma once #include #include @@ -122,5 +121,3 @@ EFIAPI AsmReadStackPointer ( VOID ); - -#endif diff --git a/IntelFsp2Pkg/Include/FspEas.h b/IntelFsp2Pkg/Include/FspEas.h index b6dff07547..5c35083f8e 100644 --- a/IntelFsp2Pkg/Include/FspEas.h +++ b/IntelFsp2Pkg/Include/FspEas.h @@ -7,12 +7,9 @@ **/ -#ifndef _FSP_EAS_H_ -#define _FSP_EAS_H_ +#pragma once #include #include #include #include - -#endif diff --git a/IntelFsp2Pkg/Include/FspEas/FspApi.h b/IntelFsp2Pkg/Include/FspEas/FspApi.h index e07aa401e6..66df0d2635 100644 --- a/IntelFsp2Pkg/Include/FspEas/FspApi.h +++ b/IntelFsp2Pkg/Include/FspEas/FspApi.h @@ -7,8 +7,7 @@ **/ -#ifndef _FSP_API_H_ -#define _FSP_API_H_ +#pragma once #include #include @@ -755,5 +754,3 @@ EFI_STATUS (EFIAPI *FSP_MULTI_PHASE_INIT)( IN FSP_MULTI_PHASE_PARAMS *MultiPhaseInitParamPtr ); - -#endif diff --git a/IntelFsp2Pkg/Include/FspGlobalData.h b/IntelFsp2Pkg/Include/FspGlobalData.h index 81813df3ce..39591ccfe4 100644 --- a/IntelFsp2Pkg/Include/FspGlobalData.h +++ b/IntelFsp2Pkg/Include/FspGlobalData.h @@ -5,8 +5,7 @@ **/ -#ifndef _FSP_GLOBAL_DATA_H_ -#define _FSP_GLOBAL_DATA_H_ +#pragma once #include @@ -100,5 +99,3 @@ typedef struct { } FSP_GLOBAL_DATA; #pragma pack() - -#endif diff --git a/IntelFsp2Pkg/Include/FspMeasurePointId.h b/IntelFsp2Pkg/Include/FspMeasurePointId.h index 00dabca243..7b77342f05 100644 --- a/IntelFsp2Pkg/Include/FspMeasurePointId.h +++ b/IntelFsp2Pkg/Include/FspMeasurePointId.h @@ -5,8 +5,7 @@ **/ -#ifndef _FSP_MEASURE_POINT_ID_H_ -#define _FSP_MEASURE_POINT_ID_H_ +#pragma once // // 0xD0 - 0xEF are reserved for FSP common measure point @@ -52,5 +51,3 @@ #define FSP_PERF_ID_API_NOTIFY_END_OF_FIRMWARE_ENTRY 0xFC #define FSP_PERF_ID_API_NOTIFY_END_OF_FIRMWARE_EXIT (FSP_PERF_ID_API_NOTIFY_END_OF_FIRMWARE_ENTRY + 1) - -#endif diff --git a/IntelFsp2Pkg/Include/FspStatusCode.h b/IntelFsp2Pkg/Include/FspStatusCode.h index c7afff5cf9..043624c968 100644 --- a/IntelFsp2Pkg/Include/FspStatusCode.h +++ b/IntelFsp2Pkg/Include/FspStatusCode.h @@ -6,8 +6,7 @@ **/ -#ifndef _FSP_STATUS_CODE_H_ -#define _FSP_STATUS_CODE_H_ +#pragma once // // FSP API - 4 BITS @@ -37,5 +36,3 @@ // #define FSP_STATUS_CODE_API_ENTRY 0x0000 #define FSP_STATUS_CODE_API_EXIT 0x007F - -#endif diff --git a/IntelFsp2Pkg/Include/Guid/FspNonVolatileStorageHob2.h b/IntelFsp2Pkg/Include/Guid/FspNonVolatileStorageHob2.h index 71748a13d4..24cc1fe8aa 100644 --- a/IntelFsp2Pkg/Include/Guid/FspNonVolatileStorageHob2.h +++ b/IntelFsp2Pkg/Include/Guid/FspNonVolatileStorageHob2.h @@ -7,8 +7,7 @@ **/ -#ifndef __FSP_NON_VOLATILE_STORAGE_HOB2_H__ -#define __FSP_NON_VOLATILE_STORAGE_HOB2_H__ +#pragma once /// /// The Non-Volatile Storage (NVS) HOB version 2 provides > 64KB buffer support. @@ -20,5 +19,3 @@ typedef struct { } FSP_NON_VOLATILE_STORAGE_HOB2; extern EFI_GUID gFspNonVolatileStorageHob2Guid; - -#endif diff --git a/IntelFsp2Pkg/Include/Guid/GuidHobFspEas.h b/IntelFsp2Pkg/Include/Guid/GuidHobFspEas.h index 150d6b842a..fd305e1bfa 100644 --- a/IntelFsp2Pkg/Include/Guid/GuidHobFspEas.h +++ b/IntelFsp2Pkg/Include/Guid/GuidHobFspEas.h @@ -7,11 +7,8 @@ **/ -#ifndef __GUID_HOB_FSP_EAS_GUID__ -#define __GUID_HOB_FSP_EAS_GUID__ +#pragma once extern EFI_GUID gFspBootLoaderTolumHobGuid; extern EFI_GUID gFspReservedMemoryResourceHobGuid; extern EFI_GUID gFspNonVolatileStorageHobGuid; - -#endif diff --git a/IntelFsp2Pkg/Include/Library/CacheAsRamLib.h b/IntelFsp2Pkg/Include/Library/CacheAsRamLib.h index e9de86717d..56c9be1c9b 100644 --- a/IntelFsp2Pkg/Include/Library/CacheAsRamLib.h +++ b/IntelFsp2Pkg/Include/Library/CacheAsRamLib.h @@ -5,8 +5,7 @@ **/ -#ifndef _CACHE_AS_RAM_LIB_H_ -#define _CACHE_AS_RAM_LIB_H_ +#pragma once /** This function disable CAR. @@ -19,5 +18,3 @@ EFIAPI DisableCacheAsRam ( IN BOOLEAN DisableCar ); - -#endif diff --git a/IntelFsp2Pkg/Include/Library/CacheLib.h b/IntelFsp2Pkg/Include/Library/CacheLib.h index 82b6d5d323..dcc7516d7b 100644 --- a/IntelFsp2Pkg/Include/Library/CacheLib.h +++ b/IntelFsp2Pkg/Include/Library/CacheLib.h @@ -5,8 +5,7 @@ **/ -#ifndef _CACHE_LIB_H_ -#define _CACHE_LIB_H_ +#pragma once // // EFI_MEMORY_CACHE_TYPE @@ -51,5 +50,3 @@ SetCacheAttributes ( IN UINT64 MemoryLength, IN EFI_MEMORY_CACHE_TYPE MemoryCacheType ); - -#endif diff --git a/IntelFsp2Pkg/Include/Library/DebugDeviceLib.h b/IntelFsp2Pkg/Include/Library/DebugDeviceLib.h index bd0b696773..1fa265ec10 100644 --- a/IntelFsp2Pkg/Include/Library/DebugDeviceLib.h +++ b/IntelFsp2Pkg/Include/Library/DebugDeviceLib.h @@ -5,8 +5,7 @@ **/ -#ifndef __DEBUG_DEVICE_LIB_H__ -#define __DEBUG_DEVICE_LIB_H__ +#pragma once /** Returns the debug print device enable state. @@ -19,5 +18,3 @@ EFIAPI GetDebugPrintDeviceEnable ( VOID ); - -#endif diff --git a/IntelFsp2Pkg/Include/Library/FspCommonLib.h b/IntelFsp2Pkg/Include/Library/FspCommonLib.h index d5bbaa69dd..60d428cd08 100644 --- a/IntelFsp2Pkg/Include/Library/FspCommonLib.h +++ b/IntelFsp2Pkg/Include/Library/FspCommonLib.h @@ -5,8 +5,7 @@ **/ -#ifndef _FSP_COMMON_LIB_H_ -#define _FSP_COMMON_LIB_H_ +#pragma once #include #include @@ -314,5 +313,3 @@ EFIAPI FspApiReturnStatusReset ( IN EFI_STATUS FspResetType ); - -#endif diff --git a/IntelFsp2Pkg/Include/Library/FspMultiPhaseLib.h b/IntelFsp2Pkg/Include/Library/FspMultiPhaseLib.h index 9c6973ceb1..e8298dbeaa 100644 --- a/IntelFsp2Pkg/Include/Library/FspMultiPhaseLib.h +++ b/IntelFsp2Pkg/Include/Library/FspMultiPhaseLib.h @@ -6,8 +6,7 @@ **/ -#ifndef _FSP_MULTIPHASE_LIB_H_ -#define _FSP_MULTIPHASE_LIB_H_ +#pragma once EFI_STATUS EFIAPI @@ -51,5 +50,3 @@ FspMultiPhaseSiInitApiHandlerV2 ( IN UINT32 ApiIdx, IN VOID *ApiParam ); - -#endif diff --git a/IntelFsp2Pkg/Include/Library/FspPlatformLib.h b/IntelFsp2Pkg/Include/Library/FspPlatformLib.h index 9a8079c0f2..73a60905ae 100644 --- a/IntelFsp2Pkg/Include/Library/FspPlatformLib.h +++ b/IntelFsp2Pkg/Include/Library/FspPlatformLib.h @@ -5,8 +5,7 @@ **/ -#ifndef _FSP_PLATFORM_LIB_H_ -#define _FSP_PLATFORM_LIB_H_ +#pragma once /** Get system memory resource descriptor by owner. @@ -133,5 +132,3 @@ ReadTemporaryRamSize ( IN UINT32 TemporaryRamBase, OUT UINT32 *TemporaryRamSize ); - -#endif diff --git a/IntelFsp2Pkg/Include/Library/FspSecPlatformLib.h b/IntelFsp2Pkg/Include/Library/FspSecPlatformLib.h index 675b3ab02f..f8848aa7bb 100644 --- a/IntelFsp2Pkg/Include/Library/FspSecPlatformLib.h +++ b/IntelFsp2Pkg/Include/Library/FspSecPlatformLib.h @@ -5,8 +5,7 @@ **/ -#ifndef _FSP_SEC_PLATFORM_LIB_H_ -#define _FSP_SEC_PLATFORM_LIB_H_ +#pragma once /** This function performs platform level initialization. @@ -115,5 +114,3 @@ FspMultiPhasePlatformGetNumberOfPhases ( IN UINT32 ApiIdx, IN OUT UINT32 *NumberOfPhasesSupported ); - -#endif diff --git a/IntelFsp2Pkg/Include/Library/FspSwitchStackLib.h b/IntelFsp2Pkg/Include/Library/FspSwitchStackLib.h index ff66e48ae2..184e681980 100644 --- a/IntelFsp2Pkg/Include/Library/FspSwitchStackLib.h +++ b/IntelFsp2Pkg/Include/Library/FspSwitchStackLib.h @@ -5,8 +5,7 @@ **/ -#ifndef _FSP_SWITCH_STACK_LIB_H_ -#define _FSP_SWITCH_STACK_LIB_H_ +#pragma once /** @@ -51,5 +50,3 @@ EFIAPI Loader2PeiSwitchStack ( VOID ); - -#endif diff --git a/IntelFsp2Pkg/Include/Ppi/FspiArchConfigPpi.h b/IntelFsp2Pkg/Include/Ppi/FspiArchConfigPpi.h index 7f2d4a817d..1bf1b49ddf 100644 --- a/IntelFsp2Pkg/Include/Ppi/FspiArchConfigPpi.h +++ b/IntelFsp2Pkg/Include/Ppi/FspiArchConfigPpi.h @@ -7,8 +7,7 @@ **/ -#ifndef _FSPI_ARCH_CONFIG_PPI_H_ -#define _FSPI_ARCH_CONFIG_PPI_H_ +#pragma once #define FSPI_ARCH_CONFIG_PPI_REVISION 0x1 @@ -50,5 +49,3 @@ typedef struct { } FSPI_ARCH_CONFIG_PPI; extern EFI_GUID gFspiArchConfigPpiGuid; - -#endif // _FSPI_ARCH_CONFIG_PPI_H_ diff --git a/IntelFsp2Pkg/Include/Ppi/FspmArchConfigPpi.h b/IntelFsp2Pkg/Include/Ppi/FspmArchConfigPpi.h index 2559627c65..6c3e5b7ff8 100644 --- a/IntelFsp2Pkg/Include/Ppi/FspmArchConfigPpi.h +++ b/IntelFsp2Pkg/Include/Ppi/FspmArchConfigPpi.h @@ -7,8 +7,7 @@ **/ -#ifndef _FSPM_ARCH_CONFIG_PPI_H_ -#define _FSPM_ARCH_CONFIG_PPI_H_ +#pragma once #define FSPM_ARCH_CONFIG_PPI_REVISION 0x1 @@ -43,5 +42,3 @@ typedef struct { } FSPM_ARCH_CONFIG_PPI; extern EFI_GUID gFspmArchConfigPpiGuid; - -#endif // _FSPM_ARCH_CONFIG_PPI_H_ diff --git a/IntelFsp2Pkg/Include/Ppi/TempRamExitPpi.h b/IntelFsp2Pkg/Include/Ppi/TempRamExitPpi.h index b497e33c5b..36b9fec458 100644 --- a/IntelFsp2Pkg/Include/Ppi/TempRamExitPpi.h +++ b/IntelFsp2Pkg/Include/Ppi/TempRamExitPpi.h @@ -7,8 +7,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent **/ -#ifndef _FSP_TEMP_RAM_EXIT_PPI_H_ -#define _FSP_TEMP_RAM_EXIT_PPI_H_ +#pragma once /// /// Global ID for the FSP_TEMP_RAM_EXIT_PPI. @@ -48,5 +47,3 @@ struct _FSP_TEMP_RAM_EXIT_PPI { }; extern EFI_GUID gFspTempRamExitPpiGuid; - -#endif // _FSP_TEMP_RAM_EXIT_PPI_H_ diff --git a/IntelFsp2Pkg/Include/Ppi/Variable.h b/IntelFsp2Pkg/Include/Ppi/Variable.h index 581f148808..85df7fd053 100644 --- a/IntelFsp2Pkg/Include/Ppi/Variable.h +++ b/IntelFsp2Pkg/Include/Ppi/Variable.h @@ -7,8 +7,7 @@ **/ -#ifndef EDKII_PEI_VARIABLE_PPI_H_ -#define EDKII_PEI_VARIABLE_PPI_H_ +#pragma once #define EDKII_PEI_VARIABLE_PPI_GUID \ { \ @@ -191,5 +190,3 @@ struct _EDKII_PEI_VARIABLE_PPI { }; extern EFI_GUID gEdkiiPeiVariablePpiGuid; - -#endif diff --git a/IntelFsp2Pkg/Library/BaseCacheLib/CacheLibInternal.h b/IntelFsp2Pkg/Library/BaseCacheLib/CacheLibInternal.h index 7dcf7fef24..a37bdbab0b 100644 --- a/IntelFsp2Pkg/Library/BaseCacheLib/CacheLibInternal.h +++ b/IntelFsp2Pkg/Library/BaseCacheLib/CacheLibInternal.h @@ -5,8 +5,7 @@ **/ -#ifndef _CACHE_LIB_INTERNAL_H_ -#define _CACHE_LIB_INTERNAL_H_ +#pragma once #define EFI_MSR_CACHE_VARIABLE_MTRR_BASE 0x00000200 #define EFI_MSR_CACHE_VARIABLE_MTRR_END 0x0000020F @@ -48,5 +47,3 @@ #define CPUID_VIR_PHY_ADDRESS_SIZE 0x80000008 #define CPUID_EXTENDED_FUNCTION 0x80000000 - -#endif diff --git a/IntelFsp2Pkg/Tools/Tests/ExpectedFspUpd.h b/IntelFsp2Pkg/Tools/Tests/ExpectedFspUpd.h index 10bb0c60f3..bed0867f97 100644 --- a/IntelFsp2Pkg/Tools/Tests/ExpectedFspUpd.h +++ b/IntelFsp2Pkg/Tools/Tests/ExpectedFspUpd.h @@ -1,5 +1,4 @@ -#ifndef __FSPUPD_H__ -#define __FSPUPD_H__ +#pragma once #include @@ -12,5 +11,3 @@ #define FSPS_UPD_SIGNATURE 0x535F4450554D4551 /* 'QEMUPD_S' */ #pragma pack() - -#endif diff --git a/IntelFsp2Pkg/Tools/Tests/ExpectedFspmUpd.h b/IntelFsp2Pkg/Tools/Tests/ExpectedFspmUpd.h index 0000ea7e60..7c1798941d 100644 --- a/IntelFsp2Pkg/Tools/Tests/ExpectedFspmUpd.h +++ b/IntelFsp2Pkg/Tools/Tests/ExpectedFspmUpd.h @@ -1,5 +1,4 @@ -#ifndef __FSPMUPD_H__ -#define __FSPMUPD_H__ +#pragma once #include @@ -68,5 +67,3 @@ typedef struct { } FSPM_UPD; #pragma pack() - -#endif diff --git a/IntelFsp2Pkg/Tools/Tests/ExpectedFspsUpd.h b/IntelFsp2Pkg/Tools/Tests/ExpectedFspsUpd.h index 5ada5c910a..c496ae3e34 100644 --- a/IntelFsp2Pkg/Tools/Tests/ExpectedFspsUpd.h +++ b/IntelFsp2Pkg/Tools/Tests/ExpectedFspsUpd.h @@ -1,5 +1,4 @@ -#ifndef __FSPSUPD_H__ -#define __FSPSUPD_H__ +#pragma once #include @@ -62,5 +61,3 @@ typedef struct { } FSPS_UPD; #pragma pack() - -#endif diff --git a/IntelFsp2Pkg/Tools/Tests/ExpectedFsptUpd.h b/IntelFsp2Pkg/Tools/Tests/ExpectedFsptUpd.h index 48310b4fc1..1aa1321a1b 100644 --- a/IntelFsp2Pkg/Tools/Tests/ExpectedFsptUpd.h +++ b/IntelFsp2Pkg/Tools/Tests/ExpectedFsptUpd.h @@ -1,5 +1,4 @@ -#ifndef __FSPTUPD_H__ -#define __FSPTUPD_H__ +#pragma once #include @@ -79,5 +78,3 @@ typedef struct { } FSPT_UPD; #pragma pack() - -#endif