Skip to contentSkip to conversation

target/arm/gdbstub: Fix builds when TCG is disabled

PATCH Applied Philippe Mathieu-Daudé 5 participants 12 messages Mar 22, 2023 – Mar 28, 2023

v1 of 2 Applied Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover target/arm/gdbstub: Fix builds when TCG is disabled

Fix when building QEMU configured with --disable-tcg:

Undefined symbols for architecture arm64:
"_arm_v7m_get_sp_ptr", referenced from:
_m_sysreg_get in target_arm_gdbstub.c.o
"_arm_v7m_mrs_control", referenced from:
_arm_gdb_get_m_systemreg in target_arm_gdbstub.c.o
"_pauth_ptr_mask", referenced from:
_aarch64_gdb_get_pauth_reg in target_arm_gdbstub64.c.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Philippe Mathieu-Daudé (2):
target/arm/gdbstub: Restrict aarch64_gdb_get_pauth_reg() to CONFIG_TCG target/arm/gdbstub: Only advertise M-profile features if TCG available

 target/arm/gdbstub.c   | 7 ++++---
 target/arm/gdbstub64.c | 4 ++++
 2 files changed, 8 insertions(+), 3 deletions(-)
Signature · 1 line
2.38.1
#1 lore raw

PATCH 1/2 target/arm/gdbstub: Restrict aarch64_gdb_get_pauth_reg() to CONFIG_TCG

aarch64_gdb_get_pauth_reg() -- although disabled since commit 5787d17a42 ("target/arm: Don't advertise aarch64-pauth.xml to gdb") is still compiled in. It calls pauth_ptr_mask() which is located in target/arm/tcg/pauth_helper.c, a TCG specific helper.

Restrict aarch64_gdb_get_pauth_reg() to TCG to avoid a linking error when TCG is not enabled:

Undefined symbols for architecture arm64:
"_pauth_ptr_mask", referenced from:
_aarch64_gdb_get_pauth_reg in target_arm_gdbstub64.c.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Fixes e995d5cce4 ("target/arm: Implement gdbstub pauth extension")
---
 target/arm/gdbstub.c   | 3 ++-
 target/arm/gdbstub64.c | 4 ++++
 2 files changed, 6 insertions(+), 1 deletion(-)
target/arm/gdbstub.c +2 -1
index 3bd86cee97..655369dc74 100644
@@ -21,6 +21,7 @@
 #include "cpu.h"
 #include "exec/gdbstub.h"
 #include "gdbstub/helpers.h"
+#include "sysemu/tcg.h"
 #include "internals.h"
 #include "cpregs.h"
 
@@ -526,7 +527,7 @@ void arm_cpu_register_gdb_regs_for_features(ARMCPU *cpu)
          * crash if they see this XML from QEMU; disable it for the 8.0
          * release, pending a better solution.
          */
