Skip to contentSkip to conversation

target/arm: gdbstub: Guard M-profile code with CONFIG_TCG

PATCH Applied Fabiano Rosas 4 participants 10 messages Jun 28, 2023 – Jul 5, 2023

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 target/arm: gdbstub: Guard M-profile code with CONFIG_TCG

This code is only relevant when TCG is present in the build. Building with --disable-tcg --enable-xen on an x86 host we get:

$ ../configure --target-list=x86_64-softmmu,aarch64-softmmu --disable-tcg --enable-xen
$ make -j$(nproc)
...
libqemu-aarch64-softmmu.fa.p/target_arm_gdbstub.c.o: in function `m_sysreg_ptr':
 ../target/arm/gdbstub.c:358: undefined reference to `arm_v7m_get_sp_ptr'
 ../target/arm/gdbstub.c:361: undefined reference to `arm_v7m_get_sp_ptr'

libqemu-aarch64-softmmu.fa.p/target_arm_gdbstub.c.o: in function `arm_gdb_get_m_systemreg':
../target/arm/gdbstub.c:405: undefined reference to `arm_v7m_mrs_control'

---
This is a respin of:
https://lore.kernel.org/r/[email protected]

---
 target/arm/gdbstub.c | 4 ++++
 1 file changed, 4 insertions(+)
target/arm/gdbstub.c +4 -0
index 03b17c814f..f421c5d041 100644
@@ -324,6 +324,7 @@ static int arm_gen_dynamic_sysreg_xml(CPUState *cs, int base_reg)
     return cpu->dyn_sysreg_xml.num;
 }
 
+#ifdef CONFIG_TCG
 typedef enum {
     M_SYSREG_MSP,
     M_SYSREG_PSP,
@@ -481,6 +482,7 @@ static int arm_gen_dynamic_m_secextreg_xml(CPUState *cs, int orig_base_reg)
     return cpu->dyn_m_secextreg_xml.num;
 }
 #endif
+#endif /* CONFIG_TCG */
 
 const char *arm_gdb_get_dynamic_xml(CPUState *cs, const char *xmlname)
 {
@@ -561,6 +563,7 @@ void arm_cpu_register_gdb_regs_for_features(ARMCPU *cpu)
                              arm_gen_dynamic_sysreg_xml(cs, cs->gdb_num_regs),
                              "system-registers.xml", 0);
 
+#ifdef CONFIG_TCG
     if (arm_feature(env, ARM_FEATURE_M) && tcg_enabled()) {
         gdb_register_coprocessor(cs,
             arm_gdb_get_m_systemreg, arm_gdb_set_m_systemreg,
@@ -575,4 +578,5 @@ void arm_cpu_register_gdb_regs_for_features(ARMCPU *cpu)
         }
 #endif
     }
+#endif /* CONFIG_TCG */
 }
Signature · 1 line
2.35.3
#1 lore raw
Quoted 10 lines · Fabiano Rosas

This code is only relevant when TCG is present in the build. Building with --disable-tcg --enable-xen on an x86 host we get:

$ ../configure --target-list=x86_64-softmmu,aarch64-softmmu --disable-tcg --enable-xen
$ make -j$(nproc)
...
libqemu-aarch64-softmmu.fa.p/target_arm_gdbstub.c.o: in function `m_sysreg_ptr':
  ../target/arm/gdbstub.c:358: undefined reference to `arm_v7m_get_sp_ptr'
  ../target/arm/gdbstub.c:361: undefined reference to `arm_v7m_get_sp_ptr'
Quoted 2 lines

libqemu-aarch64-softmmu.fa.p/target_arm_gdbstub.c.o: in function `arm_gdb_get_m_systemreg':
../target/arm/gdbstub.c:405: undefined reference to `arm_v7m_mrs_control'

I'm a bit confused, isn't this covered by the cross-arm64-xen-only job?

Quoted 7 lines

---
This is a respin of:
https://lore.kernel.org/r/[email protected]

---
  target/arm/gdbstub.c | 4 ++++
  1 file changed, 4 insertions(+)
#2 lore raw
Quoted 11 lines · Philippe Mathieu-Daudé
Quoted 10 lines · Fabiano Rosas

This code is only relevant when TCG is present in the build. Building with --disable-tcg --enable-xen on an x86 host we get:

