Skip to content

Commit d386d39

Browse files
committed
Toolchain: Fix QEMU build with latest gcc by disabling -fcf-protection
I noticed after upgrading my machine that the QEMU is no longer building due to GCC enabling `-fcf-protection` by default, even for targets that don't support it. The included patch came from the QEMU development list, but hasn't be included in any patch releases at the time of writing. https://lore.kernel.org/all/[email protected]/ Until QEMU patches, lets fix it on our end by patching before we build.
1 parent b760a1a commit d386d39

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

Toolchain/BuildQemu.sh

+6
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,12 @@ pushd "$DIR/Tarballs"
4040
else
4141
echo "Skipped extracting qemu"
4242
fi
43+
44+
pushd "$QEMU_VERSION"
45+
patch -p1 < "$DIR/Patches/qemu-cf-protection-none.patch" > /dev/null
46+
md5sum "$DIR/Patches/qemu-cf-protection-none.patch" > .patch.applied
47+
popd
48+
4349
popd
4450

4551
mkdir -p "$PREFIX"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
Subject: [PATCH] build: fix build failure with gcc 11.2 by disabling -fcf-protection
2+
Date: Tue, 8 Feb 2022 13:19:37 -0800 [thread overview]
3+
Message-ID: <[email protected]> (raw)
4+
5+
When doing RV qemu builds with host gcc 11.2, ran into following build failure
6+
7+
| cc -MMD -MP -MT linuxboot_dma.o -MF ./linuxboot_dma.d -O2 -g -march=i486 -Wall \
8+
| -Wstrict-prototypes -Wredundant-decls -Wundef -Wwrite-strings -Wmissing-prototypes \
9+
| -Wold-style-declaration -Wold-style-definition -Wtype-limits -Wformat-security \
10+
| -Wformat-y2k -Winit-self -Wignored-qualifiers -Wempty-body -Wnested-externs \
11+
| -Wendif-labels -Wexpansion-to-defined -Wimplicit-fallthrough=2 -Wno-missing-include-dirs \
12+
| -Wno-shift-negative-value -Wno-psabi -fno-pie -ffreestanding -IQEMU/include \
13+
| -fno-stack-protector -m16 -Wa,-32 \
14+
| -c QEMU/pc-bios/optionrom/linuxboot_dma.c -o linuxboot_dma.o
15+
|cc1: error: ‘-fcf-protection’ is not compatible with this target
16+
17+
Signed-off-by: Vineet Gupta <[email protected]>
18+
---
19+
This might be a crude fix to the problem
20+
---
21+
pc-bios/optionrom/Makefile | 3 +++
22+
1 file changed, 3 insertions(+)
23+
24+
diff --git a/pc-bios/optionrom/Makefile b/pc-bios/optionrom/Makefile
25+
index 5d55d25acca2..8f843ee803c1 100644
26+
--- a/pc-bios/optionrom/Makefile
27+
+++ b/pc-bios/optionrom/Makefile
28+
@@ -22,6 +22,9 @@ override CFLAGS += $(CFLAGS_NOPIE) -ffreestanding -I$(TOPSRC_DIR)/include
29+
override CFLAGS += $(call cc-option, -fno-stack-protector)
30+
override CFLAGS += $(call cc-option, -m16)
31+
32+
+# issue with gcc 11.2
33+
+override CFLAGS += $(call cc-option, -fcf-protection=none)
34+
+
35+
ifeq ($(filter -m16, $(CFLAGS)),)
36+
# Attempt to work around compilers that lack -m16 (GCC <= 4.8, clang <= ??)
37+
# On GCC we add -fno-toplevel-reorder to keep the order of asm blocks with

0 commit comments

Comments
 (0)