kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [kvm-unit-tests PATCH] Always compile the kvm-unit-tests with -fno-common
@ 2020-05-12  9:55 Thomas Huth
  2020-05-13 10:05 ` Thomas Huth
  0 siblings, 1 reply; 5+ messages in thread
From: Thomas Huth @ 2020-05-12  9:55 UTC (permalink / raw)
  To: kvm, Paolo Bonzini; +Cc: dgilbert

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 <thuth@redhat.com>
---
 Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Makefile b/Makefile
index 754ed65..3ff2f91 100644
--- a/Makefile
+++ b/Makefile
@@ -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
 
-- 
2.18.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [kvm-unit-tests PATCH] Always compile the kvm-unit-tests with -fno-common
  2020-05-12  9:55 [kvm-unit-tests PATCH] Always compile the kvm-unit-tests with -fno-common Thomas Huth
@ 2020-05-13 10:05 ` Thomas Huth
  2020-05-13 10:11   ` Thomas Huth
  0 siblings, 1 reply; 5+ messages in thread
From: Thomas Huth @ 2020-05-13 10:05 UTC (permalink / raw)
  To: kvm, Paolo Bonzini, Andrew Jones; +Cc: dgilbert

On 12/05/2020 11.55, Thomas Huth wrote:
> 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 <thuth@redhat.com>
> ---
>  Makefile | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/Makefile b/Makefile
> index 754ed65..3ff2f91 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -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


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [kvm-unit-tests PATCH] Always compile the kvm-unit-tests with -fno-common
  2020-05-13 10:05 ` Thomas Huth
@ 2020-05-13 10:11   ` Thomas Huth
  2020-05-14  7:33     ` Andrew Jones
  0 siblings, 1 reply; 5+ messages in thread
From: Thomas Huth @ 2020-05-13 10:11 UTC (permalink / raw)
  To: kvm, Paolo Bonzini, Andrew Jones; +Cc: dgilbert

On 13/05/2020 12.05, Thomas Huth wrote:
> On 12/05/2020 11.55, Thomas Huth wrote:
>> 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 <thuth@redhat.com>
>> ---
>>  Makefile | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/Makefile b/Makefile
>> index 754ed65..3ff2f91 100644
>> --- a/Makefile
>> +++ b/Makefile
>> @@ -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?

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


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [kvm-unit-tests PATCH] Always compile the kvm-unit-tests with -fno-common
  2020-05-13 10:11   ` Thomas Huth
@ 2020-05-14  7:33     ` Andrew Jones
  2020-05-14  7:37       ` Paolo Bonzini
  0 siblings, 1 reply; 5+ messages in thread
From: Andrew Jones @ 2020-05-14  7:33 UTC (permalink / raw)
  To: Thomas Huth; +Cc: kvm, Paolo Bonzini, dgilbert

On Wed, May 13, 2020 at 12:11:39PM +0200, Thomas Huth wrote:
> On 13/05/2020 12.05, Thomas Huth wrote:
> > On 12/05/2020 11.55, Thomas Huth wrote:
> >> 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 <thuth@redhat.com>
> >> ---
> >>  Makefile | 2 +-
> >>  1 file changed, 1 insertion(+), 1 deletion(-)
> >>
> >> diff --git a/Makefile b/Makefile
> >> index 754ed65..3ff2f91 100644
> >> --- a/Makefile
> >> +++ b/Makefile
> >> @@ -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?
> 
> 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?

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


diff --git a/lib/auxinfo.h b/lib/auxinfo.h
index 08b96f8ece4c..a46a1e6f6a62 100644
--- a/lib/auxinfo.h
+++ b/lib/auxinfo.h
@@ -13,7 +13,6 @@ struct auxinfo {
        unsigned long flags;
 };
 
-/* No extern!  Define a common symbol.  */
-struct auxinfo auxinfo;
+extern struct auxinfo auxinfo;
 #endif
 #endif
diff --git a/x86/Makefile.common b/x86/Makefile.common
index ab67ca0a9fda..2ea9c9f5bbcc 100644
--- a/x86/Makefile.common
+++ b/x86/Makefile.common
@@ -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


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [kvm-unit-tests PATCH] Always compile the kvm-unit-tests with -fno-common
  2020-05-14  7:33     ` Andrew Jones
@ 2020-05-14  7:37       ` Paolo Bonzini
  0 siblings, 0 replies; 5+ messages in thread
From: Paolo Bonzini @ 2020-05-14  7:37 UTC (permalink / raw)
  To: Andrew Jones, Thomas Huth; +Cc: kvm, dgilbert

On 14/05/20 09:33, Andrew Jones wrote:
> diff --git a/lib/auxinfo.h b/lib/auxinfo.h
> index 08b96f8ece4c..a46a1e6f6a62 100644
> --- a/lib/auxinfo.h
> +++ b/lib/auxinfo.h
> @@ -13,7 +13,6 @@ struct auxinfo {
>         unsigned long flags;
>  };
>  
> -/* No extern!  Define a common symbol.  */
> -struct auxinfo auxinfo;
> +extern struct auxinfo auxinfo;
>  #endif
>  #endif
> diff --git a/x86/Makefile.common b/x86/Makefile.common
> index ab67ca0a9fda..2ea9c9f5bbcc 100644
> --- a/x86/Makefile.common
> +++ b/x86/Makefile.common
> @@ -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
> 

Yes, this sounds good.


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2020-05-14  7:37 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-12  9:55 [kvm-unit-tests PATCH] Always compile the kvm-unit-tests with -fno-common Thomas Huth
2020-05-13 10:05 ` Thomas Huth
2020-05-13 10:11   ` Thomas Huth
2020-05-14  7:33     ` Andrew Jones
2020-05-14  7:37       ` Paolo Bonzini

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).