Skip to content

Commit 40be630

Browse files
author
Julien Grall
committed
Only compile the hypervisor with -Wdeclaration-after-statement
Right now, all tools and hypervisor will be complied with the option -Wdeclaration-after-statement. While most of the code in the hypervisor is controlled by us, for tools we may import external libraries. The build will fail if one of them are using the construct we are trying to prevent. This is the case when building against Python 3.12 and Yocto: | In file included from /srv/storage/alex/yocto/build-virt/tmp/work/core2-64-poky-linux/xen-tools/4.17+stable/recipe-sysroot/usr/include/python3.12/Python.h:44, | from xen/lowlevel/xc/xc.c:8: | /srv/storage/alex/yocto/build-virt/tmp/work/core2-64-poky-linux/xen-tools/4.17+stable/recipe-sysroot/usr/include/python3.12/object.h: In function 'Py_SIZE': | /srv/storage/alex/yocto/build-virt/tmp/work/core2-64-poky-linux/xen-tools/4.17+stable/recipe-sysroot/usr/include/python3.12/object.h:233:5: error: ISO C90 forbids mixed declarations and code [-Werror=declaration-after-statement] | 233 | PyVarObject *var_ob = _PyVarObject_CAST(ob); | | ^~~~~~~~~~~ | In file included from /srv/storage/alex/yocto/build-virt/tmp/work/core2-64-poky-linux/xen-tools/4.17+stable/recipe-sysroot/usr/include/python3.12/Python.h:53: | /srv/storage/alex/yocto/build-virt/tmp/work/core2-64-poky-linux/xen-tools/4.17+stable/recipe-sysroot/usr/include/python3.12/cpython/longintrepr.h: In function '_PyLong_CompactValue': | /srv/storage/alex/yocto/build-virt/tmp/work/core2-64-poky-linux/xen-tools/4.17+stable/recipe-sysroot/usr/include/python3.12/cpython/longintrepr.h:121:5: error: ISO C90 forbids mixed declarations and code [-Werror=declaration-after-statement] | 121 | Py_ssize_t sign = 1 - (op->long_value.lv_tag & _PyLong_SIGN_MASK); | | ^~~~~~~~~~ | cc1: all warnings being treated as errors Looking at the tools directory, a fair few directory already add -Wno-declaration-after-statement to inhibit the default behavior. We have always build the hypervisor with the flag, so for now remove only the flag for anything but the hypervisor. We can decide at later time whether we want to relax. Also remove the -Wno-declaration-after-statement in some subdirectory as the flag is now unnecessary. Part of the commit message was take from Alexander's first proposal: Link: https://lore.kernel.org/xen-devel/20231128174729.3880113-1-alex@linutronix.de/ Reported-by: Alexander Kanavin <alex@linutronix.de> Acked-by: Anthony PERARD <anthony.perard@citrix.com> Acked-by: Andrew Cooper <andrew.cooper3@citrix.com> Tested-by: Jason Andryuk <jandryuk@gmail.com> Signed-off-by: Julien Grall <jgrall@amazon.com>
1 parent 59df285 commit 40be630

File tree

8 files changed

+6
-12
lines changed

8 files changed

+6
-12
lines changed

Config.mk

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,6 @@ CFLAGS += -std=gnu99
177177

178178
CFLAGS += -Wall -Wstrict-prototypes
179179

180-
$(call cc-option-add,HOSTCFLAGS,HOSTCC,-Wdeclaration-after-statement)
181-
$(call cc-option-add,CFLAGS,CC,-Wdeclaration-after-statement)
182180
$(call cc-option-add,CFLAGS,CC,-Wno-unused-but-set-variable)
183181
$(call cc-option-add,CFLAGS,CC,-Wno-unused-local-typedefs)
184182

