[RFC PATCH 0/6] Fix building of sparc/sparc32plus test cases

We didn't have any reliable way to build sparc test cases. I have found someone who ships a compiler but the binaries still don't run due to the need for CASA. I'm posting mainly for those who actually care who might want to fix up the remaining cases. Alex. Alex Bennée (6): tests/tcg: special case sparc test cases tests/tcg: special case sparc32plus test cases configure: update sparc and sparc32plus target compiler detection tests/docker: add sparc-leon-cross container image configure: enable the container fallbacks for sparc/sparc32plus docs/about: deprecate add sparc/sparc32plus-*-user docs/about/deprecated.rst | 8 ++++ configure | 11 ++++- .../dockerfiles/sparc-leon-cross.docker | 40 +++++++++++++++++ tests/tcg/Makefile.target | 9 ++-- tests/tcg/sparc/Makefile.target | 45 +++++++++++++++++++ tests/tcg/sparc32plus | 1 + 6 files changed, 108 insertions(+), 6 deletions(-) create mode 100644 tests/docker/dockerfiles/sparc-leon-cross.docker create mode 100644 tests/tcg/sparc/Makefile.target create mode 120000 tests/tcg/sparc32plus -- 2.47.2

Due to an existing bug #1771 we can't run anything we build so we have to suppress the normal multiarch build. As we can't have duplicate build rules we need to copy the bits we need from the normal multiarch Makefile so we can redefine all the run-% rules. For signals and vma-pthread they also need slightly different LDFLAGS to link to the atomic support library. Signed-off-by: Alex Bennée <alex.bennee@linaro.org> --- tests/tcg/Makefile.target | 9 ++++--- tests/tcg/sparc/Makefile.target | 45 +++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 4 deletions(-) create mode 100644 tests/tcg/sparc/Makefile.target diff --git a/tests/tcg/Makefile.target b/tests/tcg/Makefile.target index af68f11664..8bcafaaf7b 100644 --- a/tests/tcg/Makefile.target +++ b/tests/tcg/Makefile.target @@ -103,9 +103,10 @@ ifeq ($(filter %-softmmu, $(TARGET)),) # then the target. If there are common tests shared between # sub-targets (e.g. ARM & AArch64) then it is up to # $(TARGET_NAME)/Makefile.target to include the common parent -# architecture in its VPATH. However some targets are so minimal we -# can't even build the multiarch tests. -ifneq ($(filter $(TARGET_NAME),aarch64_be),) +# architecture in its VPATH. However some targets are so +# minimal/broken just include directly and skip the common multiarch +# tests Makefile. +ifeq ($(filter $(TARGET_NAME),aarch64_be sparc),$(TARGET_NAME)) -include $(SRC_PATH)/tests/tcg/$(TARGET_NAME)/Makefile.target else -include $(SRC_PATH)/tests/tcg/multiarch/Makefile.target @@ -147,7 +148,7 @@ all: $(TESTS) $(EXTRA_TESTS) RUN_TESTS=$(patsubst %,run-%, $(TESTS)) # If plugins exist also include those in the tests -ifeq ($(CONFIG_PLUGIN),y) +ifeq ($(CONFIG_PLUGIN)$(SKIP_PLUGIN_TESTS),y) PLUGIN_SRC=$(SRC_PATH)/tests/tcg/plugins PLUGIN_LIB=../plugins VPATH+=$(PLUGIN_LIB) diff --git a/tests/tcg/sparc/Makefile.target b/tests/tcg/sparc/Makefile.target new file mode 100644 index 0000000000..0b5f9e8b2d --- /dev/null +++ b/tests/tcg/sparc/Makefile.target @@ -0,0 +1,45 @@ +# -*- Mode: makefile -*- +# +# For Sparc we only have multiarch tests - however as everything is +# currently broken we have to duplicate the bits needed from the +# multiarch makefile. This can be removed if we ever get running again +# (or we deprecate the target). +# + +# Compressed copy of tests/tcg/multiarch/Makefile.target +MULTIARCH_SRC=$(SRC_PATH)/tests/tcg/multiarch +VPATH += $(MULTIARCH_SRC) +MULTIARCH_SRCS = $(notdir $(wildcard $(MULTIARCH_SRC)/*.c)) +ifeq ($(filter %-linux-user, $(TARGET)),$(TARGET)) +VPATH += $(MULTIARCH_SRC)/linux +MULTIARCH_SRCS += $(notdir $(wildcard $(MULTIARCH_SRC)/linux/*.c)) +endif +MULTIARCH_TESTS = $(MULTIARCH_SRCS:.c=) + +float_%: LDFLAGS+=-lm +float_%: float_%.c libs/float_helpers.c + $(CC) $(CFLAGS) $(EXTRA_CFLAGS) $< $(MULTIARCH_SRC)/libs/float_helpers.c -o $@ $(LDFLAGS) + +fnmsub: LDFLAGS+=-lm +testthread: LDFLAGS+=-lpthread +threadcount: LDFLAGS+=-lpthread +munmap-pthread: CFLAGS+=-pthread +munmap-pthread: LDFLAGS+=-pthread +sigreturn-sigmask: CFLAGS+=-pthread +sigreturn-sigmask: LDFLAGS+=-pthread +sha1: CFLAGS+=-Wno-stringop-overread -Wno-unknown-warning-option + +TESTS += $(MULTIARCH_TESTS) +# End of copy of multiarch/Makefile.target + +# atomic primitives used by these tests need -latomic +signals: LDFLAGS+=-lrt -lpthread -latomic +vma-pthread: CFLAGS+=-pthread +vma-pthread: LDFLAGS+=-pthread -latomic + +# all tests currently broken due to broken CASA +run-%: + $(call skip-test, $*, "CASA is broken (see bug #1771)") + +# we can't even think about plugin tests yet +SKIP_PLUGIN_TESTS=y -- 2.47.2