$ ../configure --target-list=x86_64-softmmu,aarch64-softmmu --disable-tcg --enable-xen
$ make -j$(nproc)
...
libqemu-aarch64-softmmu.fa.p/target_arm_gdbstub.c.o: in function `m_sysreg_ptr':
  ../target/arm/gdbstub.c:358: undefined reference to `arm_v7m_get_sp_ptr'
  ../target/arm/gdbstub.c:361: undefined reference to `arm_v7m_get_sp_ptr'
Quoted 5 lines
Quoted 2 lines

libqemu-aarch64-softmmu.fa.p/target_arm_gdbstub.c.o: in function `arm_gdb_get_m_systemreg':
../target/arm/gdbstub.c:405: undefined reference to `arm_v7m_mrs_control'

I'm a bit confused, isn't this covered by the cross-arm64-xen-only job?

It should be. Perhaps the CI is using different optimization flags. I'll try to figure it out.

#3 lore raw
Quoted 13 lines · Fabiano Rosas
Quoted 11 lines · Philippe Mathieu-Daudé
Quoted 10 lines · Fabiano Rosas

This code is only relevant when TCG is present in the build. Building with --disable-tcg --enable-xen on an x86 host we get:

$ ../configure --target-list=x86_64-softmmu,aarch64-softmmu --disable-tcg --enable-xen
$ make -j$(nproc)
...
libqemu-aarch64-softmmu.fa.p/target_arm_gdbstub.c.o: in function `m_sysreg_ptr':
  ../target/arm/gdbstub.c:358: undefined reference to `arm_v7m_get_sp_ptr'
  ../target/arm/gdbstub.c:361: undefined reference to `arm_v7m_get_sp_ptr'
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

libqemu-aarch64-softmmu.fa.p/target_arm_gdbstub.c.o: in function `arm_gdb_get_m_systemreg':
../target/arm/gdbstub.c:405: undefined reference to `arm_v7m_mrs_control'

I'm a bit confused, isn't this covered by the cross-arm64-xen-only job?

It should be. Perhaps the CI is using different optimization flags. I'll try to figure it out.

Yep. The CI has -O2 while I am using --enable-debug.

#4 lore raw
In reply to Fabiano Rosas
Quoted 11 lines · Fabiano Rosas

This code is only relevant when TCG is present in the build. Building with --disable-tcg --enable-xen on an x86 host we get:

$ ../configure --target-list=x86_64-softmmu,aarch64-softmmu --disable-tcg --enable-xen
$ make -j$(nproc)
...
libqemu-aarch64-softmmu.fa.p/target_arm_gdbstub.c.o: in function `m_sysreg_ptr':
 ../target/arm/gdbstub.c:358: undefined reference to `arm_v7m_get_sp_ptr'
 ../target/arm/gdbstub.c:361: undefined reference to `arm_v7m_get_sp_ptr'
Quoted 4 lines

libqemu-aarch64-softmmu.fa.p/target_arm_gdbstub.c.o: in function `arm_gdb_get_m_systemreg':
../target/arm/gdbstub.c:405: undefined reference to `arm_v7m_mrs_control'

Applied to target-arm.next, thanks.

-- PMM

#5 lore raw
In reply to Fabiano Rosas
Quoted 26 lines · Fabiano Rosas

This code is only relevant when TCG is present in the build. Building with --disable-tcg --enable-xen on an x86 host we get:

$ ../configure --target-list=x86_64-softmmu,aarch64-softmmu --disable-tcg --enable-xen
$ make -j$(nproc)
...
libqemu-aarch64-softmmu.fa.p/target_arm_gdbstub.c.o: in function `m_sysreg_ptr':
  ../target/arm/gdbstub.c:358: undefined reference to `arm_v7m_get_sp_ptr'
  ../target/arm/gdbstub.c:361: undefined reference to `arm_v7m_get_sp_ptr'

libqemu-aarch64-softmmu.fa.p/target_arm_gdbstub.c.o: in function `arm_gdb_get_m_systemreg':
../target/arm/gdbstub.c:405: undefined reference to `arm_v7m_mrs_control'

---
This is a respin of:
https://lore.kernel.org/r/[email protected]

---
  target/arm/gdbstub.c | 4 ++++
  1 file changed, 4 insertions(+)
target/arm/gdbstub.c +0 -0
index 03b17c814f..f421c5d041 100644

target/arm/gdbstub.c static int arm_gen_dynamic_sysreg_xml(CPUState *cs, int base_reg) · line 327

Quoted 4 lines
target/arm/gdbstub.c +1 -0
@@ -324,6 +324,7 @@ static int arm_gen_dynamic_sysreg_xml(CPUState *cs, int base_reg)
      return cpu->dyn_sysreg_xml.num;
  }
 
+#ifdef CONFIG_TCG

OK.