-        if (isar_feature_aa64_pauth(&cpu->isar)) {
+        if (isar_feature_aa64_pauth(&cpu->isar) && tcg_enabled()) {
             gdb_register_coprocessor(cs, aarch64_gdb_get_pauth_reg,
                                      aarch64_gdb_set_pauth_reg,
                                      4, "aarch64-pauth.xml", 0);
target/arm/gdbstub64.c +4 -0
index ec1e07f139..3bb0923cbf 100644
@@ -210,6 +210,8 @@ int aarch64_gdb_set_sve_reg(CPUARMState *env, uint8_t *buf, int reg)
     return 0;
 }
 
+#ifdef CONFIG_TCG
+
 int aarch64_gdb_get_pauth_reg(CPUARMState *env, GByteArray *buf, int reg)
 {
     switch (reg) {
@@ -244,6 +246,8 @@ int aarch64_gdb_set_pauth_reg(CPUARMState *env, uint8_t *buf, int reg)
     return 0;
 }
 
+#endif
+
 static void output_vector_union_type(GString *s, int reg_width,
                                      const char *name)
 {
Signature · 1 line
2.38.1
#2 lore raw

Re: [PATCH-for-8.0 1/2] target/arm/gdbstub: Restrict aarch64_gdb_get_pauth_reg() to CONFIG_TCG

Quoted 5 lines · Philippe Mathieu-Daudé

aarch64_gdb_get_pauth_reg() -- although disabled since commit 5787d17a42 ("target/arm: Don't advertise aarch64-pauth.xml to gdb") is still compiled in. It calls pauth_ptr_mask() which is located in target/arm/tcg/pauth_helper.c, a TCG specific helper.

Quoted 8 lines

Restrict aarch64_gdb_get_pauth_reg() to TCG to avoid a linking error when TCG is not enabled:

Undefined symbols for architecture arm64:
"_pauth_ptr_mask", referenced from:
_aarch64_gdb_get_pauth_reg in target_arm_gdbstub64.c.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

I guess we should move this function somewhere else, because KVM can certainly use pauth, and we do want to be able to produce nice backtraces with gdb.

r~

#3 lore raw

Re: [PATCH-for-8.0 1/2] target/arm/gdbstub: Restrict aarch64_gdb_get_pauth_reg() to CONFIG_TCG

Quoted 9 lines · Richard Henderson
Quoted 8 lines · Philippe Mathieu-Daudé

aarch64_gdb_get_pauth_reg() -- although disabled since commit 5787d17a42 ("target/arm: Don't advertise aarch64-pauth.xml to gdb") is still compiled in. It calls pauth_ptr_mask() which is located in target/arm/tcg/pauth_helper.c, a TCG specific helper.

Restrict aarch64_gdb_get_pauth_reg() to TCG to avoid a linking error when TCG is not enabled:

Quoted 7 lines
Quoted 5 lines

   Undefined symbols for architecture arm64:
     "_pauth_ptr_mask", referenced from:
         _aarch64_gdb_get_pauth_reg in target_arm_gdbstub64.c.o
   ld: symbol(s) not found for architecture arm64
   clang: error: linker command failed with exit code 1 (use -v to see invocation)

I guess we should move this function somewhere else, because KVM can certainly use pauth, and we do want to be able to produce nice backtraces with gdb.

I ended inlining it (along with pauth_ptr_mask_internal, renamed as pauth_param_mask):

https://lore.kernel.org/qemu-devel/[email protected]/

#4 lore raw

PATCH 2/2 target/arm/gdbstub: Only advertise M-profile features if TCG available

In reply to Philippe Mathieu-Daudé

Cortex-M profile is only emulable from TCG accelerator. Restrict the GDBstub features to its availability in order to avoid a link error when TCG is not enabled:

Undefined symbols for architecture arm64:
"_arm_v7m_get_sp_ptr", referenced from:
_m_sysreg_get in target_arm_gdbstub.c.o
"_arm_v7m_mrs_control", referenced from:
_arm_gdb_get_m_systemreg in target_arm_gdbstub.c.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Fixes 7d8b28b8b5 ("target/arm: Implement gdbstub m-profile systemreg and secext")
---
 target/arm/gdbstub.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
target/arm/gdbstub.c +2 -2
index 655369dc74..2986ed6fc8 100644
@@ -554,7 +554,7 @@ void arm_cpu_register_gdb_regs_for_features(ARMCPU *cpu)
                                      2, "arm-vfp-sysregs.xml", 0);
         }
     }
-    if (cpu_isar_feature(aa32_mve, cpu)) {
+    if (cpu_isar_feature(aa32_mve, cpu) && tcg_enabled()) {
         gdb_register_coprocessor(cs, mve_gdb_get_reg, mve_gdb_set_reg,
                                  1, "arm-m-profile-mve.xml", 0);
     }
@@ -562,7 +562,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);
 