We can re-use the sparc Makefile to ensure we build but don't run the tests. Signed-off-by: Alex Bennée <alex.bennee@linaro.org> --- tests/tcg/Makefile.target | 2 +- tests/tcg/sparc32plus | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) create mode 120000 tests/tcg/sparc32plus diff --git a/tests/tcg/Makefile.target b/tests/tcg/Makefile.target index 8bcafaaf7b..bc5d2cdeeb 100644 --- a/tests/tcg/Makefile.target +++ b/tests/tcg/Makefile.target @@ -106,7 +106,7 @@ ifeq ($(filter %-softmmu, $(TARGET)),) # architecture in its VPATH. However some targets are so # minimal/broken just include directly and skip the common multiarch # tests Makefile. -ifeq ($(filter $(TARGET_NAME),aarch64_be sparc),$(TARGET_NAME)) +ifeq ($(filter $(TARGET_NAME),aarch64_be sparc sparc32plus),$(TARGET_NAME)) -include $(SRC_PATH)/tests/tcg/$(TARGET_NAME)/Makefile.target else -include $(SRC_PATH)/tests/tcg/multiarch/Makefile.target diff --git a/tests/tcg/sparc32plus b/tests/tcg/sparc32plus new file mode 120000 index 0000000000..af551a9571 --- /dev/null +++ b/tests/tcg/sparc32plus @@ -0,0 +1 @@ +sparc \ No newline at end of file -- 2.47.2

