On 7/14/25 6:51 AM, Peter Maydell wrote:
If you try to build aarch64-linux-user with clang and --enable-debug then it
fails to compile:

  ld: libqemu-aarch64-linux-user.a.p/target_arm_cpu64.c.o: in function 
`cpu_arm_set_sve':
  ../../target/arm/cpu64.c:321:(.text+0x1254): undefined reference to 
`kvm_arm_sve_supported'

This is a regression introduced in commit f86d4220, which switched
the kvm-stub.c file away from being built for all arm targets to only
being built for system emulation binaries.  It doesn't affect gcc,
presumably because even at -O0 gcc folds away the always-false
kvm_enabled() condition but clang does not.

We would prefer not to build kvm-stub.c once for usermode and once
for system-emulation binaries, and we can't build it just once for
both because it includes cpu.h.  So instead provide always-false
versions of the five functions that are valid to call without KVM
support in kvm_arm.h.

Fixes: f86d42205c2eba ("target/arm/meson: accelerator files are not needed in user 
mode")
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/3033
Signed-off-by: Peter Maydell <peter.mayd...@linaro.org>
---
I'm never sure when we prefer to use stub-functions in separate C files
vs when we prefer to have ifdeffed stubs in headers. There are several
ways we could fix this compile error, so I just picked one...
---
  target/arm/kvm_arm.h | 35 +++++++++++++++++++++++++++++++++++
  1 file changed, 35 insertions(+)


Thanks Peter, clang with --enable-debug is indeed a combination I didn't try. I'll test this too now. Going through this topic, yes I noticed that gcc always folds the any if (0) condition, and, based on a Richard comment (I can't find now) it seems that we used to rely on that for other parts of the code.

The fix you propose works well (initial goal was just to remove CONFIG_KVM, so having CONFIG_USER_ONLY is ok), but I wonder if there is something specific affecting clang in this case and preventing the folding.

Reviewed-by: Pierrick Bouvier <pierrick.bouv...@linaro.org>

Thanks,
Pierrick

Reply via email to