UefiPayloadPkg: 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>
This commit is contained in:
Michael Kubacki 2026-02-03 14:34:16 -05:00 committed by mergify[bot]
parent 2ff7f990d1
commit f3c45d2f0c
47 changed files with 49 additions and 184 deletions

View file

@ -6,8 +6,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#ifndef __DXE_BOOTLOADER_SUPPORT_H__
#define __DXE_BOOTLOADER_SUPPORT_H__
#pragma once
#include <PiDxe.h>
@ -29,5 +28,3 @@ BlArchAdditionalOps (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
);
#endif

View file

@ -6,8 +6,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#ifndef BL_SUPPORT_SMM_H_
#define BL_SUPPORT_SMM_H_
#pragma once
#include <PiDxe.h>
#include <Library/BaseLib.h>
@ -37,5 +36,3 @@ typedef struct {
UINT32 Base;
UINT32 Mask;
} SMRR_BASE_MASK;
#endif

View file

@ -6,8 +6,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#ifndef FW_BLOCK_SERVICE_H_
#define FW_BLOCK_SERVICE_H_
#pragma once
#include <Guid/EventGroup.h>
#include <Guid/FirmwareFileSystem2.h>
@ -181,5 +180,3 @@ extern FWB_GLOBAL mFvbModuleGlobal;
extern EFI_FW_VOL_BLOCK_DEVICE mFvbDeviceTemplate;
extern FV_MEMMAP_DEVICE_PATH mFvMemmapDevicePathTemplate;
extern FV_PIWG_DEVICE_PATH mFvPIWGDevicePathTemplate;
#endif

View file

@ -6,8 +6,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#ifndef SMM_FVB_COMMON_H_
#define SMM_FVB_COMMON_H_
#pragma once
#include <Protocol/SmmFirmwareVolumeBlock.h>
@ -64,5 +63,3 @@ typedef struct {
EFI_LBA StartLba;
UINTN NumOfLba;
} SMM_FVB_BLOCKS_HEADER;
#endif

View file

