target/riscv/cpu_helper: Fix linking problem with semihosting disabled
PATCH 1/1 target/riscv/cpu_helper: Fix linking problem with semihosting disabled
When QEMU has been configured with "--without-default-devices", the build is currently failing with:
/usr/bin/ld: libqemu-riscv32-softmmu.a.p/target_riscv_cpu_helper.c.o:
in function `riscv_cpu_do_interrupt':
.../qemu/target/riscv/cpu_helper.c:1678:(.text+0x2214): undefined
reference to `do_common_semihosting'
Avoid calling into do_common_semihosting() if the corresponding Kconfig switch has not been set.
--- target/riscv/cpu_helper.c | 6 ++++++ 1 file changed, 6 insertions(+)
target/riscv/cpu_helper.c +6 -0
@@ -34,6 +34,10 @@#include "debug.h" #include "tcg/oversized-guest.h" +#ifndef CONFIG_USER_ONLY +#include CONFIG_DEVICES +#endif +int riscv_env_mmu_index (CPURISCVState *env,bool ifetch) {#ifdef CONFIG_USER_ONLY
@@ -1674,10 +1678,12 @@ void riscv_cpu_do_interrupt(CPUState *cs)if (!async) {/* set tval to badaddr for traps with address information */ switch (cause) { +#ifdef CONFIG_ARM_COMPATIBLE_SEMIHOSTING case RISCV_EXCP_SEMIHOST :do_common_semihosting (cs); env->pc +=4 ;return ; +#endif case RISCV_EXCP_LOAD_GUEST_ACCESS_FAULT :case RISCV_EXCP_STORE_GUEST_AMO_ACCESS_FAULT :case RISCV_EXCP_LOAD_ADDR_MIS :
Signature · 1 line
2.46.0
Quoted 11 lines · Thomas Huth
When QEMU has been configured with "--without-default-devices", the build is currently failing with:
/usr/bin/ld:libqemu-riscv32-softmmu.a.p/target_riscv_cpu_helper.c.o:
in function `riscv_cpu_do_interrupt':
.../qemu/target/riscv/cpu_helper.c:1678:(.text+0x2214): undefined
reference to `do_common_semihosting'Avoid calling into
do_common_semihosting()if the correspondingKconfigswitch has not been set.
This would be inconsistent with Arm, where you always get semihosting if you're using TCG. (For KVM, semihosting is up to the kernel to provide, which is why we don't want the code in that case.)
Quoted 23 lines
Signed-off-by Thomas Huth <[email protected]>--- target/riscv/cpu_helper.c | 6 ++++++ 1 file changed, 6 insertions(+)target/riscv/cpu_helper.c +4
-0@@ -34,6 +34,10 @@#include "debug.h" #include "tcg/oversized-guest.h" +#ifndef CONFIG_USER_ONLY +#include CONFIG_DEVICES +#endif +int riscv_env_mmu_index (CPURISCVState *env,bool ifetch) {#ifdef CONFIG_USER_ONLY @@ -1674,10 +1678,12 @@ void riscv_cpu_do_interrupt(CPUState *cs)if (!async) {/* set tval to badaddr for traps with address information */
target/riscv/cpu_helper.c void riscv_cpu_do_interrupt(CPUState *cs) · line 1689
Quoted 10 lines
target/riscv/cpu_helper.c +2
-0switch (cause) { +#ifdef CONFIG_ARM_COMPATIBLE_SEMIHOSTING case RISCV_EXCP_SEMIHOST :do_common_semihosting (cs); env->pc +=4 ;return ; +#endif case RISCV_EXCP_LOAD_GUEST_ACCESS_FAULT :case RISCV_EXCP_STORE_GUEST_AMO_ACCESS_FAULT :case RISCV_EXCP_LOAD_ADDR_MIS :
If you do want to do this thhen this isn't sufficient, because you would also need to change the code that generates the RISCV_EXCP_SEMIHOST exception so that it instead generates the "behave as if we don't have semihosting and the semihosting-trap instruction sequence were executed "normally". But I think the best thing is to use "select if TCG" in the Kconfig.
thanks
-- PMM
Quoted 50 lines · Peter Maydell
Quoted 11 lines · Thomas Huth
When QEMU has been configured with "--without-default-devices", the build is currently failing with:
/usr/bin/ld:libqemu-riscv32-softmmu.a.p/target_riscv_cpu_helper.c.o:
in function `riscv_cpu_do_interrupt':
.../qemu/target/riscv/cpu_helper.c:1678:(.text+0x2214): undefined
reference to `do_common_semihosting'Avoid calling into
do_common_semihosting()if the correspondingKconfigswitch has not been set.This would be inconsistent with Arm, where you always get semihosting if you're using TCG. (For KVM, semihosting is up to the kernel to provide, which is why we don't want the code in that case.)
Quoted 32 lines
Signed-off-by Thomas Huth <[email protected]>--- target/riscv/cpu_helper.c | 6 ++++++ 1 file changed, 6 insertions(+)target/riscv/cpu_helper.c +6
-0@@ -34,6 +34,10 @@#include "debug.h" #include "tcg/oversized-guest.h" +#ifndef CONFIG_USER_ONLY +#include CONFIG_DEVICES +#endif +int riscv_env_mmu_index (CPURISCVState *env,bool ifetch) {#ifdef CONFIG_USER_ONLY @@ -1674,10 +1678,12 @@ void riscv_cpu_do_interrupt(CPUState *cs)if (!async) {/* set tval to badaddr for traps with address information */ switch (cause) { +#ifdef CONFIG_ARM_COMPATIBLE_SEMIHOSTING case RISCV_EXCP_SEMIHOST :do_common_semihosting (cs); env->pc +=4 ;return ; +#endif case RISCV_EXCP_LOAD_GUEST_ACCESS_FAULT :case RISCV_EXCP_STORE_GUEST_AMO_ACCESS_FAULT :
Quoted 8 lines
target/riscv/cpu_helper.c void riscv_cpu_do_interrupt(CPUState *cs) · line 1689
Quoted 1 line
target/riscv/cpu_helper.c +0
-0case RISCV_EXCP_LOAD_ADDR_MIS :If you do want to do this thhen this isn't sufficient, because you would also need to change the code that generates the
RISCV_EXCP_SEMIHOSTexception so that it instead generates the "behave as if we don't have semihosting and the semihosting-trap instruction sequence were executed "normally". But I think the best thing is to use "select if TCG" in theKconfig.
Ok, but I think we then still need a #ifdef CONFIG_TCG here, otherwise linking will fail for KVM-only builds?
Thomas
Quoted 27 lines · Thomas Huth
Quoted 18 lines · Peter Maydell
Quoted 11 lines · Thomas Huth
When QEMU has been configured with "--without-default-devices", the build is currently failing with:
/usr/bin/ld:libqemu-riscv32-softmmu.a.p/target_riscv_cpu_helper.c.o:
in function `riscv_cpu_do_interrupt':
.../qemu/target/riscv/cpu_helper.c:1678:(.text+0x2214): undefined
reference to `do_common_semihosting'Avoid calling into
do_common_semihosting()if the correspondingKconfigswitch has not been set.This would be inconsistent with Arm, where you always get semihosting if you're using TCG. (For KVM, semihosting is up to the kernel to provide, which is why we don't want the code in that case.)
Quoted 6 lines
If you do want to do this thhen this isn't sufficient, because you would also need to change the code that generates the
RISCV_EXCP_SEMIHOSTexception so that it instead generates the "behave as if we don't have semihosting and the semihosting-trap instruction sequence were executed "normally". But I think the best thing is to use "select if TCG" in theKconfig.
Quoted 2 lines
Ok, but I think we then still need a #ifdef
CONFIG_TCGhere, otherwise linking will fail for KVM-only builds?
Yes, I expect so -- the equivalent code in target/arm is wrapped in #ifdef CONFIG_TCG.
-- PMM