From aefbe90f7467dc7245f0c895b94e3d52b2ebf6f7 Mon Sep 17 00:00:00 2001 From: Laszlo Ersek Date: Fri, 2 Mar 2018 17:11:52 +0100 Subject: [PATCH 1/3] BaseTools/header.makefile: add "-Wno-stringop-truncation" gcc-8 (which is part of Fedora 28) enables the new warning "-Wstringop-truncation" in "-Wall". This warning is documented in detail at ; the introduction says > Warn for calls to bounded string manipulation functions such as strncat, > strncpy, and stpncpy that may either truncate the copied string or leave > the destination unchanged. It breaks the BaseTools build with: > EfiUtilityMsgs.c: In function 'PrintMessage': > EfiUtilityMsgs.c:484:9: error: 'strncat' output may be truncated copying > between 0 and 511 bytes from a string of length 511 > [-Werror=stringop-truncation] > strncat (Line, Line2, MAX_LINE_LEN - strlen (Line) - 1); > ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > EfiUtilityMsgs.c:469:9: error: 'strncat' output may be truncated copying > between 0 and 511 bytes from a string of length 511 > [-Werror=stringop-truncation] > strncat (Line, Line2, MAX_LINE_LEN - strlen (Line) - 1); > ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > EfiUtilityMsgs.c:511:5: error: 'strncat' output may be truncated copying > between 0 and 511 bytes from a string of length 511 > [-Werror=stringop-truncation] > strncat (Line, Line2, MAX_LINE_LEN - strlen (Line) - 1); > ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ The right way to fix the warning would be to implement string concat with snprintf(). However, Microsoft does not appear to support snprintf() before VS2015 , so we just have to shut up the warning. The strncat() calls flagged above are valid BTW. Cc: Ard Biesheuvel Cc: Cole Robinson Cc: Liming Gao Cc: Paolo Bonzini Cc: Yonghong Zhu Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Laszlo Ersek Reviewed-by: Liming Gao --- BaseTools/Source/C/Makefiles/header.makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/BaseTools/Source/C/Makefiles/header.makefile b/BaseTools/Source/C/Makefiles/header.makefile index 27aa28b2fa02..e21f9490cb70 100644 --- a/BaseTools/Source/C/Makefiles/header.makefile +++ b/BaseTools/Source/C/Makefiles/header.makefile @@ -47,9 +47,9 @@ INCLUDE = $(TOOL_INCLUDE) -I $(MAKEROOT) -I $(MAKEROOT)/Include/Common -I $(MAKE BUILD_CPPFLAGS = $(INCLUDE) -O2 ifeq ($(DARWIN),Darwin) # assume clang or clang compatible flags on OS X -BUILD_CFLAGS = -MD -fshort-wchar -fno-strict-aliasing -Wall -Werror -Wno-deprecated-declarations -Wno-self-assign -Wno-unused-result -nostdlib -c -g +BUILD_CFLAGS = -MD -fshort-wchar -fno-strict-aliasing -Wall -Werror -Wno-deprecated-declarations -Wno-stringop-truncation -Wno-self-assign -Wno-unused-result -nostdlib -c -g else -BUILD_CFLAGS = -MD -fshort-wchar -fno-strict-aliasing -Wall -Werror -Wno-deprecated-declarations -Wno-unused-result -nostdlib -c -g +BUILD_CFLAGS = -MD -fshort-wchar -fno-strict-aliasing -Wall -Werror -Wno-deprecated-declarations -Wno-stringop-truncation -Wno-unused-result -nostdlib -c -g endif BUILD_LFLAGS = BUILD_CXXFLAGS = -Wno-unused-result From e408be94b528a62b9e781055c2df57ed4a1461f9 Mon Sep 17 00:00:00 2001 From: Laszlo Ersek Date: Fri, 2 Mar 2018 17:11:52 +0100 Subject: [PATCH 2/3] BaseTools/GenVtf: silence false "stringop-overflow" warning with memcpy() gcc-8 (which is part of Fedora 28) enables the new warning "-Wstringop-overflow" in "-Wall". This warning is documented in detail at ; the introduction says > Warn for calls to string manipulation functions such as memcpy and > strcpy that are determined to overflow the destination buffer. It breaks the BaseTools build with: > GenVtf.c: In function 'ConvertVersionInfo': > GenVtf.c:132:7: error: 'strncpy' specified bound depends on the length > of the source argument [-Werror=stringop-overflow=] > strncpy (TemStr + 4 - Length, Str, Length); > ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > GenVtf.c:130:14: note: length computed here > Length = strlen(Str); > ^~~~~~~~~~~ It is a false positive because, while the bound equals the length of the source argument, the destination pointer is moved back towards the beginning of the destination buffer by the same amount (and this amount is range-checked first, so we can't precede the start of the dest buffer). Replace both strncpy() calls with memcpy(). Cc: Ard Biesheuvel Cc: Cole Robinson Cc: Liming Gao Cc: Paolo Bonzini Cc: Yonghong Zhu Reported-by: Cole Robinson Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Laszlo Ersek Reviewed-by: Liming Gao --- BaseTools/Source/C/GenVtf/GenVtf.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/BaseTools/Source/C/GenVtf/GenVtf.c b/BaseTools/Source/C/GenVtf/GenVtf.c index 65ae08eeceb8..fc7ae02203ff 100644 --- a/BaseTools/Source/C/GenVtf/GenVtf.c +++ b/BaseTools/Source/C/GenVtf/GenVtf.c @@ -129,9 +129,9 @@ Routine Description: } else { Length = strlen(Str); if (Length < 4) { - strncpy (TemStr + 4 - Length, Str, Length); + memcpy (TemStr + 4 - Length, Str, Length); } else { - strncpy (TemStr, Str + Length - 4, 4); + memcpy (TemStr, Str + Length - 4, 4); } sscanf ( From 4f249dd3291b1b7969a2e2b93f54af32a77a3719 Mon Sep 17 00:00:00 2001 From: Liming Gao Date: Thu, 1 Nov 2018 22:35:29 +0800 Subject: [PATCH 3/3] BaseTools tools_def.template: Add GCC link script option in ASLDLINK_FLAGS GCC link script is used to discard the unused section data from ELF image. ASLDLINK_FLAGS requires it to remove the unnecessary section data, then GenFw can be used to retrieve the correct data section from ELF image. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Liming Gao Cc: Yonghong Zhu Reviewed-by: Yonghong Zhu --- BaseTools/Conf/tools_def.template | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BaseTools/Conf/tools_def.template b/BaseTools/Conf/tools_def.template index d8fde02ea351..5d38c9a602a1 100755 --- a/BaseTools/Conf/tools_def.template +++ b/BaseTools/Conf/tools_def.template @@ -4587,7 +4587,7 @@ DEFINE GCC48_AARCH64_ASLDLINK_FLAGS = DEF(GCC47_AARCH64_ASLDLINK_FLAGS) DEFINE GCC49_IA32_CC_FLAGS = DEF(GCC48_IA32_CC_FLAGS) DEFINE GCC49_X64_CC_FLAGS = DEF(GCC48_X64_CC_FLAGS) DEFINE GCC49_IA32_X64_DLINK_COMMON = -nostdlib -Wl,-n,-q,--gc-sections -z common-page-size=0x40 -DEFINE GCC49_IA32_X64_ASLDLINK_FLAGS = DEF(GCC49_IA32_X64_DLINK_COMMON) -Wl,--entry,ReferenceAcpiTable -u ReferenceAcpiTable +DEFINE GCC49_IA32_X64_ASLDLINK_FLAGS = DEF(GCC49_IA32_X64_DLINK_COMMON) -Wl,--defsym=PECOFF_HEADER_SIZE=0 DEF(GCC_DLINK2_FLAGS_COMMON) -Wl,--entry,ReferenceAcpiTable -u ReferenceAcpiTable DEFINE GCC49_IA32_X64_DLINK_FLAGS = DEF(GCC49_IA32_X64_DLINK_COMMON) -Wl,--entry,$(IMAGE_ENTRY_POINT) -u $(IMAGE_ENTRY_POINT) -Wl,-Map,$(DEST_DIR_DEBUG)/$(BASE_NAME).map,--whole-archive DEFINE GCC49_IA32_DLINK2_FLAGS = DEF(GCC48_IA32_DLINK2_FLAGS) DEFINE GCC49_X64_DLINK_FLAGS = DEF(GCC49_IA32_X64_DLINK_FLAGS) -Wl,-melf_x86_64,--oformat=elf64-x86-64,-pie