Always compile the kvm-unit-tests with -fno-common
Subsystems (3)
PATCH 1/1 Always compile the kvm-unit-tests with -fno-common
The new GCC v10 uses -fno-common by default. To avoid that we commit code that declares global variables twice and thus fails to link with the latest version, we should also compile with -fno-common when using older versions of the compiler.
--- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Makefile +1 -1
@@ -49,7 +49,7 @@ include $(SRCDIR)/$(TEST_DIR)/Makefile cc-option = $(shell if $(CC) -Werror $(1) -S -o /dev/null -xc /dev/null \ > /dev/null 2>&1; then echo "$(1)"; else echo "$(2)"; fi ;) -COMMON_CFLAGS += -g $(autodepend-flags) -fno-strict-aliasing +COMMON_CFLAGS += -g $(autodepend-flags) -fno-strict-aliasing -fno-common COMMON_CFLAGS += -Wall -Wwrite-strings -Wempty-body -Wuninitialized COMMON_CFLAGS += -Wignored-qualifiers -Werror
Signature · 1 line
2.18.1
Quoted 15 lines · Thomas Huth
The new GCC v10 uses -fno-common by default. To avoid that we commit code that declares global variables twice and thus fails to link with the latest version, we should also compile with -fno-common when using older versions of the compiler.
Signed-off-by Thomas Huth <[email protected]>--- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)Makefile +0
-0
Makefile include $(SRCDIR)/$(TEST_DIR)/Makefile · line 52
Quoted 5 lines
Makefile +1
-1@@ -49,7 +49,7 @@ include $(SRCDIR)/$(TEST_DIR)/Makefile cc-option = $(shell if $(CC) -Werror $(1) -S -o /dev/null -xc /dev/null \ > /dev/null 2>&1; then echo "$(1)"; else echo "$(2)"; fi ;) -COMMON_CFLAGS += -g $(autodepend-flags) -fno-strict-aliasing +COMMON_CFLAGS += -g $(autodepend-flags) -fno-strict-aliasing -fno-common
Oh, wait, this breaks the non-x86 builds due to "extern-less" struct auxinfo auxinfo in libauxinfo.h !
Drew, why isn't this declared in auxinfo.c instead?
Thomas
Quoted 19 lines · Thomas Huth
Quoted 18 lines · Thomas Huth
The new GCC v10 uses -fno-common by default. To avoid that we commit code that declares global variables twice and thus fails to link with the latest version, we should also compile with -fno-common when using older versions of the compiler.
Signed-off-by Thomas Huth <[email protected]>--- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)Makefile +0
-0@@ -49,7 +49,7 @@ include $(SRCDIR)/$(TEST_DIR)/Makefile cc-option = $(shell if $(CC) -Werror $(1) -S -o /dev/null -xc /dev/null \ > /dev/null 2>&1; then echo "$(1)"; else echo "$(2)"; fi ;)
Quoted 6 lines
Makefile include $(SRCDIR)/$(TEST_DIR)/Makefile · line 52
Quoted 2 lines
Makefile +1
-1-COMMON_CFLAGS += -g $(autodepend-flags) -fno-strict-aliasing +COMMON_CFLAGS += -g $(autodepend-flags) -fno-strict-aliasing -fno-commonOh, wait, this breaks the non-x86 builds due to "extern-less" struct auxinfo auxinfo in
libauxinfo.h!
Drew, why isn't this declared inauxinfo.cinstead?
Oh well, it's there ... so we're playing tricks with the linker here? I guess adding a "__attribute__((common, weak))" to auxinfo.h will be ok to fix this issue?
Thomas
Quoted 27 lines · Thomas Huth
Quoted 19 lines · Thomas Huth
Quoted 18 lines · Thomas Huth
The new GCC v10 uses -fno-common by default. To avoid that we commit code that declares global variables twice and thus fails to link with the latest version, we should also compile with -fno-common when using older versions of the compiler.
Signed-off-by Thomas Huth <[email protected]>--- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)Makefile +0
-0@@ -49,7 +49,7 @@ include $(SRCDIR)/$(TEST_DIR)/Makefile cc-option = $(shell if $(CC) -Werror $(1) -S -o /dev/null -xc /dev/null \ > /dev/null 2>&1; then echo "$(1)"; else echo "$(2)"; fi ;)Quoted 6 lines
Makefile include $(SRCDIR)/$(TEST_DIR)/Makefile · line 52
Quoted 2 lines
Makefile +1
-1-COMMON_CFLAGS += -g $(autodepend-flags) -fno-strict-aliasing +COMMON_CFLAGS += -g $(autodepend-flags) -fno-strict-aliasing -fno-commonOh, wait, this breaks the non-x86 builds due to "extern-less" struct auxinfo auxinfo in
libauxinfo.h!
Drew, why isn't this declared inauxinfo.cinstead?
Quoted 3 lines
Oh well, it's there ... so we're playing tricks with the linker here? I guess adding a "
__attribute__((common, weak))" toauxinfo.hwill be ok to fix this issue?
Right. In lib/auxinfo.h we have
/* No extern! Define a common symbol. */
struct auxinfo auxinfo;
Despite git-blame giving me credit for the 'No extern' comment (and the missing 'extern'), I think Paolo made those changes when applying the patch. I presume he did so to fix compilation on x86, for which I presume the problem was that lib/argv.c references auxinfo, and that resulted in an undefined symbol, since x86 doesn't link to auxinfo.o.
Unfortunately making the symbol weak won't work because if we add it to the definition in auxinfo.h, then the linker prefers using its own zero-initialized, global symbol. And, if we add the attribute to the definition in auxinfo.c, then we still get the multiple definition error.
So I'm not really sure what the best thing to do is. Maybe we should just do this
lib/auxinfo.h +1 -2
@@ -13,7 +13,6 @@ struct auxinfo {unsigned long flags; }; -/* No extern! Define a common symbol. */ -struct auxinfo auxinfo; +extern struct auxinfo auxinfo;#endif #endif
x86/Makefile.common +1 -0
@@ -5,6 +5,7 @@ all: directories test_cases cflatobjs += lib/pci.o cflatobjs += lib/pci-edu.o cflatobjs += lib/alloc.o +cflatobjs += lib/auxinfo.o cflatobjs += lib/vmalloc.o cflatobjs += lib/alloc_page.o cflatobjs += lib/alloc_phys.o
Thanks,
drew
Paolo Bonzini
maintainerQuoted 27 lines · Andrew Jones
lib/auxinfo.h +1
-2@@ -13,7 +13,6 @@ struct auxinfo {unsigned long flags; }; -/* No extern! Define a common symbol. */ -struct auxinfo auxinfo; +extern struct auxinfo auxinfo;#endif #endif x86/Makefile.common +1
-0@@ -5,6 +5,7 @@ all: directories test_cases cflatobjs += lib/pci.o cflatobjs += lib/pci-edu.o cflatobjs += lib/alloc.o +cflatobjs += lib/auxinfo.o cflatobjs += lib/vmalloc.o cflatobjs += lib/alloc_page.o cflatobjs += lib/alloc_phys.o
Quoted 3 lines
Thanks,
drew
Yes, this sounds good.