Skip to contentSkip to conversation

riscv: Extend CI

PATCH In review Andrew Jones 1 participant 6 messages Aug 8, 2024 – Aug 12, 2024

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

v2 cover riscv: Extend CI

So far we were only building and testing 64-bit, non-efi in the CI for riscv. I had mistakenly thought Fedora's riscv compiler could only build 64-bit, but it's multilib so we just need to add some CFLAGS to get it to work. To preserve building with a 32-bit-only riscv compiler we need to introduce limits.h to our tiny libc. And, while adding 32-bit builds to CI we also add EFI builds so now we test 32-bit, 64-bit, and 64-bit EFI. And, since Fedora has been udpated, bringing in a later QEMU, we can now do the testing with the 'max' cpu type.

v2:
- *Actually* test out-of-tree builds in the rv32 CI (I was missing a few important lines, like 'cd build'...
- Add another patch to fix out-of-tree builds for riscv
- Added some indentation in the new limits.h

Andrew Jones (4):
lib: Add limits.h
riscv: Build with explicit ABI
riscv: Fix out-of-tree builds
riscv: Extend gitlab CI

 .gitlab-ci.yml | 36 +++++++++++++++++++++++++++++++-----
 configure      |  8 ++++++--
 lib/limits.h   | 43 +++++++++++++++++++++++++++++++++++++++++++
 riscv/Makefile | 12 +++++++-----
 4 files changed, 87 insertions(+), 12 deletions(-)
 create mode 100644 lib/limits.h
Signature · 1 line
2.45.2
#1 lore raw

PATCH v2 1/4 lib: Add limits.h

We already include limits.h from a couple places (libfdt and the sbi test for riscv). We should provide our own limits.h rather than depend on the build environment as some cross environments may not support it (building riscv with a ilp32d toolchain fails, for example).

We guard each definition to ensure we only provide them when the sizes match our expectations. If something is strange then the define won't be created, and either the includer won't notice since it wasn't used or the build will break and limits.h can be extended.

---
 lib/limits.h | 43 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 43 insertions(+)
 create mode 100644 lib/limits.h
lib/limits.h new file +43 -0
new file mode 100644
index 000000000000..650085c68e5d
@@ -0,0 +1,43 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+#ifndef _LIMITS_H_
+#define _LIMITS_H_
+
+#if __CHAR_BIT__ == 8
+# if __CHAR_UNSIGNED__
+#  define CHAR_MIN	0
+#  define CHAR_MAX	__UINT8_MAX__
+# else
+#  define CHAR_MAX	__INT8_MAX__
+#  define CHAR_MIN	(-CHAR_MAX - 1)
+# endif
+#endif
+
+#if __SHRT_WIDTH__ == 16
+# define SHRT_MAX	__INT16_MAX__
+# define SHRT_MIN	(-SHRT_MAX - 1)
+# define USHRT_MAX	__UINT16_MAX__
+#endif
+
+#if __INT_WIDTH__ == 32
+# define INT_MAX	__INT32_MAX__
+# define INT_MIN	(-INT_MAX - 1)
+# define UINT_MAX	__UINT32_MAX__
+#endif
+
+#if __LONG_WIDTH__ == 64
+# define LONG_MAX	__INT64_MAX__
+# define LONG_MIN	(-LONG_MAX - 1)
+# define ULONG_MAX	__UINT64_MAX__
+#elif __LONG_WIDTH__ == 32
+# define LONG_MAX	__INT32_MAX__
+# define LONG_MIN	(-LONG_MAX - 1)
+# define ULONG_MAX	__UINT32_MAX__
+#endif
+
+#if __LONG_LONG_WIDTH__ == 64
+# define LLONG_MAX	__INT64_MAX__
+# define LLONG_MIN	(-LLONG_MAX - 1)
+# define ULLONG_MAX	__UINT64_MAX__
+#endif
+
+#endif /* _LIMITS_H_ */
Signature · 1 line
2.45.2
#2 lore raw

PATCH v2 2/4 riscv: Build with explicit ABI

In reply to Andrew Jones

If we add -mabi to the command line then compilers that are built to support multiple ABIs may be used for both rv32 and rv64 builds, so add it for that reason. We also need the right linker flags, so add those too and throw in a trimming of the ISA string (drop fd) in order to keep it minimal.

---
 riscv/Makefile | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
riscv/Makefile +6 -4
index b0cd613fcd8c..7906cef7f199 100644
@@ -64,13 +64,15 @@ define arch_elf_check =
 		$(error $(1) has unsupported reloc types))
 endef
 