Quoted 12 lines
target/arm/gdbstub.c +1 -0
  typedef enum {
      M_SYSREG_MSP,
      M_SYSREG_PSP,
@@ -481,6 +482,7 @@ static int arm_gen_dynamic_m_secextreg_xml(CPUState *cs, int orig_base_reg)
      return cpu->dyn_m_secextreg_xml.num;
  }
  #endif
+#endif /* CONFIG_TCG */
 
  const char *arm_gdb_get_dynamic_xml(CPUState *cs, const char *xmlname)
  {

target/arm/gdbstub.c void arm_cpu_register_gdb_regs_for_features(ARMCPU *cpu) · line 566

Quoted 4 lines
target/arm/gdbstub.c +1 -0
@@ -561,6 +563,7 @@ void arm_cpu_register_gdb_regs_for_features(ARMCPU *cpu)
                               arm_gen_dynamic_sysreg_xml(cs, cs->gdb_num_regs),
                               "system-registers.xml", 0);
 
+#ifdef CONFIG_TCG

IIUC tcg_enabled(), this guard shouldn't be necessary; if CONFIG_TCG is not defined, tcg_enabled() evaluates to 0, and the compiler should elide the whole block.

Quoted 9 lines
target/arm/gdbstub.c +1 -0
      if (arm_feature(env, ARM_FEATURE_M) && tcg_enabled()) {
          gdb_register_coprocessor(cs,
              arm_gdb_get_m_systemreg, arm_gdb_set_m_systemreg,
@@ -575,4 +578,5 @@ void arm_cpu_register_gdb_regs_for_features(ARMCPU *cpu)
          }
  #endif
      }
+#endif /* CONFIG_TCG */
  }
#6 lore raw
Quoted 50 lines · Philippe Mathieu-Daudé
Quoted 26 lines · Fabiano Rosas

This code is only relevant when TCG is present in the build. Building with --disable-tcg --enable-xen on an x86 host we get:

$ ../configure --target-list=x86_64-softmmu,aarch64-softmmu --disable-tcg --enable-xen
$ make -j$(nproc)
...
libqemu-aarch64-softmmu.fa.p/target_arm_gdbstub.c.o: in function `m_sysreg_ptr':
  ../target/arm/gdbstub.c:358: undefined reference to `arm_v7m_get_sp_ptr'
  ../target/arm/gdbstub.c:361: undefined reference to `arm_v7m_get_sp_ptr'

libqemu-aarch64-softmmu.fa.p/target_arm_gdbstub.c.o: in function `arm_gdb_get_m_systemreg':
../target/arm/gdbstub.c:405: undefined reference to `arm_v7m_mrs_control'

---
This is a respin of:
https://lore.kernel.org/r/[email protected]

---
  target/arm/gdbstub.c | 4 ++++
  1 file changed, 4 insertions(+)
target/arm/gdbstub.c +0 -0
index 03b17c814f..f421c5d041 100644

target/arm/gdbstub.c static int arm_gen_dynamic_sysreg_xml(CPUState *cs, int base_reg) · line 327

Quoted 4 lines
target/arm/gdbstub.c +1 -0
@@ -324,6 +324,7 @@ static int arm_gen_dynamic_sysreg_xml(CPUState *cs, int base_reg)
      return cpu->dyn_sysreg_xml.num;
  }
 
+#ifdef CONFIG_TCG

OK.

Quoted 15 lines
target/arm/gdbstub.c +1 -0
  typedef enum {
      M_SYSREG_MSP,
      M_SYSREG_PSP,
@@ -481,6 +482,7 @@ static int arm_gen_dynamic_m_secextreg_xml(CPUState *cs, int orig_base_reg)
      return cpu->dyn_m_secextreg_xml.num;
  }
  #endif
+#endif /* CONFIG_TCG */
 
  const char *arm_gdb_get_dynamic_xml(CPUState *cs, const char *xmlname)
  {
@@ -561,6 +563,7 @@ void arm_cpu_register_gdb_regs_for_features(ARMCPU *cpu)
                               arm_gen_dynamic_sysreg_xml(cs, cs->gdb_num_regs),
                               "system-registers.xml", 0);
 
Quoted 5 lines

target/arm/gdbstub.c void arm_cpu_register_gdb_regs_for_features(ARMCPU *cpu) · line 566

Quoted 1 line
target/arm/gdbstub.c +1 -0
+#ifdef CONFIG_TCG

IIUC tcg_enabled(), this guard shouldn't be necessary; if CONFIG_TCG is not defined, tcg_enabled() evaluates to 0, and the compiler should elide the whole block.

IME it's a bit optimistic to assume that the compiler will always do that, especially with no optimisation enabled.

thanks
-- PMM

#7 lore raw
Quoted 51 lines · Peter Maydell
Quoted 50 lines · Philippe Mathieu-Daudé
Quoted 26 lines · Fabiano Rosas

This code is only relevant when TCG is present in the build. Building with --disable-tcg --enable-xen on an x86 host we get:

$ ../configure --target-list=x86_64-softmmu,aarch64-softmmu --disable-tcg --enable-xen
$ make -j$(nproc)
...
libqemu-aarch64-softmmu.fa.p/target_arm_gdbstub.c.o: in function `m_sysreg_ptr':
   ../target/arm/gdbstub.c:358: undefined reference to `arm_v7m_get_sp_ptr'
   ../target/arm/gdbstub.c:361: undefined reference to `arm_v7m_get_sp_ptr'