stubdom/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ tpm_emulator-$(XEN_TARGET_ARCH): tpm_emulator-$(TPMEMU_VERSION).tar.gz
245245
patch -d $@ -p1 < vtpm-command-duration.patch
246246
patch -d $@ -p1 < vtpm-tpm_bn_t-addr.patch
247247
mkdir $@/build
248-
cd $@/build; CC=${CC} $(CMAKE) .. -DCMAKE_C_FLAGS:STRING="-std=c99 -DTPM_NO_EXTERN $(TARGET_CPPFLAGS) $(TARGET_CFLAGS) -Wno-declaration-after-statement"
248+
cd $@/build; CC=${CC} $(CMAKE) .. -DCMAKE_C_FLAGS:STRING="-std=c99 -DTPM_NO_EXTERN $(TARGET_CPPFLAGS) $(TARGET_CFLAGS)"
249249
touch $@
250250

251251
TPMEMU_STAMPFILE=$(CROSS_ROOT)/$(GNU_TARGET_ARCH)-xen-elf/lib/libtpm.a

stubdom/vtpmmgr/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ OBJS += vtpm_disk.o disk_tpm.o disk_io.o disk_crypto.o disk_read.o disk_write.o
1717
OBJS += mgmt_authority.o
1818

1919
CFLAGS+=-Werror -Iutil -Icrypto -Itcs
20-
CFLAGS+=-Wno-declaration-after-statement -Wno-unused-label
20+
CFLAGS+=-Wno-unused-label
2121

2222
build: $(TARGET)
2323
$(TARGET): $(OBJS)

tools/libs/light/Makefile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@ vpath static_tables.c $(ACPI_PATH)/
3838

3939
OBJS-$(CONFIG_X86) += $(ACPI_OBJS)
4040

41-
CFLAGS += -Wno-format-zero-length -Wmissing-declarations \
42-
-Wno-declaration-after-statement -Wformat-nonliteral
41+
CFLAGS += -Wno-format-zero-length -Wmissing-declarations -Wformat-nonliteral
4342

4443
CFLAGS-$(CONFIG_X86) += -DCONFIG_PCI_SUPP_LEGACY_IRQ
4544

tools/libs/util/Makefile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ OBJS-y += libxlu_disk.o
99
OBJS-y += libxlu_vif.o
1010
OBJS-y += libxlu_pci.o
1111

12-
CFLAGS += -Wno-format-zero-length -Wmissing-declarations \
13-
-Wno-declaration-after-statement -Wformat-nonliteral
12+
CFLAGS += -Wno-format-zero-length -Wmissing-declarations -Wformat-nonliteral
1413
CFLAGS += $(CFLAGS_libxenctrl)
1514

1615
CFLAGS += $(PTHREAD_CFLAGS)

tools/tests/depriv/Makefile

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
XEN_ROOT=$(CURDIR)/../../..
22
include $(XEN_ROOT)/tools/Rules.mk
33

4-
CFLAGS += -Wno-declaration-after-statement
5-
64
CFLAGS += $(CFLAGS_xeninclude)
75
CFLAGS += $(CFLAGS_libxenctrl)
86
CFLAGS += $(CFLAGS_libxencall)

tools/xl/Makefile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
XEN_ROOT = $(CURDIR)/../..
66
include $(XEN_ROOT)/tools/Rules.mk
77

8-
CFLAGS += -Wno-format-zero-length -Wmissing-declarations \
9-
-Wno-declaration-after-statement -Wformat-nonliteral
8+
CFLAGS += -Wno-format-zero-length -Wmissing-declarations -Wformat-nonliteral
109
CFLAGS += -fPIC
1110

1211
CFLAGS += $(PTHREAD_CFLAGS)

xen/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,7 @@ CFLAGS-$(CONFIG_CC_SPLIT_SECTIONS) += -ffunction-sections -fdata-sections
393393

394394
CFLAGS += -nostdinc -fno-builtin -fno-common
395395
CFLAGS += -Werror -Wredundant-decls -Wwrite-strings -Wno-pointer-arith
396+
$(call cc-option-add,CFLAGS,CC,-Wdeclaration-after-statement)
396397
$(call cc-option-add,CFLAGS,CC,-Wvla)
397398
CFLAGS += -pipe -D__XEN__ -include $(srctree)/include/xen/config.h
398399
CFLAGS-$(CONFIG_DEBUG_INFO) += -g

0 commit comments

Comments
 (0)