[kvm-unit-tests] riscv build failure

Andrew Jones andrew.jones at linux.dev
Fri Sep 5 08:31:16 PDT 2025


On Fri, Sep 05, 2025 at 06:26:55PM +1000, Nicholas Piggin wrote:
> On Thu, Sep 04, 2025 at 05:17:45PM -0500, Andrew Jones wrote:
> > On Thu, Sep 04, 2025 at 08:57:54AM +0930, Joel Stanley wrote:
> > > I'm building kvm-unit-tests as part of buildroot and hitting a build
> > > failure. It looks like there's a missing dependency on
> > > riscv/sbi-asm.S, as building that manually fixes the issue. Triggering
> > > buildroot again (several times) doesn't resolve the issue so it
> > > doesn't look like a race condition.
> > > 
> > > I can't reproduce with a normal cross compile on my machine. Buildroot
> > > uses make -C, in case that makes a difference.
> > > 
> > > The build steps look like this:
> > > 
> > > bzcat /localdev/jms/buildroot/dl/kvm-unit-tests/kvm-unit-tests-v2025-06-05.tar.bz2
> > > | /localdev/jms/buildroot/output-riscv-rvv/host/bin/tar
> > > --strip-components=1 -C
> > > /localdev/jms/buildroot/output-riscv-rvv/build/kvm-unit-tests-2025-06-05
> > >   -xf -
> > > cd /localdev/jms/buildroot/output-riscv-rvv/build/kvm-unit-tests-2025-06-05
> > > && ./configure --disable-werror --arch="riscv64" --processor=""
> > > --endian="little"
> > > --cross-prefix="/localdev/jms/buildroot/output-riscv-rvv/host/bin/riscv64-buildroot-linux-gnu-"
> > > GIT_DIR=. PATH="/localdev/jms/buildroot/output-riscv-rvv/host/bin:/localdev/jms/buildroot/output-riscv-rvv/host/sbin:/home/jms/.local/bin:/home/jms/bin:/home/jms/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin"
> > > /usr/bin/make -j385  -C
> > > /localdev/jms/buildroot/output-riscv-rvv/build/kvm-unit-tests-2025-06-05
> > > standalone
> > 
> > I applied similar steps but couldn't reproduce this. It also looks like we
> > have a dependency because configuring with '--cc=/path/to/mygcc', where
> > mygcc is
> > 
> >    #!/bin/bash
> >    for x in $@; do
> >        if [[ $x =~ sbi-asm ]] && ! [[ $x =~ sbi-asm-offsets ]]; then
> >            sleep 5
> >            break
> >        fi
> >    done
> >    /path/to/riscv64-linux-gnu-gcc $@
> > 
> > stalls the build 5 seconds when compiling sbi-asm.S but doesn't reproduce
> > the issue. That said, running make with -d shows that riscv/sbi-asm.o is
> > an implicit prerequisite, although so are other files. I'm using
> > GNU Make 4.4.1. Which version are you using?
> > 
> > Also, while the steps above shouldn't cause problems, they are a bit odd
> >  * '--endian' only applies to ppc64
> >  * -j385 is quite large and specific. Typicall -j$(nproc) is recommended.
> >  * No need for '-C "$PWD"'
> 
> Thanks for taking a look, it's Make 4.2.1 at least. I tracked it down
> to second expansion barfing when the variable name has a / in it. It
> looks like it can be fixed with the below, so I didn't look too closely
> at whether that's a bug, in what versions, or not previously supported
> because I was able to fix it like this.
> 
> Thanks,
> Nick
> 
>     build: work around second expansion limitation with some Make versions
>     
>     GNU Make 4.2.1 as shipped in Ubuntu 20.04 has a problem with secondary
>     expansion and variable names containing the '/' character. Make 4.3 and
>     4.4 don't have the problem.
>     
>     Avoid putting the riscv/ directory name in the sbi-deps variable, and
>     instead strip the directory off the target name when turning it into
>     the dependency variable name.
> 
> diff --git a/riscv/Makefile b/riscv/Makefile
> index beaeaefa..64720c38 100644
> --- a/riscv/Makefile
> +++ b/riscv/Makefile
> @@ -18,12 +18,12 @@ tests += $(TEST_DIR)/isa-dbltrp.$(exe)
>  
>  all: $(tests)
>  
> -$(TEST_DIR)/sbi-deps += $(TEST_DIR)/sbi-asm.o
> -$(TEST_DIR)/sbi-deps += $(TEST_DIR)/sbi-dbtr.o
> -$(TEST_DIR)/sbi-deps += $(TEST_DIR)/sbi-fwft.o
> -$(TEST_DIR)/sbi-deps += $(TEST_DIR)/sbi-sse.o
> +sbi-deps += $(TEST_DIR)/sbi-asm.o
> +sbi-deps += $(TEST_DIR)/sbi-dbtr.o
> +sbi-deps += $(TEST_DIR)/sbi-fwft.o
> +sbi-deps += $(TEST_DIR)/sbi-sse.o
>  
> -all_deps += $($(TEST_DIR)/sbi-deps)
> +all_deps += $(sbi-deps)
>  
>  # When built for EFI sieve needs extra memory, run with e.g. '-m 256' on QEMU
>  $(TEST_DIR)/sieve.$(exe): AUXFLAGS = 0x1
> @@ -113,7 +113,7 @@ cflatobjs += lib/efi.o
>  .PRECIOUS: %.so
>  
>  %.so: EFI_LDFLAGS += -defsym=EFI_SUBSYSTEM=0xa --no-undefined
> -%.so: %.o $(FLATLIBS) $(SRCDIR)/riscv/efi/elf_riscv64_efi.lds $(cstart.o) %.aux.o $$($$*-deps)
> +%.so: %.o $(FLATLIBS) $(SRCDIR)/riscv/efi/elf_riscv64_efi.lds $(cstart.o) %.aux.o $$($$(notdir $$*)-deps)
>  	$(LD) $(EFI_LDFLAGS) -o $@ -T $(SRCDIR)/riscv/efi/elf_riscv64_efi.lds \
>  		$(filter %.o, $^) $(FLATLIBS) $(EFI_LIBS)
>  
> @@ -129,7 +129,7 @@ cflatobjs += lib/efi.o
>  		-O binary $^ $@
>  else
>  %.elf: LDFLAGS += -pie -n -z notext
> -%.elf: %.o $(FLATLIBS) $(SRCDIR)/riscv/flat.lds $(cstart.o) %.aux.o $$($$*-deps)
> +%.elf: %.o $(FLATLIBS) $(SRCDIR)/riscv/flat.lds $(cstart.o) %.aux.o $$($$(notdir $$*)-deps)
>  	$(LD) $(LDFLAGS) -o $@ -T $(SRCDIR)/riscv/flat.lds \
>  		$(filter %.o, $^) $(FLATLIBS)
>  	@chmod a-x $@

Thanks, Nicholas.

This looks good to me. Can you please send as an independent patch with
your sign-off?

Thanks,
drew



More information about the kvm-riscv mailing list