libqemu-aarch64-softmmu.fa.p/target_arm_gdbstub.c.o: in function `arm_gdb_get_m_systemreg':
../target/arm/gdbstub.c:405: undefined reference to `arm_v7m_mrs_control'

---
This is a respin of:
https://lore.kernel.org/r/[email protected]

---
   target/arm/gdbstub.c | 4 ++++
   1 file changed, 4 insertions(+)
target/arm/gdbstub.c +0 -0
index 03b17c814f..f421c5d041 100644

target/arm/gdbstub.c static int arm_gen_dynamic_sysreg_xml(CPUState *cs, int base_reg) · line 327

Quoted 4 lines
target/arm/gdbstub.c +1 -0
@@ -324,6 +324,7 @@ static int arm_gen_dynamic_sysreg_xml(CPUState *cs, int base_reg)
       return cpu->dyn_sysreg_xml.num;
   }
 
+#ifdef CONFIG_TCG

OK.

Quoted 15 lines
target/arm/gdbstub.c +1 -0
   typedef enum {
       M_SYSREG_MSP,
       M_SYSREG_PSP,
@@ -481,6 +482,7 @@ static int arm_gen_dynamic_m_secextreg_xml(CPUState *cs, int orig_base_reg)
       return cpu->dyn_m_secextreg_xml.num;
   }
   #endif
+#endif /* CONFIG_TCG */
 
   const char *arm_gdb_get_dynamic_xml(CPUState *cs, const char *xmlname)
   {
@@ -561,6 +563,7 @@ void arm_cpu_register_gdb_regs_for_features(ARMCPU *cpu)
                                arm_gen_dynamic_sysreg_xml(cs, cs->gdb_num_regs),
                                "system-registers.xml", 0);
 
Quoted 8 lines
Quoted 5 lines

target/arm/gdbstub.c void arm_cpu_register_gdb_regs_for_features(ARMCPU *cpu) · line 566

Quoted 1 line
target/arm/gdbstub.c +1 -0
+#ifdef CONFIG_TCG

IIUC tcg_enabled(), this guard shouldn't be necessary; if CONFIG_TCG is not defined, tcg_enabled() evaluates to 0, and the compiler should elide the whole block.

IME it's a bit optimistic to assume that the compiler will always do that, especially with no optimisation enabled.

OK I see, thanks.

#8 lore raw
In reply to Peter Maydell
Quoted 6 lines · Peter Maydell
Quoted 3 lines

IIUC tcg_enabled(), this guard shouldn't be necessary; if CONFIG_TCG is not defined, tcg_enabled() evaluates to 0, and the compiler should elide the whole block.

IME it's a bit optimistic to assume that the compiler will always do that, especially with no optimisation enabled.

There's plenty of other places that we do. The compiler is usually pretty good with "if (0)".

My question is if

Quoted 1 line
      if (arm_feature(env, ARM_FEATURE_M) && tcg_enabled()) { 

needs to be written

    if (tcg_enabled()) {
        if (arm_feature(..., M) {
           ...
        }
    }

r~

#9 lore raw
Quoted 15 lines · Richard Henderson
Quoted 6 lines · Peter Maydell
Quoted 3 lines

IIUC tcg_enabled(), this guard shouldn't be necessary; if CONFIG_TCG is not defined, tcg_enabled() evaluates to 0, and the compiler should elide the whole block.

IME it's a bit optimistic to assume that the compiler will always do that, especially with no optimisation enabled.

There's plenty of other places that we do. The compiler is usually pretty good with "if (0)".

My question is if

Quoted 1 line
      if (arm_feature(env, ARM_FEATURE_M) && tcg_enabled()) { 
Quoted 7 lines

needs to be written

     if (tcg_enabled()) {
         if (arm_feature(..., M) {
            ...
         }
     }

Yeah, that doesn't work either. I don't understand why in this particular case the compiler seems unable to remove that code.

Can anyone else reproduce this or is it just happening on my setup? Maybe something is broken on my side...