-ISA_COMMON = mafdc_zicsr_zifencei_zihintpause
+ISA_COMMON = imac_zicsr_zifencei_zihintpause
 
 ifeq ($(ARCH),riscv64)
-CFLAGS += -march=rv64i$(ISA_COMMON)
-CFLAGS += -DCONFIG_64BIT
+CFLAGS  += -DCONFIG_64BIT
+CFLAGS  += -mabi=lp64 -march=rv64$(ISA_COMMON)
+LDFLAGS += -melf64lriscv
 else ifeq ($(ARCH),riscv32)
-CFLAGS += -march=rv32i$(ISA_COMMON)
+CFLAGS  += -mabi=ilp32 -march=rv32$(ISA_COMMON)
+LDFLAGS += -melf32lriscv
 endif
 CFLAGS += -DCONFIG_RELOC
 CFLAGS += -mcmodel=medany
Signature · 1 line
2.45.2
#3 lore raw

PATCH v2 3/4 riscv: Fix out-of-tree builds

In reply to Andrew Jones

My riscv compiler doesn't seem to want to create directories as other compilers are apparently doing. There's only a few of them, so let's just manually create them in configure. And riscv also needed '-I lib' in CFLAGS.

---
 configure      | 8 ++++++--
 riscv/Makefile | 2 +-
 2 files changed, 7 insertions(+), 3 deletions(-)
configure +6 -2
index db15e85d6ac7..27ae9cc89657 100755
@@ -418,12 +418,16 @@ rm -f lib/asm
 asm="asm-generic"
 if [ -d "$srcdir/lib/$arch/asm" ]; then
 	asm="$srcdir/lib/$arch/asm"
+	mkdir -p "lib/$arch"
+elif [ -d "$srcdir/lib/$arch_libdir/asm" ]; then
+	asm="$srcdir/lib/$arch_libdir/asm"
+	mkdir -p "lib/$arch_libdir"
 elif [ -d "$srcdir/lib/$testdir/asm" ]; then
 	asm="$srcdir/lib/$testdir/asm"
+	mkdir -p "lib/$testdir"
 fi
-mkdir -p lib
 ln -sf "$asm" lib/asm
-
+mkdir -p lib/generated lib/libfdt
 
 # create the config
 cat <<EOF > config.mak
riscv/Makefile +1 -1
index 7906cef7f199..179a373dbacf 100644
@@ -80,7 +80,7 @@ CFLAGS += -mstrict-align
 CFLAGS += -std=gnu99
 CFLAGS += -ffreestanding
 CFLAGS += -O2
-CFLAGS += -I $(SRCDIR)/lib -I $(SRCDIR)/lib/libfdt
+CFLAGS += -I $(SRCDIR)/lib -I $(SRCDIR)/lib/libfdt -I lib
 
 asm-offsets = lib/riscv/asm-offsets.h
 include $(SRCDIR)/scripts/asm-offsets.mak
Signature · 1 line
2.45.2
#4 lore raw

PATCH v2 4/4 riscv: Extend gitlab CI

In reply to Andrew Jones

Fedora's riscv64 gcc supports ilp32 so enable 32-bit RISCV testing. And use the out-of-tree template for the 32-bit build to get that covered too. Also add EFI build testing and, since Fedora has been updated which brings in a later QEMU, we can now use the 'max' cpu type.

---
 .gitlab-ci.yml | 36 +++++++++++++++++++++++++++++++-----
 1 file changed, 31 insertions(+), 5 deletions(-)
.gitlab-ci.yml +31 -5
index e0eb85a94910..180ef6e78558 100644
@@ -133,18 +133,44 @@ build-ppc64le:
       | tee results.txt
  - if grep -q FAIL results.txt ; then exit 1 ; fi
 