@ -7,8 +7,8 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#ifndef _GRAPHICS_OUTPUT_DXE_H_
#define _GRAPHICS_OUTPUT_DXE_H_
#pragma once
#include <PiDxe.h>
#include <IndustryStandard/Pci.h>
@ -51,4 +51,3 @@ typedef struct {
extern EFI_COMPONENT_NAME_PROTOCOL mGraphicsOutputComponentName;
extern EFI_COMPONENT_NAME2_PROTOCOL mGraphicsOutputComponentName2;
#endif

View file

@ -6,8 +6,7 @@
**/
#ifndef ACPI_BOARD_INFO_GUID_H_
#define ACPI_BOARD_INFO_GUID_H_
#pragma once
///
/// Board information GUID
@ -26,5 +25,3 @@ typedef struct {
UINT64 PcieBaseAddress;
UINT64 PcieBaseSize;
} ACPI_BOARD_INFO;
#endif

View file

@ -6,8 +6,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#ifndef UNIVERSAL_PAYLOAD_BOOT_MANAGER_MENU_H_
#define UNIVERSAL_PAYLOAD_BOOT_MANAGER_MENU_H_
#pragma once
#include <Uefi.h>
#include <UniversalPayload/UniversalPayload.h>
@ -24,4 +23,3 @@ typedef struct {
#define UNIVERSAL_PAYLOAD_BOOT_MANAGER_MENU_REVISION 1
extern GUID gEdkiiBootManagerMenuFileGuid;
#endif

View file

@ -6,8 +6,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#ifndef UEFI_PAYLOAD_DEBUG_PRINT_ERROR_LEVEL_H_
#define UEFI_PAYLOAD_DEBUG_PRINT_ERROR_LEVEL_H_
#pragma once
#include <Uefi.h>
#include <UniversalPayload/UniversalPayload.h>
@ -28,4 +27,3 @@ typedef struct {
#define UEFI_PAYLOAD_DEBUG_PRINT_ERROR_LEVEL_REVISION 1
extern GUID gEdkiiDebugPrintErrorLevelGuid;
#endif

View file

@ -7,8 +7,7 @@
**/
#ifndef FIRMWARE_INFO_GUID_H_
#define FIRMWARE_INFO_GUID_H_
#pragma once
///
/// Firmware information GUID
@ -22,5 +21,3 @@ typedef struct {
UINT32 LowestSupportedVersion;
UINT32 ImageSize;
} FIRMWARE_INFO;
#endif // FIRMWARE_INFO_GUID_H_

View file

@ -6,8 +6,7 @@
**/
#ifndef MEMORY_MAP_INFO_GUID_H_
#define MEMORY_MAP_INFO_GUID_H_
#pragma once
#include <Library/PcdLib.h>
@ -32,5 +31,3 @@ typedef struct {
MEMORY_MAP_ENTRY Entry[0];
} MEMORY_MAP_INFO;
#pragma pack()
#endif

View file

@ -6,8 +6,7 @@
**/
#ifndef NV_VARIABLE_INFO_GUID_H_
#define NV_VARIABLE_INFO_GUID_H_
#pragma once
//
// NV variable hob info GUID
@ -20,5 +19,3 @@ typedef struct {
UINT32 VariableStoreBase;
UINT32 VariableStoreSize;
} NV_VARIABLE_INFO;
#endif

View file

@ -6,8 +6,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#ifndef PAYLOAD_COMMAND_LINE_H_
#define PAYLOAD_COMMAND_LINE_H_
#pragma once
#include <Uefi.h>
#include <UniversalPayload/UniversalPayload.h>
@ -25,4 +24,3 @@ typedef struct {
#define UNIVERSAL_PAYLOAD_COMMAND_LINE_REVISION 1
extern GUID gEdkiiPayloadCommandLineGuid;
#endif

View file

@ -6,8 +6,7 @@
**/
#ifndef UPL_PCI_SEGMENT_INFO_GUID_H_
#define UPL_PCI_SEGMENT_INFO_GUID_H_
#pragma once
///
/// UPL Pcie Segment Information Hob GUID
@ -28,5 +27,3 @@ typedef struct {
#pragma pack()
#define UNIVERSAL_PAYLOAD_PCI_SEGMENT_INFO_REVISION 1
#endif

View file

@ -6,8 +6,7 @@
**/
#ifndef SERIAL_PORT_INFO_GUID_H_
#define SERIAL_PORT_INFO_GUID_H_
#pragma once
///
/// Serial Port Information GUID
@ -27,5 +26,3 @@ typedef struct {
UINT32 InputHertz;
UINT32 UartPciAddr;
} SERIAL_PORT_INFO;
#endif

View file

@ -6,8 +6,7 @@
**/
#ifndef PAYLOAD_SMM_REGISTER_INFO_GUID_H_
#define PAYLOAD_SMM_REGISTER_INFO_GUID_H_
#pragma once
#include <IndustryStandard/Acpi.h>
@ -43,5 +42,3 @@ typedef struct {
} PLD_SMM_REGISTERS;
#pragma pack()
#endif

View file

@ -6,8 +6,7 @@
**/
#ifndef PAYLOAD_S3_COMMUNICATION_GUID_H_
#define PAYLOAD_S3_COMMUNICATION_GUID_H_
#pragma once
extern EFI_GUID gS3CommunicationGuid;
@ -50,5 +49,3 @@ typedef struct {
} PLD_TO_BL_SMM_INFO;
#pragma pack()
#endif

View file

@ -6,8 +6,7 @@
**/
#ifndef SMMSTORE_GUID_H_
#define SMMSTORE_GUID_H_
#pragma once
///
/// System Table Information GUID
@ -22,5 +21,3 @@ typedef struct {
UINT64 MmioAddress;
UINT8 ApmCmd;
} SMMSTORE_INFO;
#endif // SMMSTORE_GUID_H_

View file

@ -6,8 +6,7 @@
**/
#ifndef SPI_FLASH_INFO_GUID_H_
#define SPI_FLASH_INFO_GUID_H_
#pragma once
#include <IndustryStandard/Acpi.h>
//
@ -34,5 +33,3 @@ typedef struct {
UINT16 Flags;
PLD_GENERIC_ADDRESS SpiAddress;
} SPI_FLASH_INFO;
#endif

View file

@ -6,8 +6,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#ifndef UNIVERSAL_PAYLOAD_BASE_H_
#define UNIVERSAL_PAYLOAD_BASE_H_
#pragma once
extern GUID gUniversalPayloadBaseGuid;
@ -25,5 +24,3 @@ typedef struct {
#define SS_32BIT_MEMORY_SPACE BIT25
#define SS_64BIT_MEMORY_SPACE BIT24+BIT25
#define DWORDS_TO_NEXT_ADDR_TYPE 7
#endif // UNIVERSAL_PAYLOAD_BASE_H_

View file

@ -6,8 +6,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#ifndef UNIVERSAL_PAYLOAD_SERIAL_PORT_PARENT_DEVICE_INFO_
#define UNIVERSAL_PAYLOAD_SERIAL_PORT_PARENT_DEVICE_INFO_
#pragma once
extern GUID gUniversalPayloadSerialPortParentDeviceInfoGuid;
@ -24,5 +23,3 @@ typedef struct {
#pragma pack()
#define UNIVERSAL_PAYLOAD_SERIAL_PORT_PARENT_DEVICE_INFO_REVISION 1
#endif // UNIVERSAL_PAYLOAD_SERIAL_PORT_PARENT_DEVICE_INFO_

View file

@ -7,8 +7,7 @@
**/
#ifndef BOOTLOADER_PARSE_LIB_
#define BOOTLOADER_PARSE_LIB_
#pragma once
#include <PiPei.h>
#include <Guid/GraphicsInfoHob.h>
@ -183,5 +182,3 @@ EFIAPI
ParseCapsules (
IN BL_CAPSULE_CALLBACK CapsuleCallback
);
#endif

View file

@ -5,8 +5,7 @@
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#ifndef BUILD_FDT_LIB_H_
#define BUILD_FDT_LIB_H_
#pragma once
/**
It will build FDT for UPL consumed.
@ -18,5 +17,3 @@ EFI_STATUS
BuildFdtForUPL (
IN VOID *FdtBase
);
#endif

View file

@ -15,12 +15,9 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#ifndef DXE_HOB_LIST_LIB_H_
#define DXE_HOB_LIST_LIB_H_
#pragma once
///
/// Cache copy of the start of HOB list
///
extern VOID *gHobList;
#endif

View file

@ -5,8 +5,7 @@
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#ifndef FDT_PARSER_LIB_H_
#define FDT_PARSER_LIB_H_
#pragma once
/**
It will parse FDT based on DTB.
@ -60,5 +59,3 @@ EFIAPI
UplInitHob (
IN VOID *FdtBase
);
#endif

View file

@ -6,8 +6,7 @@
**/
#ifndef FLASHDEVICE_LIB_H_
#define FLASHDEVICE_LIB_H_
#pragma once
/**
Read NumBytes bytes of data from the address specified by
@ -100,5 +99,3 @@ PHYSICAL_ADDRESS
EFIAPI
LibFvbFlashDeviceMemoryMap (
);
#endif

View file

@ -5,8 +5,7 @@
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#ifndef HOB_PARSER_LIB_H_
#define HOB_PARSER_LIB_H_
#pragma once
/**
*
@ -66,5 +65,3 @@ BOOLEAN
IsHobNeed (
EFI_PEI_HOB_POINTERS Hob
);
#endif

View file

@ -8,8 +8,7 @@
**/
#ifndef PAYLOAD_ENTRY_HELPER_LIB_H_
#define PAYLOAD_ENTRY_HELPER_LIB_H_
#pragma once
/**
Add a new HOB to the HOB List.
@ -27,5 +26,3 @@ CreateHob (
IN UINT16 HobType,
IN UINT16 HobLength
);
#endif // PAYLOAD_ENTRY_HELPER_LIB_H_

View file

@ -8,8 +8,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#ifndef BOOTLOADER_PLATFORM_SUPPORT_LIB_
#define BOOTLOADER_PLATFORM_SUPPORT_LIB_
#pragma once
/**
Parse platform specific information from bootloader
@ -23,5 +22,3 @@ EFIAPI
ParsePlatformInfo (
VOID
);
#endif // __BOOTLOADER_PLATFORM_SUPPORT_LIB__

View file

@ -7,8 +7,7 @@
**/
#ifndef SMM_STORE_LIB_H_
#define SMM_STORE_LIB_H_
#pragma once
#include <Base.h>
#include <Uefi/UefiBaseType.h>
@ -193,5 +192,3 @@ EFIAPI
SmmStoreLibDeinitialize (
VOID
);
#endif /* SMM_STORE_LIB_H_ */

View file

@ -7,8 +7,7 @@
**/
#ifndef SMM_STORE_PARSE_LIB_H_
#define SMM_STORE_PARSE_LIB_H_
#pragma once
#include <Guid/SmmStoreInfoGuid.h>
@ -25,5 +24,3 @@ EFIAPI
ParseSmmStoreInfo (
OUT SMMSTORE_INFO *SmmStoreInfo
);
#endif // SMM_STORE_PARSE_LIB_H_

View file

@ -6,8 +6,7 @@
**/
#ifndef SPI_FLASH_LIB_H_
#define SPI_FLASH_LIB_H_
#pragma once
/**
Flash Region Type
@ -209,5 +208,3 @@ SpiGetRegionAddress (
OUT UINT32 *BaseAddress OPTIONAL,
OUT UINT32 *RegionSize OPTIONAL
);
#endif

View file

@ -8,8 +8,7 @@
- Universal Payload Specification 0.8 (https://universalpayload.github.io/spec/)
**/
#ifndef UNIVERSAL_PAYLOAD_DEVICE_TREE_H_
#define UNIVERSAL_PAYLOAD_DEVICE_TREE_H_
#pragma once
#include <Uefi.h>
#include <UniversalPayload/UniversalPayload.h>
@ -26,5 +25,3 @@ typedef struct {
#define UNIVERSAL_PAYLOAD_DEVICE_TREE_REVISION 1
extern GUID gUniversalPayloadDeviceTreeGuid;
#endif // UNIVERSAL_PAYLOAD_SMBIOS_TABLE_H_

View file

@ -8,8 +8,7 @@
**/
#ifndef PCI_HOST_BRIDGE_H_
#define PCI_HOST_BRIDGE_H_
#pragma once
#include <UniversalPayload/PciRootBridges.h>
@ -113,5 +112,3 @@ CreateRootBridgeDevicePath (
IN UINT32 HID,
IN UINT32 UID
);
#endif

View file

@ -5,8 +5,7 @@ Copyright (c) 2015 - 2016, Intel Corporation. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#ifndef PLATFORM_BOOT_MANAGER_H_
#define PLATFORM_BOOT_MANAGER_H_
#pragma once
#include <PiDxe.h>
#include <Protocol/LoadedImage.h>
@ -130,5 +129,3 @@ PlatformBootManagerShowProgress (
IN UINTN Progress,
IN UINTN PreviousValue
);
#endif // _PLATFORM_BOOT_MANAGER_H

View file

@ -5,8 +5,7 @@ Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#ifndef PLATFORM_CONSOLE_H_
#define PLATFORM_CONSOLE_H_
#pragma once
#include <PiDxe.h>
#include <IndustryStandard/Pci.h>
@ -64,5 +63,3 @@ EFIAPI
PlatformConsoleInit (
VOID
);
#endif

View file

@ -7,8 +7,7 @@
**/
#ifndef COREBOOT_SMMSTORE_H_
#define COREBOOT_SMMSTORE_H_
#pragma once
#define SMMSTORE_RET_SUCCESS 0
#define SMMSTORE_RET_FAILURE 1
@ -82,5 +81,3 @@ TriggerSmi (
IN UINTN Arg,
IN UINTN Retry
);
#endif // COREBOOT_SMMSTORE_H_

View file

@ -6,8 +6,7 @@
**/
#ifndef REGS_SPI_H_
#define REGS_SPI_H_
#pragma once
#define R_SPI_BASE 0x10 ///< 32-bit Memory Base Address Register
#define B_SPI_BAR0_MASK 0x0FFF
@ -117,5 +116,3 @@
//
#define R_SPI_FCBA_FLCOMP 0x00 ///< Flash Components Register
#define B_SPI_FLCOMP_COMP1_MASK 0x0F ///< Flash Component 1 Density
#endif

View file

@ -6,8 +6,7 @@
**/
#ifndef SPI_COMMON_LIB_H_
#define SPI_COMMON_LIB_H_
#pragma once
#include <PiDxe.h>
#include <Uefi/UefiBaseType.h>
@ -199,5 +198,3 @@ WaitForSpiCycleComplete (
IN UINT32 PchSpiBar0,
IN BOOLEAN ErrorCheck
);
#endif

View file

@ -6,8 +6,7 @@
**/
#ifndef ELF_LIB_H_
#define ELF_LIB_H_
#pragma once
#include <PiPei.h>
@ -118,5 +117,3 @@ GetElfSectionPos (
OUT UINTN *Offset,
OUT UINTN *Size
);
#endif /* ELF_LIB_H_ */

View file

@ -6,8 +6,7 @@
**/
#ifndef EFI_LIB_INTERNAL_H_
#define EFI_LIB_INTERNAL_H_
#pragma once
#include <Library/BaseLib.h>
#include <Library/DebugLib.h>
@ -104,5 +103,3 @@ EFI_STATUS
LoadElf64Image (
IN ELF_IMAGE_CONTEXT *ElfCt
);
#endif

View file

@ -4,8 +4,7 @@ Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#ifndef FIT_LIB_H_
#define FIT_LIB_H_
#pragma once
#include <PiPei.h>
#include <Library/DebugLib.h>
@ -56,5 +55,3 @@ ParseFitImage (
IN VOID *ImageBase,
OUT FIT_IMAGE_CONTEXT *Context
);
#endif

View file

@ -6,8 +6,7 @@
**/
#ifndef SMM_SW_DISPATCH2_H_
#define SMM_SW_DISPATCH2_H_
#pragma once
#include <PiDxe.h>
#include <Protocol/SmmSwDispatch2.h>
@ -32,5 +31,3 @@ typedef struct {
UINTN SwSmiInputValue;
UINTN DispatchFunction;
} EFI_SMM_SW_DISPATCH2_CONTEXT;
#endif

View file

@ -7,8 +7,8 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#ifndef _PCI_PLATFORM_DXE_H_
#define _PCI_PLATFORM_DXE_H_
#pragma once
#include <PiDxe.h>
#include <IndustryStandard/Pci.h>
@ -16,5 +16,3 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
#include <IndustryStandard/Pci22.h>
#include <Protocol/PciIo.h>
#include <Protocol/PciPlatform.h>
#endif

View file

@ -6,8 +6,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#ifndef SMM_ACCESS_DRIVER_H_
#define SMM_ACCESS_DRIVER_H_
#pragma once
#include <PiDxe.h>
#include <Protocol/SmmAccess2.h>
@ -32,5 +31,3 @@ typedef struct {
UINT32 NumberRegions;
EFI_SMRAM_DESCRIPTOR *SmramDesc;
} SMM_ACCESS_PRIVATE_DATA;
#endif

View file

@ -6,8 +6,7 @@
**/
#ifndef SMM_STORE_DXE_H_
#define SMM_STORE_DXE_H_
#pragma once
#include <Base.h>
#include <PiDxe.h>
@ -107,5 +106,3 @@ FvbEraseBlocks (
IN CONST EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL *This,
...
);
#endif // SMM_STORE_DXE_H_

View file

@ -6,8 +6,7 @@
**/
#ifndef __UEFI_PAYLOAD_ENTRY_H__
#define __UEFI_PAYLOAD_ENTRY_H__
#pragma once
#include <PiPei.h>
@ -282,5 +281,3 @@ EFIAPI
InitializeFloatingPointUnits (
VOID
);
#endif

View file

@ -14,8 +14,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#ifndef _VIRTUAL_MEMORY_H_
#define _VIRTUAL_MEMORY_H_
#pragma once
#define SYS_CODE64_SEL 0x38
@ -326,5 +325,3 @@ VOID *
AllocatePageTableMemory (
IN UINTN Pages
);
#endif