On 11/9/23 12:11, Philippe Mathieu-Daudé wrote:
> On 8/9/23 21:21, Paolo Bonzini wrote:
>> On Fri, Sep 8, 2023 at 7:28 PM Kevin Wolf <kwolf@redhat.com> wrote:
>>> Maybe the calls aren't eliminated because --enable-debug implies -O0?
>>
>> My experience is that it will still fold simple dead code like "0 &&
>> foo()" or even "if (0) { ... }", but maybe it's a GCC vs. clang
>> difference. Philippe, I take it that you are looking at it?
FTR preprocessed code is indeed:
# 5682 "../../target/i386/cpu.c"
uint64_t x86_cpu_get_supported_feature_word(FeatureWord w,
_Bool migratable_only)
{
FeatureWordInfo *wi = &feature_word_info[w];
uint64_t r = 0;
if ((0)) {
switch (wi->type) {
case CPUID_FEATURE_WORD:
r = kvm_arch_get_supported_cpuid(kvm_state, wi->cpuid.eax,
wi->cpuid.ecx,
wi->cpuid.reg);
break;
case MSR_FEATURE_WORD:
r = kvm_arch_get_supported_msr_feature(kvm_state,
wi->msr.index);
break;
}
} else if (0) {
if (wi->type != CPUID_FEATURE_WORD) {
return 0;
}
r = 0;
} else if ((tcg_allowed)) {
r = wi->tcg_features;
} else {
return ~0;
}
# 5725 "../../target/i386/cpu.c"
if (migratable_only) {
r &= x86_cpu_get_migratable_flags(w);
}
return r;
}
static void x86_cpu_get_supported_cpuid(uint32_t func, uint32_t index,
uint32_t *eax, uint32_t *ebx,
uint32_t *ecx, uint32_t *edx)
{
if ((0)) {
*eax = kvm_arch_get_supported_cpuid(kvm_state, func, index, R_EAX);
*ebx = kvm_arch_get_supported_cpuid(kvm_state, func, index, R_EBX);
*ecx = kvm_arch_get_supported_cpuid(kvm_state, func, index, R_ECX);
*edx = kvm_arch_get_supported_cpuid(kvm_state, func, index, R_EDX);
} else if (0) {
*eax = 0;
*ebx = 0;
*ecx = 0;
*edx = 0;
} else {
*eax = 0;
*ebx = 0;
*ecx = 0;
*edx = 0;
}
}
Which made me wonder about this sysemu code use from useremu,
in particular because the link failure comes from
libqemu-x86_64-linux-user.fa.p. This pair of #ifdef'ry to
restrict system-specific code seems sufficient to link:
-- >8 --
diff --git a/target/i386/cpu.c b/target/i386/cpu.c
index 24ee67b42d..83914d5d1b 100644
--- a/target/i386/cpu.c
+++ b/target/i386/cpu.c
@@ -6163,6 +6163,7 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t
index, uint32_t count,
}
*edx = env->features[FEAT_7_0_EDX]; /* Feature flags */
+#ifndef CONFIG_USER_ONLY
/*
* SGX cannot be emulated in software. If hardware does not
* support enabling SGX and/or SGX flexible launch control,
@@ -6181,6 +6182,7 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t
index, uint32_t count,
CPUID_7_0_ECX_SGX_LC))) {
*ecx &= ~CPUID_7_0_ECX_SGX_LC;
}
+#endif
} else if (count == 1) {
*eax = env->features[FEAT_7_1_EAX];
*edx = env->features[FEAT_7_1_EDX];
@@ -7152,6 +7154,7 @@ static void x86_cpu_filter_features(X86CPU *cpu,
bool verbose)
mark_unavailable_features(cpu, w, unavailable_features, prefix);
}
+#ifndef CONFIG_USER_ONLY
if ((env->features[FEAT_7_0_EBX] & CPUID_7_0_EBX_INTEL_PT) &&
kvm_enabled()) {
KVMState *s = CPU(cpu)->kvm_state;
@@ -7179,6 +7182,7 @@ static void x86_cpu_filter_features(X86CPU *cpu,
bool verbose)
mark_unavailable_features(cpu, FEAT_7_0_EBX,
CPUID_7_0_EBX_INTEL_PT, prefix);
}
}
+#endif
}
---
So I'll send a v3.