-    if (arm_feature(env, ARM_FEATURE_M)) {
+    if (arm_feature(env, ARM_FEATURE_M) && tcg_enabled()) {
         gdb_register_coprocessor(cs,
             arm_gdb_get_m_systemreg, arm_gdb_set_m_systemreg,
             arm_gen_dynamic_m_systemreg_xml(cs, cs->gdb_num_regs),
Signature · 1 line
2.38.1
Reviewed-by on v1 2/2
#5 lore raw

Re: [PATCH-for-8.0 2/2] target/arm/gdbstub: Only advertise M-profile features if TCG available

Quoted 12 lines · Philippe Mathieu-Daudé

Cortex-M profile is only emulable from TCG accelerator. Restrict the GDBstub features to its availability in order to avoid a link error when TCG is not enabled:

Undefined symbols for architecture arm64:
"_arm_v7m_get_sp_ptr", referenced from:
_m_sysreg_get in target_arm_gdbstub.c.o
"_arm_v7m_mrs_control", referenced from:
_arm_gdb_get_m_systemreg in target_arm_gdbstub.c.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Quoted 5 lines
Fixes 7d8b28b8b5 ("target/arm: Implement gdbstub m-profile systemreg and secext")
---
  target/arm/gdbstub.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)

r~

Reviewed-by on v1 2/2
#6 lore raw

Re: [PATCH-for-8.0 2/2] target/arm/gdbstub: Only advertise M-profile features if TCG available

In reply to Philippe Mathieu-Daudé
Quoted 12 lines · Philippe Mathieu-Daudé

Cortex-M profile is only emulable from TCG accelerator. Restrict the GDBstub features to its availability in order to avoid a link error when TCG is not enabled:

Undefined symbols for architecture arm64:
"_arm_v7m_get_sp_ptr", referenced from:
_m_sysreg_get in target_arm_gdbstub.c.o
"_arm_v7m_mrs_control", referenced from:
_arm_gdb_get_m_systemreg in target_arm_gdbstub.c.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Quoted 2 lines
Fixes 7d8b28b8b5 ("target/arm: Implement gdbstub m-profile systemreg and secext")
Signature · 2 lines
Alex Bennée
Virtualisation Tech Lead @ Linaro
#7 lore raw
In reply to Philippe Mathieu-Daudé
Quoted 11 lines · Philippe Mathieu-Daudé

Fix when building QEMU configured with --disable-tcg:

Undefined symbols for architecture arm64:
"_arm_v7m_get_sp_ptr", referenced from:
_m_sysreg_get in target_arm_gdbstub.c.o
"_arm_v7m_mrs_control", referenced from:
_arm_gdb_get_m_systemreg in target_arm_gdbstub.c.o
"_pauth_ptr_mask", referenced from:
_aarch64_gdb_get_pauth_reg in target_arm_gdbstub64.c.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Beside having the non-TCG configs tested in CI, (I think) we can avoid such breakage by moving the TCG-specific declarations from target/arm/internals.h to some target/arm/tcg/tcg-internals.h header. (target/arm/internals.h is 1400+ LoC anyway). Worth it?

#8 lore raw
Quoted 13 lines · Philippe Mathieu-Daudé
Quoted 11 lines · Philippe Mathieu-Daudé

Fix when building QEMU configured with --disable-tcg:

Undefined symbols for architecture arm64:
"_arm_v7m_get_sp_ptr", referenced from:
_m_sysreg_get in target_arm_gdbstub.c.o
"_arm_v7m_mrs_control", referenced from:
_arm_gdb_get_m_systemreg in target_arm_gdbstub.c.o
"_pauth_ptr_mask", referenced from:
_aarch64_gdb_get_pauth_reg in target_arm_gdbstub64.c.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Quoted 4 lines

Beside having the non-TCG configs tested in CI, (I think) we can avoid such breakage by moving the TCG-specific declarations from target/arm/internals.h to some target/arm/tcg/tcg-internals.h header. (target/arm/internals.h is 1400+ LoC anyway). Worth it?

I think it would be worth it. That still leaves the issue of these small functions that are semantically related to what is being emulated but don't need any TCG-specific symbols. It would be nice if we had a default approach for where to put them. Without going back to sticking everything in helper.c, of course. =)

#9 lore raw
In reply to Philippe Mathieu-Daudé
Quoted 13 lines · Philippe Mathieu-Daudé

Fix when building QEMU configured with --disable-tcg:

Undefined symbols for architecture arm64:
"_arm_v7m_get_sp_ptr", referenced from:
_m_sysreg_get in target_arm_gdbstub.c.o
"_arm_v7m_mrs_control", referenced from:
_arm_gdb_get_m_systemreg in target_arm_gdbstub.c.o
"_pauth_ptr_mask", referenced from:
_aarch64_gdb_get_pauth_reg in target_arm_gdbstub64.c.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Quoted 3 lines

Philippe Mathieu-Daudé (2):
target/arm/gdbstub: Restrict aarch64_gdb_get_pauth_reg() to CONFIG_TCG target/arm/gdbstub: Only advertise M-profile features if TCG available

I've applied patch 2 to target-arm.next; thanks.

-- PMM

#10 lore raw
Quoted 14 lines · Peter Maydell
Quoted 13 lines · Philippe Mathieu-Daudé

Fix when building QEMU configured with --disable-tcg:

Undefined symbols for architecture arm64:
"_arm_v7m_get_sp_ptr", referenced from:
_m_sysreg_get in target_arm_gdbstub.c.o
"_arm_v7m_mrs_control", referenced from:
_arm_gdb_get_m_systemreg in target_arm_gdbstub.c.o
"_pauth_ptr_mask", referenced from:
_aarch64_gdb_get_pauth_reg in target_arm_gdbstub64.c.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Quoted 5 lines
Quoted 3 lines

Philippe Mathieu-Daudé (2):
target/arm/gdbstub: Restrict aarch64_gdb_get_pauth_reg() to CONFIG_TCG target/arm/gdbstub: Only advertise M-profile features if TCG available

I've applied patch 2 to target-arm.next; thanks.

If you only take #2, then you need to squash this from #1:

-- >8 --

target/arm/gdbstub.c +1 -1
@@ -21,6 +21,7 @@
 #include "cpu.h"
 #include "exec/gdbstub.h"
 #include "gdbstub/helpers.h"
+#include "sysemu/tcg.h"
 #include "internals.h"
 #include "cpregs.h"
---

I can respin if it eases your workflow.

Thanks,

Phil.

#11 lore raw
Quoted 34 lines · Philippe Mathieu-Daudé
Quoted 14 lines · Peter Maydell
Quoted 13 lines · Philippe Mathieu-Daudé

Fix when building QEMU configured with --disable-tcg:

   Undefined symbols for architecture arm64:
     "_arm_v7m_get_sp_ptr", referenced from:
         _m_sysreg_get in target_arm_gdbstub.c.o "_arm_v7m_mrs_control", referenced from:
         _arm_gdb_get_m_systemreg in target_arm_gdbstub.c.o "_pauth_ptr_mask", referenced from:
         _aarch64_gdb_get_pauth_reg in target_arm_gdbstub64.c.o
   ld: symbol(s) not found for architecture arm64
   clang: error: linker command failed with exit code 1 (use -v to see invocation)

Quoted 5 lines
Quoted 3 lines

Philippe Mathieu-Daudé (2):
   target/arm/gdbstub: Restrict aarch64_gdb_get_pauth_reg() to CONFIG_TCG target/arm/gdbstub: Only advertise M-profile features if TCG available

I've applied patch 2 to target-arm.next; thanks.

If you only take #2, then you need to squash this from #1:

-- >8 --

target/arm/gdbstub.c +1 -1
@@ -21,6 +21,7 @@
  #include "cpu.h"
  #include "exec/gdbstub.h"
  #include "gdbstub/helpers.h"
+#include "sysemu/tcg.h"
  #include "internals.h"
  #include "cpregs.h"
---
Quoted 1 line

I can respin if it eases your workflow.

Posted as:
https://lore.kernel.org/qemu-devel/[email protected]/

Along with rth's suggestion as another patch.