Skip to content

Commit bcdcdfc

Browse files
committed
modules/linuxboot: Import upstream edk2 patches to fix building with gcc 8
Signed-off-by: Nathan Rennie-Waldock <nathan.renniewaldock@gmail.com>
1 parent bb3df89 commit bcdcdfc

File tree

4 files changed

+184
-0
lines changed

4 files changed

+184
-0
lines changed

modules/linuxboot

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,20 @@ linuxboot_dir := linuxboot-$(linuxboot_version)/build/$(linuxboot_board)
1313

1414
linuxboot_configure := \
1515
echo >&2 "Pre-building edk2" ; \
16+
if [ -d $(pwd)/patches/linuxboot-edk2 ] && \
17+
[ ! -f $(build)/$(linuxboot_base_dir)/edk2/.patched ]; then \
18+
set -e ; \
19+
$(MAKE) \
20+
-C $(build)/$(linuxboot_base_dir) \
21+
BOARD=$(linuxboot_board) \
22+
edk2/.git ; \
23+
for patch in $(pwd)/patches/linuxboot-edk2/*.patch; do \
24+
echo Applying $$$${patch\#\#*/} ; \
25+
( cd $(build)/$(linuxboot_base_dir)/edk2 && \
26+
patch -p1) < $$$$patch ; \
27+
done ; \
28+
touch $(build)/$(linuxboot_base_dir)/edk2/.patched ; \
29+
fi ; \
1630
$(MAKE) \
1731
-C $(build)/$(linuxboot_base_dir) \
1832
BOARD=$(linuxboot_board) \
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
From 9de306701312f986c9638cb819d3f1f848d55cab Mon Sep 17 00:00:00 2001
2+
From: Laszlo Ersek <lersek@redhat.com>
3+
Date: Fri, 2 Mar 2018 17:11:52 +0100
4+
Subject: [PATCH] BaseTools/GenVtf: silence false "stringop-overflow" warning
5+
with memcpy()
6+
7+
gcc-8 (which is part of Fedora 28) enables the new warning
8+
"-Wstringop-overflow" in "-Wall". This warning is documented in detail at
9+
<https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html>; the
10+
introduction says
11+
12+
> Warn for calls to string manipulation functions such as memcpy and
13+
> strcpy that are determined to overflow the destination buffer.
14+
15+
It breaks the BaseTools build with:
16+
17+
> GenVtf.c: In function 'ConvertVersionInfo':
18+
> GenVtf.c:132:7: error: 'strncpy' specified bound depends on the length
19+
> of the source argument [-Werror=stringop-overflow=]
20+
> strncpy (TemStr + 4 - Length, Str, Length);
21+
> ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
22+
> GenVtf.c:130:14: note: length computed here
23+
> Length = strlen(Str);
24+
> ^~~~~~~~~~~
25+
26+
It is a false positive because, while the bound equals the length of the
27+
source argument, the destination pointer is moved back towards the
28+
beginning of the destination buffer by the same amount (and this amount is
29+
range-checked first, so we can't precede the start of the dest buffer).
30+
31+
Replace both strncpy() calls with memcpy().
32+
33+
Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>
34+
Cc: Cole Robinson <crobinso@redhat.com>
35+
Cc: Liming Gao <liming.gao@intel.com>
36+
Cc: Paolo Bonzini <pbonzini@redhat.com>
37+
Cc: Yonghong Zhu <yonghong.zhu@intel.com>
38+
Reported-by: Cole Robinson <crobinso@redhat.com>
39+
Contributed-under: TianoCore Contribution Agreement 1.1
40+
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
41+
Reviewed-by: Liming Gao <liming.gao@intel.com>
42+
---
43+
BaseTools/Source/C/GenVtf/GenVtf.c | 4 ++--
44+
1 file changed, 2 insertions(+), 2 deletions(-)
45+
46+
diff --git a/BaseTools/Source/C/GenVtf/GenVtf.c b/BaseTools/Source/C/GenVtf/GenVtf.c
47+
index 65ae08eece..fc7ae02203 100644
48+
--- a/BaseTools/Source/C/GenVtf/GenVtf.c
49+
+++ b/BaseTools/Source/C/GenVtf/GenVtf.c
50+
@@ -129,9 +129,9 @@ Returns:
51+
} else {
52+
Length = strlen(Str);
53+
if (Length < 4) {
54+
- strncpy (TemStr + 4 - Length, Str, Length);
55+
+ memcpy (TemStr + 4 - Length, Str, Length);
56+
} else {
57+
- strncpy (TemStr, Str + Length - 4, 4);
58+
+ memcpy (TemStr, Str + Length - 4, 4);
59+
}
60+
61+
sscanf (
62+
--
63+
2.25.1
64+
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
From 1d212a83df0eaf32a6f5d4159beb2d77832e0231 Mon Sep 17 00:00:00 2001
2+
From: Laszlo Ersek <lersek@redhat.com>
3+
Date: Fri, 2 Mar 2018 17:11:52 +0100
4+
Subject: [PATCH 01/11] BaseTools/header.makefile: add
5+
"-Wno-stringop-truncation"
6+
7+
gcc-8 (which is part of Fedora 28) enables the new warning
8+
"-Wstringop-truncation" in "-Wall". This warning is documented in detail
9+
at <https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html>; the
10+
introduction says
11+
12+
> Warn for calls to bounded string manipulation functions such as strncat,
13+
> strncpy, and stpncpy that may either truncate the copied string or leave
14+
> the destination unchanged.
15+
16+
It breaks the BaseTools build with:
17+
18+
> EfiUtilityMsgs.c: In function 'PrintMessage':
19+
> EfiUtilityMsgs.c:484:9: error: 'strncat' output may be truncated copying
20+
> between 0 and 511 bytes from a string of length 511
21+
> [-Werror=stringop-truncation]
22+
> strncat (Line, Line2, MAX_LINE_LEN - strlen (Line) - 1);
23+
> ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
24+
> EfiUtilityMsgs.c:469:9: error: 'strncat' output may be truncated copying
25+
> between 0 and 511 bytes from a string of length 511
26+
> [-Werror=stringop-truncation]
27+
> strncat (Line, Line2, MAX_LINE_LEN - strlen (Line) - 1);
28+
> ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
29+
> EfiUtilityMsgs.c:511:5: error: 'strncat' output may be truncated copying
30+
> between 0 and 511 bytes from a string of length 511
31+
> [-Werror=stringop-truncation]
32+
> strncat (Line, Line2, MAX_LINE_LEN - strlen (Line) - 1);
33+
> ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
34+
35+
The right way to fix the warning would be to implement string concat with
36+
snprintf(). However, Microsoft does not appear to support snprintf()
37+
before VS2015
38+
<https://stackoverflow.com/questions/2915672/snprintf-and-visual-studio-2010>,
39+
so we just have to shut up the warning. The strncat() calls flagged above
40+
are valid BTW.
41+
42+
Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>
43+
Cc: Cole Robinson <crobinso@redhat.com>
44+
Cc: Liming Gao <liming.gao@intel.com>
45+
Cc: Paolo Bonzini <pbonzini@redhat.com>
46+
Cc: Yonghong Zhu <yonghong.zhu@intel.com>
47+
Contributed-under: TianoCore Contribution Agreement 1.1
48+
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
49+
Reviewed-by: Liming Gao <liming.gao@intel.com>
50+
---
51+
BaseTools/Source/C/Makefiles/header.makefile | 4 ++--
52+
1 file changed, 2 insertions(+), 2 deletions(-)
53+
54+
diff --git a/BaseTools/Source/C/Makefiles/header.makefile b/BaseTools/Source/C/Makefiles/header.makefile
55+
index 0976973bdd..550f8b35bc 100644
56+
--- a/BaseTools/Source/C/Makefiles/header.makefile
57+
+++ b/BaseTools/Source/C/Makefiles/header.makefile
58+
@@ -71,9 +71,9 @@ INCLUDE = $(TOOL_INCLUDE) -I $(MAKEROOT) -I $(MAKEROOT)/Include/Common -I $(MAKE
59+
BUILD_CPPFLAGS = $(INCLUDE) -O2
60+
ifeq ($(DARWIN),Darwin)
61+
# assume clang or clang compatible flags on OS X
62+
-BUILD_CFLAGS = -MD -fshort-wchar -fno-strict-aliasing -Wall -Werror -Wno-deprecated-declarations -Wno-self-assign -Wno-unused-result -nostdlib -c -g
63+
+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
64+
else
65+
-BUILD_CFLAGS = -MD -fshort-wchar -fno-strict-aliasing -Wall -Werror -Wno-deprecated-declarations -Wno-unused-result -nostdlib -c -g
66+
+BUILD_CFLAGS = -MD -fshort-wchar -fno-strict-aliasing -Wall -Werror -Wno-deprecated-declarations -Wno-stringop-truncation -Wno-unused-result -nostdlib -c -g
67+
endif
68+
BUILD_LFLAGS =
69+
BUILD_CXXFLAGS = -Wno-unused-result
70+
--
71+
2.25.1
72+
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
From 88e8498f8a72cff1f7af6852ec8166772913399e Mon Sep 17 00:00:00 2001
2+
From: Liming Gao <liming.gao@intel.com>
3+
Date: Thu, 1 Nov 2018 22:35:29 +0800
4+
Subject: [PATCH] BaseTools tools_def.template: Add GCC link script option in
5+
ASLDLINK_FLAGS
6+
7+
GCC link script is used to discard the unused section data from ELF image.
8+
ASLDLINK_FLAGS requires it to remove the unnecessary section data, then
9+
GenFw can be used to retrieve the correct data section from ELF image.
10+
11+
Contributed-under: TianoCore Contribution Agreement 1.1
12+
Signed-off-by: Liming Gao <liming.gao@intel.com>
13+
Cc: Yonghong Zhu <yonghong.zhu@intel.com>
14+
Reviewed-by: Yonghong Zhu <yonghong.zhu@intel.com>
15+
---
16+
BaseTools/Conf/tools_def.template | 2 +-
17+
1 file changed, 1 insertion(+), 1 deletion(-)
18+
19+
diff --git a/BaseTools/Conf/tools_def.template b/BaseTools/Conf/tools_def.template
20+
index a22b96c0b8..e0e68fd7fb 100755
21+
--- a/BaseTools/Conf/tools_def.template
22+
+++ b/BaseTools/Conf/tools_def.template
23+
@@ -4253,7 +4253,7 @@ DEFINE GCC48_AARCH64_ASLDLINK_FLAGS = DEF(GCC47_AARCH64_ASLDLINK_FLAGS)
24+
DEFINE GCC49_IA32_CC_FLAGS = DEF(GCC48_IA32_CC_FLAGS)
25+
DEFINE GCC49_X64_CC_FLAGS = DEF(GCC48_X64_CC_FLAGS)
26+
DEFINE GCC49_IA32_X64_DLINK_COMMON = -nostdlib -Wl,-n,-q,--gc-sections -z common-page-size=0x40
27+
-DEFINE GCC49_IA32_X64_ASLDLINK_FLAGS = DEF(GCC49_IA32_X64_DLINK_COMMON) -Wl,--entry,ReferenceAcpiTable -u ReferenceAcpiTable
28+
+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
29+
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
30+
DEFINE GCC49_IA32_DLINK2_FLAGS = DEF(GCC48_IA32_DLINK2_FLAGS)
31+
DEFINE GCC49_X64_DLINK_FLAGS = DEF(GCC49_IA32_X64_DLINK_FLAGS) -Wl,-melf_x86_64,--oformat=elf64-x86-64,-pie
32+
--
33+
2.25.1
34+

0 commit comments

Comments
 (0)