* [PATCH v2] target/i386: Re-introduce few KVM stubs for Clang debug builds
@ 2023-09-11 13:15 Philippe Mathieu-Daudé
2023-09-11 15:05 ` Philippe Mathieu-Daudé
0 siblings, 1 reply; 2+ messages in thread
From: Philippe Mathieu-Daudé @ 2023-09-11 13:15 UTC (permalink / raw)
To: qemu-devel
Cc: kvm, Daniel Henrique Barboza, Paolo Bonzini, Michael Tokarev,
Stefan Hajnoczi, Richard Henderson, Marcelo Tosatti,
Philippe Mathieu-Daudé, Kevin Wolf, Daniel P . Berrangé
Since commits 3adce820cf..ef1cf6890f, When building on
a x86 host configured as:
$ ./configure --cc=clang \
--target-list=x86_64-linux-user,x86_64-softmmu \
--enable-debug
we get:
[71/71] Linking target qemu-x86_64
FAILED: qemu-x86_64
/usr/bin/ld: libqemu-x86_64-linux-user.fa.p/target_i386_cpu.c.o: in function `cpu_x86_cpuid':
cpu.c:(.text+0x1374): undefined reference to `kvm_arch_get_supported_cpuid'
/usr/bin/ld: libqemu-x86_64-linux-user.fa.p/target_i386_cpu.c.o: in function `x86_cpu_filter_features':
cpu.c:(.text+0x81c2): undefined reference to `kvm_arch_get_supported_cpuid'
/usr/bin/ld: cpu.c:(.text+0x81da): undefined reference to `kvm_arch_get_supported_cpuid'
/usr/bin/ld: cpu.c:(.text+0x81f2): undefined reference to `kvm_arch_get_supported_cpuid'
/usr/bin/ld: cpu.c:(.text+0x820a): undefined reference to `kvm_arch_get_supported_cpuid'
/usr/bin/ld: libqemu-x86_64-linux-user.fa.p/target_i386_cpu.c.o:cpu.c:(.text+0x8225): more undefined references to `kvm_arch_get_supported_cpuid' follow
clang: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.
'--enable-debug' disables optimizations (CFLAGS=-O0).
While at this (un)optimization level GCC eliminate the
following dead code:
if (0 && foo()) {
...
}
Clang does not. This was previously documented in commit 2140cfa51d
("i386: Fix build by providing stub kvm_arch_get_supported_cpuid()").
Fix by partially reverting those commits, restoring a pair of stubs
for the unoptimized Clang builds.
Reported-by: Kevin Wolf <kwolf@redhat.com>
Suggested-by: Daniel P. Berrangé <berrange@redhat.com>
Fixes: 3adce820cf ("target/i386: Remove unused KVM stubs")
Fixes: ef1cf6890f ("target/i386: Allow elision of kvm_hv_vpindex_settable()")
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
target/i386/kvm/kvm-stub.c | 31 +++++++++++++++++++++++++++++++
target/i386/kvm/meson.build | 2 ++
2 files changed, 33 insertions(+)
create mode 100644 target/i386/kvm/kvm-stub.c
diff --git a/target/i386/kvm/kvm-stub.c b/target/i386/kvm/kvm-stub.c
new file mode 100644
index 0000000000..d3d4a238ce
--- /dev/null
+++ b/target/i386/kvm/kvm-stub.c
@@ -0,0 +1,31 @@
+/*
+ * QEMU KVM x86 specific function stubs
+ *
+ * Copyright Linaro Limited 2012
+ *
+ * Author: Peter Maydell <peter.maydell@linaro.org>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ *
+ */
+#include "qemu/osdep.h"
+#include "cpu.h"
+#include "kvm_i386.h"
+
+#ifndef __OPTIMIZE__
+/* This function is only called inside conditionals which we
+ * rely on the compiler to optimize out when CONFIG_KVM is not
+ * defined.
+ */
+uint32_t kvm_arch_get_supported_cpuid(KVMState *env, uint32_t function,
+ uint32_t index, int reg)
+{
+ abort();
+}
+#endif
+
+bool kvm_hv_vpindex_settable(void)
+{
+ return false;
+}
diff --git a/target/i386/kvm/meson.build b/target/i386/kvm/meson.build
index 5d9174bbb5..40fbde96ca 100644
--- a/target/i386/kvm/meson.build
+++ b/target/i386/kvm/meson.build
@@ -1,3 +1,5 @@
+i386_ss.add(when: 'CONFIG_KVM', if_false: files('kvm-stub.c'))
+
i386_softmmu_kvm_ss = ss.source_set()
i386_softmmu_kvm_ss.add(files(
--
2.41.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH v2] target/i386: Re-introduce few KVM stubs for Clang debug builds
2023-09-11 13:15 [PATCH v2] target/i386: Re-introduce few KVM stubs for Clang debug builds Philippe Mathieu-Daudé
@ 2023-09-11 15:05 ` Philippe Mathieu-Daudé
0 siblings, 0 replies; 2+ messages in thread
From: Philippe Mathieu-Daudé @ 2023-09-11 15:05 UTC (permalink / raw)
To: qemu-devel
Cc: kvm, Daniel Henrique Barboza, Paolo Bonzini, Michael Tokarev,
Stefan Hajnoczi, Richard Henderson, Marcelo Tosatti, Kevin Wolf,
Daniel P . Berrangé
On 11/9/23 15:15, Philippe Mathieu-Daudé wrote:
> Since commits 3adce820cf..ef1cf6890f, When building on
> a x86 host configured as:
>
> $ ./configure --cc=clang \
> --target-list=x86_64-linux-user,x86_64-softmmu \
> --enable-debug
>
> we get:
>
> [71/71] Linking target qemu-x86_64
> FAILED: qemu-x86_64
> /usr/bin/ld: libqemu-x86_64-linux-user.fa.p/target_i386_cpu.c.o: in function `cpu_x86_cpuid':
> cpu.c:(.text+0x1374): undefined reference to `kvm_arch_get_supported_cpuid'
> /usr/bin/ld: libqemu-x86_64-linux-user.fa.p/target_i386_cpu.c.o: in function `x86_cpu_filter_features':
> cpu.c:(.text+0x81c2): undefined reference to `kvm_arch_get_supported_cpuid'
> /usr/bin/ld: cpu.c:(.text+0x81da): undefined reference to `kvm_arch_get_supported_cpuid'
> /usr/bin/ld: cpu.c:(.text+0x81f2): undefined reference to `kvm_arch_get_supported_cpuid'
> /usr/bin/ld: cpu.c:(.text+0x820a): undefined reference to `kvm_arch_get_supported_cpuid'
> /usr/bin/ld: libqemu-x86_64-linux-user.fa.p/target_i386_cpu.c.o:cpu.c:(.text+0x8225): more undefined references to `kvm_arch_get_supported_cpuid' follow
> clang: error: linker command failed with exit code 1 (use -v to see invocation)
> ninja: build stopped: subcommand failed.
>
> '--enable-debug' disables optimizations (CFLAGS=-O0).
>
> While at this (un)optimization level GCC eliminate the
> following dead code:
>
> if (0 && foo()) {
> ...
> }
>
> Clang does not. This was previously documented in commit 2140cfa51d
> ("i386: Fix build by providing stub kvm_arch_get_supported_cpuid()").
>
> Fix by partially reverting those commits, restoring a pair of stubs
> for the unoptimized Clang builds.
>
> Reported-by: Kevin Wolf <kwolf@redhat.com>
> Suggested-by: Daniel P. Berrangé <berrange@redhat.com>
> Fixes: 3adce820cf ("target/i386: Remove unused KVM stubs")
> Fixes: ef1cf6890f ("target/i386: Allow elision of kvm_hv_vpindex_settable()")
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
> target/i386/kvm/kvm-stub.c | 31 +++++++++++++++++++++++++++++++
> target/i386/kvm/meson.build | 2 ++
> 2 files changed, 33 insertions(+)
> create mode 100644 target/i386/kvm/kvm-stub.c
Patch superseded, see v3:
https://lore.kernel.org/qemu-devel/20230911142729.25548-1-philmd@linaro.org/
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-09-11 15:06 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-09-11 13:15 [PATCH v2] target/i386: Re-introduce few KVM stubs for Clang debug builds Philippe Mathieu-Daudé
2023-09-11 15:05 ` Philippe Mathieu-Daudé
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).