Test compiling with Clang in the Travis-CI
cover Test compiling with Clang in the Travis-CI
Travis-CI recently changed their policy so that builds on the non-x86 build machines are possible without consuming any credits again. While we're already testing the non-x86 builds in the gitlab-CI with the GCC cross-compilers, we could still benefit from the non-x86 builders in the Travis-CI by compiling the code with Clang there, too (since there are AFAIK no Clang cross-compilers available in the usual distros on x86).
Thomas Huth (4):
configure: Add the possibility to specify additional cflags
powerpc: Probe whether the compiler understands -mabi=no-altivec lib/s390x: Fix the epsw inline assembly
Test compilation with Clang on aarch64, ppc64le and s390x in Travis-CI
.travis.yml | 44 ++++++++++++++++++++++++++++++++++++++++ Makefile | 3 --- configure | 10 +++++++-- lib/s390x/asm/arch_def.h | 2 +- powerpc/Makefile.common | 4 +++- 5 files changed, 56 insertions(+), 7 deletions(-) create mode 100644 .travis.yml
Signature · 1 line
2.27.0
PATCH 1/4 configure: Add the possibility to specify additional cflags
For certain compilers or experiments, it might be necessary to specify additional CFLAGS for the build. Let's add an option to the configure script to specify such additional compiler flags.
--- Makefile | 3 --- configure | 10 ++++++++-- 2 files changed, 8 insertions(+), 5 deletions(-)
Makefile +0 -3
@@ -22,9 +22,6 @@ DESTDIR := $(PREFIX)/share/kvm-unit-tests/ 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 ;) -#make sure env CFLAGS variable is not used -CFLAGS = - libcflat := lib/libcflat.a cflatobjs := \ lib/argv.o \
configure +8 -2
@@ -8,6 +8,7 @@ fi srcdir=$(cd "$(dirname "$0")"; pwd) prefix=/usr/local cc=gcc +cflags= ld=ld objcopy=objcopy objdump=objdump
@@ -38,8 +39,9 @@ usage() { --target=TARGET target platform that the tests will be running on (qemu or kvmtool, default is qemu) (arm/arm64 only) --cross-prefix=PREFIX cross compiler prefix - --cc=CC c compiler to use ($cc) - --ld=LD ld linker to use ($ld) + --cc=CC c compiler to use ($cc) + --cflags=FLAGS extra options to be passed to the c compiler + --ld=LD ld linker to use ($ld) --prefix=PREFIX where to install things ($prefix) --endian=ENDIAN endianness to compile for (little or big, ppc64 only) --[enable|disable]-pretty-print-stacks
@@ -100,6 +102,9 @@ while [[ "$1" = -* ]]; do --cc) cc="$arg" ;; + --cflags) + cflags="$arg" + ;; --ld) ld="$arg" ;;
@@ -316,6 +321,7 @@ ARCH=$arch ARCH_NAME=$arch_name PROCESSOR=$processor CC=$cross_prefix$cc +CFLAGS=$cflags LD=$cross_prefix$ld OBJCOPY=$cross_prefix$objcopy OBJDUMP=$cross_prefix$objdump
Signature · 1 line
2.27.0
PATCH 2/4 powerpc: Probe whether the compiler understands -mabi=no-altivec
In reply to Thomas HuthClang does not support "-mabi=no-altivec", so let's check whether this option is supported before using it.
--- powerpc/Makefile.common | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
powerpc/Makefile.common +3 -1
@@ -17,9 +17,11 @@ all: directories $(TEST_DIR)/boot_rom.bin $(tests-all) ################################################################## +mabi_no_altivec := $(call cc-option,-mabi=no-altivec,"") + CFLAGS += -std=gnu99 CFLAGS += -ffreestanding -CFLAGS += -O2 -msoft-float -mabi=no-altivec -mno-altivec +CFLAGS += -O2 -msoft-float -mno-altivec $(mabi_no_altivec) CFLAGS += -I $(SRCDIR)/lib -I $(SRCDIR)/lib/libfdt -I lib CFLAGS += -Wa,-mregnames
Signature · 1 line
2.27.0
PATCH 3/4 lib/s390x: Fix the epsw inline assembly
In reply to Thomas HuthAccording to the Principles of Operation, the epsw instruction does not touch the second register if it is r0. With GCC we were lucky so far that it never tried to use r0 here, but when compiling the kvm-unit-tests with Clang, this indeed happens and leads to very weird crashes. Thus let's make sure to never use r0 for the second operand of the epsw instruction.
--- lib/s390x/asm/arch_def.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
lib/s390x/asm/arch_def.h +1 -1
@@ -265,7 +265,7 @@ static inline uint64_t extract_psw_mask(void) asmvolatile (" epsw %0,%1\n" - :"+r" (mask_upper),"+r" (mask_lower) : : ); + :"=r" (mask_upper),"=a" (mask_lower));return (uint64_t ) mask_upper <<32 | mask_lower; }
Signature · 1 line
2.27.0
Re: [kvm-unit-tests PATCH 3/4] lib/s390x: Fix the epsw inline assembly
Quoted 8 lines · On Tue, 22 Jun 2021 15:55:16 +0200 Thomas Huth <[email protected]> wrote:
According to the Principles of Operation, the epsw instruction does not touch the second register if it is r0. With GCC we were lucky so far that it never tried to use r0 here, but when compiling the kvm-unit-tests with Clang, this indeed happens and leads to very weird crashes. Thus let's make sure to never use r0 for the second operand of the epsw instruction.
Signed-off-by Thomas Huth <[email protected]>
maybe also mention in the patch description why you changed + to =
Quoted 17 lines
--- lib/s390x/asm/arch_def.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)lib/s390x/asm/arch_def.h +1
-1@@ -265,7 +265,7 @@ static inline uint64_t extract_psw_mask(void) asmvolatile (" epsw %0,%1\n" - :"+r" (mask_upper),"+r" (mask_lower) : : ); + :"=r" (mask_upper),"=a" (mask_lower));return (uint64_t ) mask_upper <<32 | mask_lower; }
Re: [kvm-unit-tests PATCH 3/4] lib/s390x: Fix the epsw inline assembly
Quoted 10 lines · Claudio Imbrenda
Quoted 7 lines · On Tue, 22 Jun 2021 15:55:16 +0200 Thomas Huth <[email protected]> wrote:
According to the Principles of Operation, the epsw instruction does not touch the second register if it is r0. With GCC we were lucky so far that it never tried to use r0 here, but when compiling the kvm-unit-tests with Clang, this indeed happens and leads to very weird crashes. Thus let's make sure to never use r0 for the second operand of the epsw instruction.
Quoted 5 lines
Quoted 1 line
Signed-off-by Thomas Huth <[email protected]>Reviewed-by Claudio Imbrenda <[email protected]>maybe also mention in the patch description why you changed + to =
Yes, that makes sense. I'll add something like:
While we're at it, also change the constraint modifier from "+" to "=" since these are only output parameters, not input.
Thomas
Re: [kvm-unit-tests PATCH 3/4] lib/s390x: Fix the epsw inline assembly
In reply to Thomas HuthQuoted 18 lines · Thomas Huth
According to the Principles of Operation, the epsw instruction does not touch the second register if it is r0. With GCC we were lucky so far that it never tried to use r0 here, but when compiling the kvm-unit-tests with Clang, this indeed happens and leads to very weird crashes. Thus let's make sure to never use r0 for the second operand of the epsw instruction.
Signed-off-by Thomas Huth <[email protected]>--- lib/s390x/asm/arch_def.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)lib/s390x/asm/arch_def.h +0
-0
lib/s390x/asm/arch_def.h static inline uint64_t extract_psw_mask(void) · line 271
Quoted 8 lines
lib/s390x/asm/arch_def.h +1
-1@@ -265,7 +265,7 @@ static inline uint64_t extract_psw_mask(void) asmvolatile (" epsw %0,%1\n" - :"+r" (mask_upper),"+r" (mask_lower) : : ); + :"=r" (mask_upper),"=a" (mask_lower));return (uint64_t ) mask_upper <<32 | mask_lower; }
With Claudio's nits fixed:
PATCH 4/4 Test compilation with Clang on aarch64, ppc64le and s390x in Travis-CI
In reply to Thomas HuthTravis-CI recently changed their policy so that builds on the non-x86 build machines are possible without consuming any credits again. We can use these systems to test compilation of the non-x86 code with Clang. Unfortunately, the qemu-system-s390x of Ubuntu 20.04 seems to be buggy, so that the s390x binaries cause that QEMU to crash. Thus we can only run the TCG tests for ppc64le and aarch64.
--- .travis.yml | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 .travis.yml
.travis.yml new file +44 -0
@@ -0,0 +1,44 @@ +dist: focal +language: c +cache: ccache +compiler: clang +git: + submodules: false + +jobs: + include: + + - arch: arm64 + addons: + apt_packages: qemu-system-aarch64 + env: + - CONFIG="--arch=arm64 --cc=clang" + - TESTS="cache gicv2-active gicv2-ipi gicv2-mmio gicv3-active gicv3-ipi + pci-test pmu-cycle-counter pmu-event-counter-config pmu-sw-incr + selftest-setup selftest-smp selftest-vectors-kernel + selftest-vectors-user timer" + + - arch: ppc64le + addons: + apt_packages: clang-11 qemu-system-ppc + env: + - CONFIG="--arch=ppc64 --endian=little --cc=clang-11 --cflags=-no-integrated-as" + - TESTS="emulator rtas-get-time-of-day rtas-get-time-of-day-base + rtas-set-time-of-day selftest-setup spapr_hcall" + + - arch: s390x + addons: + apt_packages: clang-11 qemu-system-s390x + env: + - CONFIG="--arch=s390x --cc=clang-11 --cflags=-no-integrated-as" + - TESTS="" + +before_script: + - mkdir -p build && cd build + - $TRAVIS_BUILD_DIR/configure $CONFIG +script: + - make -j3 + - if [ -n "$TESTS" ]; then + ACCEL="${ACCEL:-tcg}" ./run_tests.sh -v $TESTS | tee results.txt && + grep -q PASS results.txt && ! grep -q FAIL results.txt ; + fi
Signature · 1 line
2.27.0
Paolo Bonzini
maintainerQuoted 7 lines · Thomas Huth
Travis-CI recently changed their policy so that builds on the non-x86 build machines are possible without consuming any credits again. While we're already testing the non-x86 builds in the gitlab-CI with the GCC cross-compilers, we could still benefit from the non-x86 builders in the Travis-CI by compiling the code with Clang there, too (since there are AFAIK no Clang cross-compilers available in the usual distros on x86).
Looks good apart from Claudio's remark. Thanks very much!
Paolo