-# build-riscv32:
-# Fedora doesn't package a riscv32 compiler for QEMU. Oh, well.
+build-riscv32:
+ extends: .outoftree_template
+ script:
+ - dnf install -y qemu-system-riscv gcc-riscv64-linux-gnu
+ - mkdir build
+ - cd build
+ - ../configure --arch=riscv32 --cross-prefix=riscv64-linux-gnu-
+ - make -j2
+ - printf "FOO=foo\nBAR=bar\nBAZ=baz\nMVENDORID=0\nMARCHID=0\nMIMPID=0\n" >test-env
+ - ACCEL=tcg KVM_UNIT_TESTS_ENV=test-env ./run_tests.sh
+      selftest
+      sbi
+      | tee results.txt
+ - grep -q PASS results.txt && ! grep -q FAIL results.txt
 
-# Select 'rv64' with PROCESSOR_OVERRIDE in case QEMU is too old to have 'max'
 build-riscv64:
  extends: .intree_template
  script:
  - dnf install -y qemu-system-riscv gcc-riscv64-linux-gnu
  - ./configure --arch=riscv64 --cross-prefix=riscv64-linux-gnu-
  - make -j2
- - printf "FOO=foo\nBAR=bar\nBAZ=baz\nMVENDORID=0\n" >test-env
- - PROCESSOR_OVERRIDE=rv64 ACCEL=tcg KVM_UNIT_TESTS_ENV=test-env ./run_tests.sh
+ - printf "FOO=foo\nBAR=bar\nBAZ=baz\nMVENDORID=0\nMARCHID=0\nMIMPID=0\n" >test-env
+ - ACCEL=tcg KVM_UNIT_TESTS_ENV=test-env ./run_tests.sh
+      selftest
+      sbi
+      | tee results.txt
+ - grep -q PASS results.txt && ! grep -q FAIL results.txt
+
+build-riscv64-efi:
+ extends: .intree_template
+ script:
+ - dnf install -y edk2-riscv64 qemu-system-riscv gcc-riscv64-linux-gnu
+ - cp /usr/share/edk2/riscv/RISCV_VIRT_CODE.fd .
+ - truncate -s 32M RISCV_VIRT_CODE.fd
+ - ./configure --arch=riscv64 --cross-prefix=riscv64-linux-gnu- --enable-efi
+ - make -j2
+ - printf "FOO=foo\nBAR=bar\nBAZ=baz\nMVENDORID=0\nMARCHID=0\nMIMPID=0\n" >test-env
+ - ACCEL=tcg KVM_UNIT_TESTS_ENV=test-env ./run_tests.sh
       selftest
       sbi
       | tee results.txt
Signature · 1 line
2.45.2
#5 lore raw
In reply to Andrew Jones
Quoted 21 lines · Andrew Jones

So far we were only building and testing 64-bit, non-efi in the CI for riscv. I had mistakenly thought Fedora's riscv compiler could only build 64-bit, but it's multilib so we just need to add some CFLAGS to get it to work. To preserve building with a 32-bit-only riscv compiler we need to introduce limits.h to our tiny libc. And, while adding 32-bit builds to CI we also add EFI builds so now we test 32-bit, 64-bit, and 64-bit EFI. And, since Fedora has been udpated, bringing in a later QEMU, we can now do the testing with the 'max' cpu type.

v2:
- *Actually* test out-of-tree builds in the rv32 CI (I was missing a few important lines, like 'cd build'...
- Add another patch to fix out-of-tree builds for riscv
- Added some indentation in the new limits.h

Andrew Jones (4):
lib: Add limits.h
riscv: Build with explicit ABI
riscv: Fix out-of-tree builds
riscv: Extend gitlab CI

Quoted 10 lines
 .gitlab-ci.yml | 36 +++++++++++++++++++++++++++++++-----
 configure      |  8 ++++++--
 lib/limits.h   | 43 +++++++++++++++++++++++++++++++++++++++++++
 riscv/Makefile | 12 +++++++-----
 4 files changed, 87 insertions(+), 12 deletions(-)
 create mode 100644 lib/limits.h
Signature · 1 line
2.45.2

Queued on riscv/queue, https://gitlab.com/jones-drew/kvm-unit-tests/-/commits/riscv%2Fqueue

drew