The sparc64 compiler can nominally be configured to compile 32 bit and v8plus binaries although in practice no one is now shipping them. Signed-off-by: Alex Bennée <alex.bennee@linaro.org> --- configure | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/configure b/configure index 2b2b3d6597..3651cc3085 100755 --- a/configure +++ b/configure @@ -1356,6 +1356,7 @@ fi : ${cross_prefix_sh4="sh4-linux-gnu-"} : ${cross_prefix_sparc64="sparc64-linux-gnu-"} : ${cross_prefix_sparc="$cross_prefix_sparc64"} +: ${cross_prefix_sparc32plus="$cross_prefix_sparc64"} : ${cross_prefix_tricore="tricore-"} : ${cross_prefix_x86_64="x86_64-linux-gnu-"} @@ -1371,8 +1372,8 @@ fi : ${cross_cc_ppc64le="$cross_cc_ppc64"} : ${cross_cc_cflags_ppc64le="-m64 -mlittle-endian"} : ${cross_cc_cflags_sparc64="-m64 -mcpu=ultrasparc"} -: ${cross_cc_sparc="$cross_cc_sparc64"} : ${cross_cc_cflags_sparc="-m32 -mcpu=supersparc"} +: ${cross_cc_cflags_sparc32plus="-m32 -mv8plus"} : ${cross_cc_cflags_x86_64="-m64 -mcx16"} compute_target_variable() { @@ -1543,7 +1544,7 @@ probe_target_compiler() { i386:x86_64 | \ mips*:mips64 | \ ppc*:ppc64 | \ - sparc:sparc64 | \ + sparc:sparc32plus:sparc64 | \ "$cpu:$cpu") try='native cross' ;; esac -- 2.47.2

The distros no longer ship sparc compilers so we must use some others. The best I could find was Frontgrade Gasiler who ship gcc binaries: https://www.gaisler.com/compilers-operating-systems Add a simple image for building the test cases. Signed-off-by: Alex Bennée <alex.bennee@linaro.org> --- .../dockerfiles/sparc-leon-cross.docker | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 tests/docker/dockerfiles/sparc-leon-cross.docker diff --git a/tests/docker/dockerfiles/sparc-leon-cross.docker b/tests/docker/dockerfiles/sparc-leon-cross.docker new file mode 100644 index 0000000000..ec391b01eb --- /dev/null +++ b/tests/docker/dockerfiles/sparc-leon-cross.docker @@ -0,0 +1,40 @@ +# +# Docker sparc cross-compiler target (tests only) +# +# +# +# While the normal cross builds take care to setup proper multiarch +# build environments which can cross build QEMU this just installs the +# basic compilers for as many targets as possible. We shall use this +# to build and run linux-user tests on GitLab +# +FROM docker.io/library/debian:12-slim + +RUN export DEBIAN_FRONTEND=noninteractive && \ + apt-get update && \ + apt-get install -y eatmydata && \ + eatmydata apt-get dist-upgrade -y + +# Add extra build tools and as many cross compilers as we can for testing +RUN DEBIAN_FRONTEND=noninteractive eatmydata\ + apt install -y --no-install-recommends \ + ca-certificates \ + ccache \ + curl \ + tar \ + xz-utils + +RUN mkdir -p /opt + +RUN curl -#SL https://download.gaisler.com/anonftp/linux/linux-2.6/toolchains/sparc-gaisle... \ + | tar -xvJC /opt + + +ENV PATH $PATH:/opt/sparc-gaisler-linux5.10/bin +ENV LD_LIBRARY_PATH /opt/sparc-gaisler-linux5.10/sysroot/leon5/lib/:$LD_LIBRARY_PATH + +# As a final step configure the user (if env is defined) +ARG USER +ARG UID +RUN if [ "${USER}" ]; then \ + id ${USER} 2>/dev/null || useradd -u ${UID} -U ${USER}; fi -- 2.47.2

Signed-off-by: Alex Bennée <alex.bennee@linaro.org> --- configure | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/configure b/configure index 3651cc3085..f187480d3a 100755 --- a/configure +++ b/configure @@ -1442,6 +1442,8 @@ probe_target_compiler() { riscv64) container_hosts=x86_64 ;; s390x) container_hosts=x86_64 ;; sh4) container_hosts=x86_64 ;; + sparc) container_hosts=x86_64 ;; + sparc32plus) container_hosts=x86_64 ;; sparc64) container_hosts=x86_64 ;; tricore) container_hosts=x86_64 ;; x86_64) container_hosts="aarch64 ppc64le x86_64" ;; @@ -1469,6 +1471,10 @@ probe_target_compiler() { container_image=debian-all-test-cross container_cross_prefix=powerpc${target_arch#ppc}-linux-gnu- ;; + sparc|sparc32plus) + container_image=sparc-leon-cross + container_cross_prefix=sparc-gaisler-linux5.10- + ;; # debian-legacy-test-cross architectures (need Debian 11) # - libc6.1-dev-alpha-cross: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1054412 -- 2.47.2

Even with a toolchain *-user is still broken. Maybe we should just deprecate the target. I haven't deprecated for system as we have functional tests that work and will continue to do so. Signed-off-by: Alex Bennée <alex.bennee@linaro.org> --- docs/about/deprecated.rst | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/docs/about/deprecated.rst b/docs/about/deprecated.rst index d50645a071..c2199129d8 100644 --- a/docs/about/deprecated.rst +++ b/docs/about/deprecated.rst @@ -267,6 +267,14 @@ known-good implementation to test against. GCC is in the process of dropping their support for iwMMXt codegen. These CPU types are therefore deprecated in QEMU, and will be removed in a future release. +``sparc`` and ``sparc32plus`` (since 10.1) +'''''''''''''''''''''''''''''''''''''''''' + +Without regular testing these targets have bit-rotted and even after +scrapping together the seemingly last packaged toolchain we can't +generate binaries that can currently be run. + + System emulator CPUs -------------------- -- 2.47.2

On 16/07/2025 12.54, Alex Bennée wrote:
Even with a toolchain *-user is still broken. Maybe we should just deprecate the target. I haven't deprecated for system as we have functional tests that work and will continue to do so.
Signed-off-by: Alex Bennée <alex.bennee@linaro.org> --- docs/about/deprecated.rst | 8 ++++++++ 1 file changed, 8 insertions(+)
diff --git a/docs/about/deprecated.rst b/docs/about/deprecated.rst index d50645a071..c2199129d8 100644 --- a/docs/about/deprecated.rst +++ b/docs/about/deprecated.rst @@ -267,6 +267,14 @@ known-good implementation to test against. GCC is in the process of dropping their support for iwMMXt codegen. These CPU types are therefore deprecated in QEMU, and will be removed in a future release.
+``sparc`` and ``sparc32plus`` (since 10.1) +'''''''''''''''''''''''''''''''''''''''''' + +Without regular testing these targets have bit-rotted and even after +scrapping together the seemingly last packaged toolchain we can't +generate binaries that can currently be run.
I think it's fair to deprecate it in this case. If someone wants to maintain it, they can come up with patches and we can revert this patch. Otherwise it's only dead code anyway. Reviewed-by: Thomas Huth <thuth@redhat.com>

On 16/07/2025 11:54, Alex Bennée wrote:
We didn't have any reliable way to build sparc test cases. I have found someone who ships a compiler but the binaries still don't run due to the need for CASA.
I'm posting mainly for those who actually care who might want to fix up the remaining cases.
Alex.
Alex Bennée (6): tests/tcg: special case sparc test cases tests/tcg: special case sparc32plus test cases configure: update sparc and sparc32plus target compiler detection tests/docker: add sparc-leon-cross container image configure: enable the container fallbacks for sparc/sparc32plus docs/about: deprecate add sparc/sparc32plus-*-user
docs/about/deprecated.rst | 8 ++++ configure | 11 ++++- .../dockerfiles/sparc-leon-cross.docker | 40 +++++++++++++++++ tests/tcg/Makefile.target | 9 ++-- tests/tcg/sparc/Makefile.target | 45 +++++++++++++++++++ tests/tcg/sparc32plus | 1 + 6 files changed, 108 insertions(+), 6 deletions(-) create mode 100644 tests/docker/dockerfiles/sparc-leon-cross.docker create mode 100644 tests/tcg/sparc/Makefile.target create mode 120000 tests/tcg/sparc32plus
I think the basic Debian toolchain for 32-bit SPARC is working because it is currently used to build OpenBIOS, so I don't think we're quite at deprecation point yet. Let me have a look and see if I can figure out what is going on here. ATB, Mark.

Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk> writes:
On 16/07/2025 11:54, Alex Bennée wrote:
We didn't have any reliable way to build sparc test cases. I have found someone who ships a compiler but the binaries still don't run due to the need for CASA. I'm posting mainly for those who actually care who might want to fix up the remaining cases. Alex. Alex Bennée (6): tests/tcg: special case sparc test cases tests/tcg: special case sparc32plus test cases configure: update sparc and sparc32plus target compiler detection tests/docker: add sparc-leon-cross container image configure: enable the container fallbacks for sparc/sparc32plus docs/about: deprecate add sparc/sparc32plus-*-user docs/about/deprecated.rst | 8 ++++ configure | 11 ++++- .../dockerfiles/sparc-leon-cross.docker | 40 +++++++++++++++++ tests/tcg/Makefile.target | 9 ++-- tests/tcg/sparc/Makefile.target | 45 +++++++++++++++++++ tests/tcg/sparc32plus | 1 + 6 files changed, 108 insertions(+), 6 deletions(-) create mode 100644 tests/docker/dockerfiles/sparc-leon-cross.docker create mode 100644 tests/tcg/sparc/Makefile.target create mode 120000 tests/tcg/sparc32plus
I think the basic Debian toolchain for 32-bit SPARC is working because it is currently used to build OpenBIOS, so I don't think we're quite at deprecation point yet.
If you can figure out the right runes to compile then we can just tweak configure and also use the debian-all-test-cross image as a fallback.
Let me have a look and see if I can figure out what is going on here.
Ack. -- Alex Bennée Virtualisation Tech Lead @ Linaro
participants (3)
-
Alex Bennée
-
Mark Cave-Ayland
-
Thomas Huth