Message ID | 20200924182401.95891-1-r.bolshakov@yadro.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | [kvm-unit-tests] configure: Test if compiler supports -m16 on x86 | expand |
On 24/09/2020 20.24, Roman Bolshakov wrote: > -m16 option is available only since GCC 4.9.0 [1]. That causes a build > failure on centos-7 [2] that has GCC 4.8.5. > > Fallback to -m32 if -m16 is not available. > > 1. http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59672 > 2. https://gitlab.com/bonzini/kvm-unit-tests/-/jobs/755368387 > > Fixes: 2616ad934e2 ("x86: realmode: Workaround clang issues") > Signed-off-by: Roman Bolshakov <r.bolshakov@yadro.com> > --- > configure | 11 +++++++++++ > x86/Makefile.common | 4 ++++ > 2 files changed, 15 insertions(+) > > diff --git a/configure b/configure > index f930543..7dc2e3b 100755 > --- a/configure > +++ b/configure > @@ -16,6 +16,7 @@ pretty_print_stacks=yes > environ_default=yes > u32_long= > wa_divide= > +m16_support= > vmm="qemu" > errata_force=0 > erratatxt="$srcdir/errata.txt" > @@ -167,6 +168,15 @@ EOF > rm -f lib-test.{o,S} > fi > > +# check if -m16 is supported > +if [ "$arch" = "i386" ] || [ "$arch" = "x86_64" ]; then > + cat << EOF > lib-test.c > +int f(int a, int b) { return a + b; } > +EOF > + m16_support=$("$cross_prefix$cc" -m16 -c lib-test.c >/dev/null 2>&1 && echo yes) > + rm -f lib-test.{o,c} > +fi > + > # require enhanced getopt > getopt -T > /dev/null > if [ $? -ne 4 ]; then > @@ -224,6 +234,7 @@ ENVIRON_DEFAULT=$environ_default > ERRATATXT=$erratatxt > U32_LONG_FMT=$u32_long > WA_DIVIDE=$wa_divide > +M16_SUPPORT=$m16_support > EOF > > cat <<EOF > lib/config.h > diff --git a/x86/Makefile.common b/x86/Makefile.common > index 5567d66..553bf49 100644 > --- a/x86/Makefile.common > +++ b/x86/Makefile.common > @@ -72,7 +72,11 @@ $(TEST_DIR)/realmode.elf: $(TEST_DIR)/realmode.o > $(CC) -m32 -nostdlib -o $@ -Wl,-m,elf_i386 \ > -Wl,-T,$(SRCDIR)/$(TEST_DIR)/realmode.lds $^ > > +ifeq ($(M16_SUPPORT),yes) > $(TEST_DIR)/realmode.o: bits = 16 > +else > +$(TEST_DIR)/realmode.o: bits = 32 > +endif > > $(TEST_DIR)/kvmclock_test.elf: $(TEST_DIR)/kvmclock.o > > Reviewed-by: Thomas Huth <thuth@redhat.com>
On 24/09/20 20:24, Roman Bolshakov wrote: > -m16 option is available only since GCC 4.9.0 [1]. That causes a build > failure on centos-7 [2] that has GCC 4.8.5. > > Fallback to -m32 if -m16 is not available. > > 1. http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59672 > 2. https://gitlab.com/bonzini/kvm-unit-tests/-/jobs/755368387 > > Fixes: 2616ad934e2 ("x86: realmode: Workaround clang issues") > Signed-off-by: Roman Bolshakov <r.bolshakov@yadro.com> This is a simpler way to do it: diff --git a/x86/Makefile.common b/x86/Makefile.common index 5567d66..781dba6 100644 --- a/x86/Makefile.common +++ b/x86/Makefile.common @@ -72,7 +72,7 @@ $(TEST_DIR)/realmode.elf: $(TEST_DIR)/realmode.o $(CC) -m32 -nostdlib -o $@ -Wl,-m,elf_i386 \ -Wl,-T,$(SRCDIR)/$(TEST_DIR)/realmode.lds $^ -$(TEST_DIR)/realmode.o: bits = 16 +$(TEST_DIR)/realmode.o: bits := $(if $(call cc-option,-m16,""),16,32) $(TEST_DIR)/kvmclock_test.elf: $(TEST_DIR)/kvmclock.o It's a tiny bit slower because the check is done on every compilation, but only if realmode.o is stale. It passes CI (https://gitlab.com/bonzini/kvm-unit-tests/-/pipelines/194356382) so I plan to commit it. Paolo > --- > configure | 11 +++++++++++ > x86/Makefile.common | 4 ++++ > 2 files changed, 15 insertions(+) > > diff --git a/configure b/configure > index f930543..7dc2e3b 100755 > --- a/configure > +++ b/configure > @@ -16,6 +16,7 @@ pretty_print_stacks=yes > environ_default=yes > u32_long= > wa_divide= > +m16_support= > vmm="qemu" > errata_force=0 > erratatxt="$srcdir/errata.txt" > @@ -167,6 +168,15 @@ EOF > rm -f lib-test.{o,S} > fi > > +# check if -m16 is supported > +if [ "$arch" = "i386" ] || [ "$arch" = "x86_64" ]; then > + cat << EOF > lib-test.c > +int f(int a, int b) { return a + b; } > +EOF > + m16_support=$("$cross_prefix$cc" -m16 -c lib-test.c >/dev/null 2>&1 && echo yes) > + rm -f lib-test.{o,c} > +fi > + > # require enhanced getopt > getopt -T > /dev/null > if [ $? -ne 4 ]; then > @@ -224,6 +234,7 @@ ENVIRON_DEFAULT=$environ_default > ERRATATXT=$erratatxt > U32_LONG_FMT=$u32_long > WA_DIVIDE=$wa_divide > +M16_SUPPORT=$m16_support > EOF > > cat <<EOF > lib/config.h > diff --git a/x86/Makefile.common b/x86/Makefile.common > index 5567d66..553bf49 100644 > --- a/x86/Makefile.common > +++ b/x86/Makefile.common > @@ -72,7 +72,11 @@ $(TEST_DIR)/realmode.elf: $(TEST_DIR)/realmode.o > $(CC) -m32 -nostdlib -o $@ -Wl,-m,elf_i386 \ > -Wl,-T,$(SRCDIR)/$(TEST_DIR)/realmode.lds $^ > > +ifeq ($(M16_SUPPORT),yes) > $(TEST_DIR)/realmode.o: bits = 16 > +else > +$(TEST_DIR)/realmode.o: bits = 32 > +endif > > $(TEST_DIR)/kvmclock_test.elf: $(TEST_DIR)/kvmclock.o > >
On Fri, Sep 25, 2020 at 09:17:00AM +0200, Paolo Bonzini wrote: > On 24/09/20 20:24, Roman Bolshakov wrote: > > -m16 option is available only since GCC 4.9.0 [1]. That causes a build > > failure on centos-7 [2] that has GCC 4.8.5. > > > > Fallback to -m32 if -m16 is not available. > > > > 1. http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59672 > > 2. https://gitlab.com/bonzini/kvm-unit-tests/-/jobs/755368387 > > > > Fixes: 2616ad934e2 ("x86: realmode: Workaround clang issues") > > Signed-off-by: Roman Bolshakov <r.bolshakov@yadro.com> > > This is a simpler way to do it: > > diff --git a/x86/Makefile.common b/x86/Makefile.common > index 5567d66..781dba6 100644 > --- a/x86/Makefile.common > +++ b/x86/Makefile.common > @@ -72,7 +72,7 @@ $(TEST_DIR)/realmode.elf: $(TEST_DIR)/realmode.o > $(CC) -m32 -nostdlib -o $@ -Wl,-m,elf_i386 \ > -Wl,-T,$(SRCDIR)/$(TEST_DIR)/realmode.lds $^ > > -$(TEST_DIR)/realmode.o: bits = 16 > +$(TEST_DIR)/realmode.o: bits := $(if $(call cc-option,-m16,""),16,32) > > $(TEST_DIR)/kvmclock_test.elf: $(TEST_DIR)/kvmclock.o > > It's a tiny bit slower because the check is done on every compilation, > but only if realmode.o is stale. > > It passes CI (https://gitlab.com/bonzini/kvm-unit-tests/-/pipelines/194356382) > so I plan to commit it. > That's fine, Reviewed-by: Roman Bolshakov <r.bolshakov@yadro.com> Thanks, Roman
diff --git a/configure b/configure index f930543..7dc2e3b 100755 --- a/configure +++ b/configure @@ -16,6 +16,7 @@ pretty_print_stacks=yes environ_default=yes u32_long= wa_divide= +m16_support= vmm="qemu" errata_force=0 erratatxt="$srcdir/errata.txt" @@ -167,6 +168,15 @@ EOF rm -f lib-test.{o,S} fi +# check if -m16 is supported +if [ "$arch" = "i386" ] || [ "$arch" = "x86_64" ]; then + cat << EOF > lib-test.c +int f(int a, int b) { return a + b; } +EOF + m16_support=$("$cross_prefix$cc" -m16 -c lib-test.c >/dev/null 2>&1 && echo yes) + rm -f lib-test.{o,c} +fi + # require enhanced getopt getopt -T > /dev/null if [ $? -ne 4 ]; then @@ -224,6 +234,7 @@ ENVIRON_DEFAULT=$environ_default ERRATATXT=$erratatxt U32_LONG_FMT=$u32_long WA_DIVIDE=$wa_divide +M16_SUPPORT=$m16_support EOF cat <<EOF > lib/config.h diff --git a/x86/Makefile.common b/x86/Makefile.common index 5567d66..553bf49 100644 --- a/x86/Makefile.common +++ b/x86/Makefile.common @@ -72,7 +72,11 @@ $(TEST_DIR)/realmode.elf: $(TEST_DIR)/realmode.o $(CC) -m32 -nostdlib -o $@ -Wl,-m,elf_i386 \ -Wl,-T,$(SRCDIR)/$(TEST_DIR)/realmode.lds $^ +ifeq ($(M16_SUPPORT),yes) $(TEST_DIR)/realmode.o: bits = 16 +else +$(TEST_DIR)/realmode.o: bits = 32 +endif $(TEST_DIR)/kvmclock_test.elf: $(TEST_DIR)/kvmclock.o
-m16 option is available only since GCC 4.9.0 [1]. That causes a build failure on centos-7 [2] that has GCC 4.8.5. Fallback to -m32 if -m16 is not available. 1. http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59672 2. https://gitlab.com/bonzini/kvm-unit-tests/-/jobs/755368387 Fixes: 2616ad934e2 ("x86: realmode: Workaround clang issues") Signed-off-by: Roman Bolshakov <r.bolshakov@yadro.com> --- configure | 11 +++++++++++ x86/Makefile.common | 4 ++++ 2 files changed, 15 insertions(+)