Scott: I find this change will impact the check result of ECC tool. This tool is in BaseTools directory that is used to check the coding style in source file.
I think we need to investigate how to enhance ECC to support EFIFORMAT. Thanks Liming -----Original Message----- From: edk2-devel [mailto:[email protected]] On Behalf Of Scott Duplichan Sent: Saturday, August 08, 2015 1:58 PM To: [email protected] Cc: Tian, Feng Subject: [edk2] [PATCH 4/10] MdeModulePkg: Support format string argument checking Support compile time argument consistency checking for functions that accept a PrintLib format string followed by a variable argument list. Macro 'EFIFORMAT' added to the function prototype accepts a single argument indicating which function argument holds the format string. The EFIFORMAT macro assumes the variable argument list immediately follows the format string. Format string argument checking requires a compiler that understands EDK2 format strings, such as GCC with the gcc_format from BaseTools/gcc applied. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Scott Duplichan <[email protected]> --- MdeModulePkg/Include/Library/NetLib.h | 1 + MdeModulePkg/Include/Protocol/Print2.h | 8 +++--- .../CustomizedDisplayLibInternal.h | 1 + MdePkg/Include/AArch64/ProcessorBind.h | 33 ++++++++++++++++++++++ MdePkg/Include/Arm/ProcessorBind.h | 31 ++++++++++++++++++++ MdePkg/Include/Ia32/ProcessorBind.h | 32 +++++++++++++++++++++ MdePkg/Include/Ipf/ProcessorBind.h | 32 +++++++++++++++++++++ MdePkg/Include/Library/DebugLib.h | 1 + MdePkg/Include/Library/FileHandleLib.h | 1 + MdePkg/Include/Library/PrintLib.h | 4 +++ MdePkg/Include/Library/UefiLib.h | 7 +++++ MdePkg/Include/X64/ProcessorBind.h | 32 +++++++++++++++++++++ MdePkg/Library/BasePrintLib/PrintLibInternal.h | 1 + .../Library/UefiDevicePathLib/DevicePathToText.c | 1 + 14 files changed, 181 insertions(+), 4 deletions(-) diff --git a/MdeModulePkg/Include/Library/NetLib.h b/MdeModulePkg/Include/Library/NetLib.h index 280c51a..9608335 100644 --- a/MdeModulePkg/Include/Library/NetLib.h +++ b/MdeModulePkg/Include/Library/NetLib.h @@ -292,6 +292,7 @@ typedef struct { **/ CHAR8 * EFIAPI +EFIFORMAT (1) NetDebugASPrint ( IN CHAR8 *Format, ... diff --git a/MdeModulePkg/Include/Protocol/Print2.h b/MdeModulePkg/Include/Protocol/Print2.h index 1c127d5..795faba 100644 --- a/MdeModulePkg/Include/Protocol/Print2.h +++ b/MdeModulePkg/Include/Protocol/Print2.h @@ -102,7 +102,7 @@ UINTN **/ typedef UINTN -(EFIAPI *UNICODE_S_PRINT)( +(EFIAPI EFIFORMAT (3) *UNICODE_S_PRINT)( OUT CHAR16 *StartOfBuffer, IN UINTN BufferSize, IN CONST CHAR16 *FormatString, @@ -184,7 +184,7 @@ UINTN **/ typedef UINTN -(EFIAPI *UNICODE_S_PRINT_ASCII_FORMAT)( +(EFIAPI EFIFORMAT (3) *UNICODE_S_PRINT_ASCII_FORMAT)( OUT CHAR16 *StartOfBuffer, IN UINTN BufferSize, IN CONST CHAR8 *FormatString, @@ -314,7 +314,7 @@ UINTN **/ typedef UINTN -(EFIAPI *ASCII_S_PRINT)( +(EFIAPI EFIFORMAT (3) *ASCII_S_PRINT)( OUT CHAR8 *StartOfBuffer, IN UINTN BufferSize, IN CONST CHAR8 *FormatString, @@ -396,7 +396,7 @@ UINTN **/ typedef UINTN -(EFIAPI *ASCII_S_PRINT_UNICODE_FORMAT)( +(EFIAPI EFIFORMAT (3) *ASCII_S_PRINT_UNICODE_FORMAT)( OUT CHAR8 *StartOfBuffer, IN UINTN BufferSize, IN CONST CHAR16 *FormatString, diff --git a/MdeModulePkg/Library/CustomizedDisplayLib/CustomizedDisplayLibInternal.h b/MdeModulePkg/Library/CustomizedDisplayLib/CustomizedDisplayLibInternal.h index 7342b50..6e37cc1 100644 --- a/MdeModulePkg/Library/CustomizedDisplayLib/CustomizedDisplayLibInternal.h +++ b/MdeModulePkg/Library/CustomizedDisplayLib/CustomizedDisplayLibInte +++ rnal.h @@ -275,6 +275,7 @@ LibSetUnicodeMem ( **/ UINTN EFIAPI +EFIFORMAT (4) PrintAt ( IN UINTN Width, IN UINTN Column, diff --git a/MdePkg/Include/AArch64/ProcessorBind.h b/MdePkg/Include/AArch64/ProcessorBind.h index c5fe874..2a6faa5 100644 --- a/MdePkg/Include/AArch64/ProcessorBind.h +++ b/MdePkg/Include/AArch64/ProcessorBind.h @@ -145,4 +145,37 @@ typedef INT64 INTN; #define __USER_LABEL_PREFIX__ #endif +/** + Define modifiers to enable function argument checking for a format + string followed by a variable argument list. + + Modifier EFIFORMAT enables argument checking for a format string of + the type described in PrintLib.h. Modifier EFIFORMAT_SHELL enables + argument checking for a format string of the type described in + ShellLib.h. The FormatPosition macro argument identifies which + function argument contains the format string (relative 1). The + variable argument list must start immediately after the format + string. To use this argument checking with gcc, the gcc tool chain must be rebuilt using the patch in BaseTools/gcc. + + @param FormatPosition Position (relative 1) of the function argument + containing the format string. + + @return None + +**/ +#if defined(EDK2_FORMAT_CHECKING) + #if defined(__GCC_EDK2_FORMATS__) + #define EFIFORMAT(FormatPosition) \ + __attribute__((format (edk2_printf, FormatPosition, FormatPosition+1))) + #define EFIFORMAT_SHELL(FormatPosition) \ + __attribute__((format (edk2_shell_printf, FormatPosition, +FormatPosition+1))) + #else + #error "EDK2_FORMAT_CHECKING is not supported by this tool chain" + #endif +#else + #define EFIFORMAT(FormatPosition) + #define EFIFORMAT_SHELL(FormatPosition) #endif + + #endif diff --git a/MdePkg/Include/Arm/ProcessorBind.h b/MdePkg/Include/Arm/ProcessorBind.h index c2482c2..4975f20 100644 --- a/MdePkg/Include/Arm/ProcessorBind.h +++ b/MdePkg/Include/Arm/ProcessorBind.h @@ -164,6 +164,37 @@ typedef INT32 INTN; #define __USER_LABEL_PREFIX__ #endif +/** + Define modifiers to enable function argument checking for a format + string followed by a variable argument list. + + Modifier EFIFORMAT enables argument checking for a format string of + the type described in PrintLib.h. Modifier EFIFORMAT_SHELL enables + argument checking for a format string of the type described in + ShellLib.h. The FormatPosition macro argument identifies which + function argument contains the format string (relative 1). The + variable argument list must start immediately after the format + string. To use this argument checking with gcc, the gcc tool chain must be rebuilt using the patch in BaseTools/gcc. + + @param FormatPosition Position (relative 1) of the function argument + containing the format string. + + @return None + +**/ +#if defined(EDK2_FORMAT_CHECKING) + #if defined(__GCC_EDK2_FORMATS__) + #define EFIFORMAT(FormatPosition) \ + __attribute__((format (edk2_printf, FormatPosition, FormatPosition+1))) + #define EFIFORMAT_SHELL(FormatPosition) \ + __attribute__((format (edk2_shell_printf, FormatPosition, +FormatPosition+1))) + #else + #error "EDK2_FORMAT_CHECKING is not supported by this tool chain" + #endif +#else + #define EFIFORMAT(FormatPosition) + #define EFIFORMAT_SHELL(FormatPosition) #endif +#endif diff --git a/MdePkg/Include/Ia32/ProcessorBind.h b/MdePkg/Include/Ia32/ProcessorBind.h index 22f07ca..216434f 100644 --- a/MdePkg/Include/Ia32/ProcessorBind.h +++ b/MdePkg/Include/Ia32/ProcessorBind.h @@ -308,5 +308,37 @@ typedef INT32 INTN; #define __USER_LABEL_PREFIX__ _ #endif +/** + Define modifiers to enable function argument checking for a format + string followed by a variable argument list. + + Modifier EFIFORMAT enables argument checking for a format string of + the type described in PrintLib.h. Modifier EFIFORMAT_SHELL enables + argument checking for a format string of the type described in + ShellLib.h. The FormatPosition macro argument identifies which + function argument contains the format string (relative 1). The + variable argument list must start immediately after the format + string. To use this argument checking with gcc, the gcc tool chain must be rebuilt using the patch in BaseTools/gcc. + + @param FormatPosition Position (relative 1) of the function argument + containing the format string. + + @return None + +**/ +#if defined(EDK2_FORMAT_CHECKING) + #if defined(__GCC_EDK2_FORMATS__) + #define EFIFORMAT(FormatPosition) \ + __attribute__((format (edk2_printf, FormatPosition, FormatPosition+1))) + #define EFIFORMAT_SHELL(FormatPosition) \ + __attribute__((format (edk2_shell_printf, FormatPosition, +FormatPosition+1))) + #else + #error "EDK2_FORMAT_CHECKING is not supported by this tool chain" + #endif +#else + #define EFIFORMAT(FormatPosition) + #define EFIFORMAT_SHELL(FormatPosition) #endif + +#endif diff --git a/MdePkg/Include/Ipf/ProcessorBind.h b/MdePkg/Include/Ipf/ProcessorBind.h index cead575..42b32f2 100644 --- a/MdePkg/Include/Ipf/ProcessorBind.h +++ b/MdePkg/Include/Ipf/ProcessorBind.h @@ -309,5 +309,37 @@ typedef struct { #define __USER_LABEL_PREFIX__ #endif +/** + Define modifiers to enable function argument checking for a format + string followed by a variable argument list. + + Modifier EFIFORMAT enables argument checking for a format string of + the type described in PrintLib.h. Modifier EFIFORMAT_SHELL enables + argument checking for a format string of the type described in + ShellLib.h. The FormatPosition macro argument identifies which + function argument contains the format string (relative 1). The + variable argument list must start immediately after the format + string. To use this argument checking with gcc, the gcc tool chain must be rebuilt using the patch in BaseTools/gcc. + + @param FormatPosition Position (relative 1) of the function argument + containing the format string. + + @return None + +**/ +#if defined(EDK2_FORMAT_CHECKING) + #if defined(__GCC_EDK2_FORMATS__) + #define EFIFORMAT(FormatPosition) \ + __attribute__((format (edk2_printf, FormatPosition, FormatPosition+1))) + #define EFIFORMAT_SHELL(FormatPosition) \ + __attribute__((format (edk2_shell_printf, FormatPosition, +FormatPosition+1))) + #else + #error "EDK2_FORMAT_CHECKING is not supported by this tool chain" + #endif +#else + #define EFIFORMAT(FormatPosition) + #define EFIFORMAT_SHELL(FormatPosition) #endif + +#endif diff --git a/MdePkg/Include/Library/DebugLib.h b/MdePkg/Include/Library/DebugLib.h index 219d147..fdde108 100644 --- a/MdePkg/Include/Library/DebugLib.h +++ b/MdePkg/Include/Library/DebugLib.h @@ -93,6 +93,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. **/ VOID EFIAPI +EFIFORMAT (2) DebugPrint ( IN UINTN ErrorLevel, IN CONST CHAR8 *Format, diff --git a/MdePkg/Include/Library/FileHandleLib.h b/MdePkg/Include/Library/FileHandleLib.h index b5ac19a..dac6be0 100644 --- a/MdePkg/Include/Library/FileHandleLib.h +++ b/MdePkg/Include/Library/FileHandleLib.h @@ -474,6 +474,7 @@ FileHandleWriteLine( **/ EFI_STATUS EFIAPI +EFIFORMAT (2) FileHandlePrintLine( IN EFI_FILE_HANDLE Handle, IN CONST CHAR16 *Format, diff --git a/MdePkg/Include/Library/PrintLib.h b/MdePkg/Include/Library/PrintLib.h index fcaacde..4abb318 100644 --- a/MdePkg/Include/Library/PrintLib.h +++ b/MdePkg/Include/Library/PrintLib.h @@ -325,6 +325,7 @@ UnicodeBSPrint ( **/ UINTN EFIAPI +EFIFORMAT (3) UnicodeSPrint ( OUT CHAR16 *StartOfBuffer, IN UINTN BufferSize, @@ -452,6 +453,7 @@ UnicodeBSPrintAsciiFormat ( **/ UINTN EFIAPI +EFIFORMAT (3) UnicodeSPrintAsciiFormat ( OUT CHAR16 *StartOfBuffer, IN UINTN BufferSize, @@ -626,6 +628,7 @@ AsciiBSPrint ( **/ UINTN EFIAPI +EFIFORMAT (3) AsciiSPrint ( OUT CHAR8 *StartOfBuffer, IN UINTN BufferSize, @@ -753,6 +756,7 @@ AsciiBSPrintUnicodeFormat ( **/ UINTN EFIAPI +EFIFORMAT (3) AsciiSPrintUnicodeFormat ( OUT CHAR8 *StartOfBuffer, IN UINTN BufferSize, diff --git a/MdePkg/Include/Library/UefiLib.h b/MdePkg/Include/Library/UefiLib.h index 4ce8dc6..f1580fb 100644 --- a/MdePkg/Include/Library/UefiLib.h +++ b/MdePkg/Include/Library/UefiLib.h @@ -1059,6 +1059,7 @@ EfiGetNameGuidFromFwVolDevicePathNode ( **/ UINTN EFIAPI +EFIFORMAT (1) Print ( IN CONST CHAR16 *Format, ... @@ -1086,6 +1087,7 @@ Print ( **/ UINTN EFIAPI +EFIFORMAT (1) ErrorPrint ( IN CONST CHAR16 *Format, ... @@ -1112,6 +1114,7 @@ ErrorPrint ( **/ UINTN EFIAPI +EFIFORMAT (1) AsciiPrint ( IN CONST CHAR8 *Format, ... @@ -1138,6 +1141,7 @@ AsciiPrint ( **/ UINTN EFIAPI +EFIFORMAT (1) AsciiErrorPrint ( IN CONST CHAR8 *Format, ... @@ -1186,6 +1190,7 @@ AsciiErrorPrint ( **/ UINTN EFIAPI +EFIFORMAT (5) PrintXY ( IN UINTN PointX, IN UINTN PointY, @@ -1236,6 +1241,7 @@ PrintXY ( **/ UINTN EFIAPI +EFIFORMAT (5) AsciiPrintXY ( IN UINTN PointX, IN UINTN PointY, @@ -1450,6 +1456,7 @@ CatVSPrint ( **/ CHAR16 * EFIAPI +EFIFORMAT (2) CatSPrint ( IN CHAR16 *String, OPTIONAL IN CONST CHAR16 *FormatString, diff --git a/MdePkg/Include/X64/ProcessorBind.h b/MdePkg/Include/X64/ProcessorBind.h index 81dbe18..5897f0e 100644 --- a/MdePkg/Include/X64/ProcessorBind.h +++ b/MdePkg/Include/X64/ProcessorBind.h @@ -314,5 +314,37 @@ typedef INT64 INTN; #define __USER_LABEL_PREFIX__ #endif +/** + Define modifiers to enable function argument checking for a format + string followed by a variable argument list. + + Modifier EFIFORMAT enables argument checking for a format string of + the type described in PrintLib.h. Modifier EFIFORMAT_SHELL enables + argument checking for a format string of the type described in + ShellLib.h. The FormatPosition macro argument identifies which + function argument contains the format string (relative 1). The + variable argument list must start immediately after the format + string. To use this argument checking with gcc, the gcc tool chain must be rebuilt using the patch in BaseTools/gcc. + + @param FormatPosition Position (relative 1) of the function argument + containing the format string. + + @return None + +**/ +#if defined(EDK2_FORMAT_CHECKING) + #if defined(__GCC_EDK2_FORMATS__) + #define EFIFORMAT(FormatPosition) \ + __attribute__((format (edk2_printf, FormatPosition, FormatPosition+1))) + #define EFIFORMAT_SHELL(FormatPosition) \ + __attribute__((format (edk2_shell_printf, FormatPosition, +FormatPosition+1))) + #else + #error "EDK2_FORMAT_CHECKING is not supported by this tool chain" + #endif +#else + #define EFIFORMAT(FormatPosition) + #define EFIFORMAT_SHELL(FormatPosition) #endif + +#endif diff --git a/MdePkg/Library/BasePrintLib/PrintLibInternal.h b/MdePkg/Library/BasePrintLib/PrintLibInternal.h index 05f2e1b..7cadfe7 100644 --- a/MdePkg/Library/BasePrintLib/PrintLibInternal.h +++ b/MdePkg/Library/BasePrintLib/PrintLibInternal.h @@ -113,6 +113,7 @@ BasePrintLibSPrintMarker ( **/ UINTN EFIAPI +EFIFORMAT (4) BasePrintLibSPrint ( OUT CHAR8 *StartOfBuffer, IN UINTN BufferSize, diff --git a/MdePkg/Library/UefiDevicePathLib/DevicePathToText.c b/MdePkg/Library/UefiDevicePathLib/DevicePathToText.c index be4619a..f249c8c 100644 --- a/MdePkg/Library/UefiDevicePathLib/DevicePathToText.c +++ b/MdePkg/Library/UefiDevicePathLib/DevicePathToText.c @@ -31,6 +31,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. **/ CHAR16 * EFIAPI +EFIFORMAT (2) UefiDevicePathLibCatPrint ( IN OUT POOL_PRINT *Str, IN CHAR16 *Fmt, _______________________________________________ edk2-devel mailing list [email protected] https://lists.01.org/mailman/listinfo/edk2-devel _______________________________________________ edk2-devel mailing list [email protected] https://lists.01.org/mailman/listinfo/edk2-devel

