Skip to contentSkip to conversation

gdbstub: attempt to split gdb into 32/64 bit targets [!WORKING PLZ HELP]

RFC PATCH In review Alex Bennée 2 participants 4 messages Mar 2, 2023 – Mar 3, 2023 Arm/Amlogic Meson SoC support

lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 gdbstub: attempt to split gdb into 32/64 bit targets [!WORKING PLZ HELP]

Instead of building gdb syscalls for every target only build what really matters, 64 or 32 bit support.

[AJB: Any clues or hints, I get a double linking compilation error:

FAILED: qemu-system-aarch64
c++ -m64 -mcx16 @qemu-system-aarch64.rsp
/usr/bin/ld: gdbstub/libgdb64.fa.p/syscalls.c.o: in function `use_gdb_syscalls':
/home/alex/lsrc/qemu.git/builds/all/../../gdbstub/syscalls.c:50: multiple definition of use_gdb_syscalls'; gdbstub/libgdb64.fa.p/syscalls.c.o:/home/alex/lsrc/qemu.git/builds/all/../../gdbstub/syscalls.c:50: first defined here /usr/bin/ld: gdbstub/libgdb64.fa.p/syscalls.c.o: in function gdb_disable_syscalls':
/home/alex/lsrc/qemu.git/builds/all/../../gdbstub/syscalls.c:71: multiple definition of `gdb_disable_syscalls'; gdbstub/libgdb64.fa.p/syscalls.c.o:/home/alex/lsrc/qemu.git/builds/all/../../gdbstub/syscalls.c:71: first defined here /usr/bin/ld: gdbstub/libgdb64.fa.p/syscalls.c.o: in function `gdb_syscall_reset':
/home/alex/lsrc/qemu.git/builds/all/../../gdbstub/syscalls.c:76: multiple definition of gdb_syscall_reset'; gdbstub/libgdb64.fa.p/syscalls.c.o:/home/alex/lsrc/qemu.git/builds/all/../../gdbstub/syscalls.c:76: first defined here /usr/bin/ld: gdbstub/libgdb64.fa.p/syscalls.c.o: in function gdb_handled_syscall':
/home/alex/lsrc/qemu.git/builds/all/../../gdbstub/syscalls.c:81: multiple definition of `gdb_handled_syscall'; gdbstub/libgdb64.fa.p/syscalls.c.o:/home/alex/lsrc/qemu.git/builds/all/../../gdbstub/syscalls.c:81: first defined here /usr/bin/ld: gdbstub/libgdb64.fa.p/syscalls.c.o: in function `gdb_attached':
/home/alex/lsrc/qemu.git/builds/all/../../gdbstub/syscalls.c:39: multiple definition of gdb_do_syscallv'; gdbstub/libgdb64.fa.p/syscalls.c.o:/home/alex/lsrc/qemu.git/builds/all/../../gdbstub/syscalls.c:39: first defined here /usr/bin/ld: gdbstub/libgdb64.fa.p/syscalls.c.o: in function gdb_do_syscall':
/home/alex/lsrc/qemu.git/builds/all/../../gdbstub/syscalls.c:156: multiple definition of gdb_do_syscall'; gdbstub/libgdb64.fa.p/syscalls.c.o:/home/alex/lsrc/qemu.git/builds/all/../../gdbstub/syscalls.c:156: first defined here /usr/bin/ld: gdbstub/libgdb64.fa.p/syscalls.c.o: in function gdb_handle_file_io':
/home/alex/lsrc/qemu.git/builds/all/../../gdbstub/syscalls.c:170: multiple definition of `gdb_handle_file_io'; gdbstub/libgdb64.fa.p/syscalls.c.o:/home/alex/lsrc/qemu.git/builds/all/../../gdbstub/syscalls.c:170: first defined here /usr/bin/ld: /lib/x86_64-linux-gnu/libtirpc.so.3: warning: common of `rpc_createerr@@GLIBC_2.2.5' overridden by definition from /lib/x86_64-linux-gnu/libc.so.6
collect2: error: ld returned 1 exit status
]

Based-on: <[email protected]>

---
 configs/targets/aarch64-linux-user.mak    |  1 +
 configs/targets/aarch64-softmmu.mak       |  1 +
 configs/targets/aarch64_be-linux-user.mak |  1 +
 configs/targets/alpha-linux-user.mak      |  1 +
 configs/targets/alpha-softmmu.mak         |  1 +
 configs/targets/arm-softmmu.mak           |  1 +
 configs/targets/sh4-linux-user.mak        |  1 +
 configs/targets/sh4-softmmu.mak           |  1 +
 configs/targets/sh4eb-linux-user.mak      |  1 +
 configs/targets/sh4eb-softmmu.mak         |  1 +
 include/exec/poison.h                     |  7 ++++++
 include/exec/target_long.h                |  7 ++++++
 gdbstub/syscalls.c                        |  3 ++-
 gdbstub/meson.build                       | 28 +++++++++++++++++++++--
 scripts/make-config-poison.sh             |  7 +++++-
 15 files changed, 58 insertions(+), 4 deletions(-)
configs/targets/aarch64-linux-user.mak +1 -0
index db552f1839..2f8d05d400 100644
@@ -1,5 +1,6 @@
 TARGET_ARCH=aarch64
 TARGET_BASE_ARCH=arm
+TARGET_64BIT=y
 TARGET_XML_FILES= gdb-xml/aarch64-core.xml gdb-xml/aarch64-fpu.xml
 TARGET_HAS_BFLT=y
 CONFIG_SEMIHOSTING=y
configs/targets/aarch64-softmmu.mak +1 -0
index d489e6da83..dacab8b96a 100644
@@ -1,5 +1,6 @@
 TARGET_ARCH=aarch64
 TARGET_BASE_ARCH=arm
+TARGET_64BIT=y
 TARGET_SUPPORTS_MTTCG=y
 TARGET_XML_FILES= gdb-xml/aarch64-core.xml gdb-xml/aarch64-fpu.xml gdb-xml/arm-core.xml gdb-xml/arm-vfp.xml gdb-xml/arm-vfp3.xml gdb-xml/arm-vfp-sysregs.xml gdb-xml/arm-neon.xml gdb-xml/arm-m-profile.xml gdb-xml/arm-m-profile-mve.xml
 TARGET_NEED_FDT=y
configs/targets/aarch64_be-linux-user.mak +1 -0
index dc78044fb1..f81ce2bcf2 100644
@@ -1,5 +1,6 @@
 TARGET_ARCH=aarch64
 TARGET_BASE_ARCH=arm
+TARGET_64BIT=y
 TARGET_BIG_ENDIAN=y
 TARGET_XML_FILES= gdb-xml/aarch64-core.xml gdb-xml/aarch64-fpu.xml
 TARGET_HAS_BFLT=y
configs/targets/alpha-linux-user.mak +1 -0
index 7e62fd796a..3714c1f6ae 100644
@@ -1,4 +1,5 @@
 TARGET_ARCH=alpha
+TARGET_32BIT=y
 TARGET_SYSTBL_ABI=common
 TARGET_SYSTBL=syscall.tbl
 TARGET_ALIGNED_ONLY=y
configs/targets/alpha-softmmu.mak +1 -0
index e4b874a19e..7c10ce4550 100644
@@ -1,3 +1,4 @@
 TARGET_ARCH=alpha
+TARGET_64BIT=y
 TARGET_ALIGNED_ONLY=y
 TARGET_SUPPORTS_MTTCG=y
configs/targets/arm-softmmu.mak +1 -0
index 92c8349b96..c06975ba86 100644
@@ -1,4 +1,5 @@
 TARGET_ARCH=arm
+TARGET_32BIT=y
 TARGET_SUPPORTS_MTTCG=y
 TARGET_XML_FILES= gdb-xml/arm-core.xml gdb-xml/arm-vfp.xml gdb-xml/arm-vfp3.xml gdb-xml/arm-vfp-sysregs.xml gdb-xml/arm-neon.xml gdb-xml/arm-m-profile.xml gdb-xml/arm-m-profile-mve.xml
 TARGET_NEED_FDT=y
configs/targets/sh4-linux-user.mak +1 -0
index 0152d6621e..39370af1ed 100644
@@ -1,4 +1,5 @@
 TARGET_ARCH=sh4
+TARGET_32BIT=y
 TARGET_SYSTBL_ABI=common
 TARGET_SYSTBL=syscall.tbl
 TARGET_ALIGNED_ONLY=y
configs/targets/sh4-softmmu.mak +1 -0
index 95896376c4..b632e874df 100644
@@ -1,2 +1,3 @@
 TARGET_ARCH=sh4
+TARGET_32BIT=y
 TARGET_ALIGNED_ONLY=y
configs/targets/sh4eb-linux-user.mak +1 -0
index 6724165efe..fdf04dea2b 100644
@@ -1,4 +1,5 @@
 TARGET_ARCH=sh4
+TARGET_32BIT=y
 TARGET_SYSTBL_ABI=common
 TARGET_SYSTBL=syscall.tbl
 TARGET_ALIGNED_ONLY=y
configs/targets/sh4eb-softmmu.mak +1 -0
index dc8b30bf7a..e95b7a5da9 100644
@@ -1,3 +1,4 @@
 TARGET_ARCH=sh4
+TARGET_32BIT=y
 TARGET_ALIGNED_ONLY=y
 TARGET_BIG_ENDIAN=y
include/exec/poison.h +7 -0
index 140daa4a85..69850b46fa 100644
@@ -42,10 +42,17 @@
 #pragma GCC poison TARGET_BIG_ENDIAN
 #pragma GCC poison BSWAP_NEEDED
 
+/*
+ * In some special cases we may define TARGET_LONG_BITS directly to
+ * build 32 and 64 bit versions of a common binary. Therefor if it is
+ * already defined for the compilation unit don't poison it.
+ */
+#ifndef TARGET_LONG_BITS
 #pragma GCC poison TARGET_LONG_BITS
 #pragma GCC poison TARGET_FMT_lx
 #pragma GCC poison TARGET_FMT_ld
 #pragma GCC poison TARGET_FMT_lu
+#endif
 
 #pragma GCC poison TARGET_PAGE_SIZE
 #pragma GCC poison TARGET_PAGE_MASK
include/exec/target_long.h +7 -0
index 93c9472971..5576543588 100644
@@ -20,6 +20,13 @@
 #error TARGET_LONG_BITS not defined
 #endif
 
+/* Sanity check with system configuration via configs/ */
+#if defined(TARGET_64BIT) && TARGET_LONG_BITS != 64
+#error system 64 bit configuration disagrees with cpu-param.h
+#elif defined(TARGET_32BIT) && TARGET_LONG_BITS != 32
+#error system 32 bit configuration disagrees with cpu-param.h
+#endif
+
 #define TARGET_LONG_SIZE (TARGET_LONG_BITS / 8)
 
 /* target_ulong is the type of a virtual address */
gdbstub/syscalls.c +2 -1
index 1ca3d81305..c01f4d0dea 100644
@@ -13,7 +13,8 @@
  */
 
 #include "qemu/osdep.h"
-#include "cpu.h"
+#include "exec/hwaddr.h"
+#include "exec/target_long.h"
 #include "semihosting/semihost.h"
 #include "sysemu/runstate.h"
 #include "gdbstub/user.h"
gdbstub/meson.build +26 -2
index d679c7ab86..c8b1f8361b 100644
@@ -31,8 +31,32 @@ user_ss.add(gdb_user)
 gdb_softmmu = declare_dependency(link_whole: libgdb_softmmu)
 softmmu_ss.add(gdb_softmmu)
 
-# These have to built to the target ABI
-specific_ss.add(files('syscalls.c'))
+# These have to built to the target ABI but are otherwise target
+# independent
+gdb32_ss = ss.source_set()
+gdb64_ss = ss.source_set()
+
+gdb32_ss.add(files('syscalls.c'))
+gdb64_ss.add(files('syscalls.c'))
+
+gdb32_ss = gdb32_ss.apply(config_host, strict: false)
+gdb64_ss = gdb64_ss.apply(config_host, strict: false)
+
+libgdb32 = static_library('gdb32', gdb32_ss.sources(),
+                          name_suffix: 'fa',
+                          c_args: ['-DTARGET_LONG_BITS=32'])
+libgdb64 = static_library('gdb64', gdb64_ss.sources(),
+                          name_suffix: 'fa',
+                          c_args: ['-DTARGET_LONG_BITS=64'])
+
+gdb32 = declare_dependency(link_whole: libgdb32)
+gdb64 = declare_dependency(link_whole: libgdb64)
+
+specific_ss.add(when: 'TARGET_64BIT', if_true: gdb64)
+specific_ss.add(when: 'TARGET_32BIT', if_true: gdb32)
+
+# finally add to specific_ss depending on the target bit size
+specific_ss.add(when: 'CONFIG_USER_ONLY', if_true: files('user-target.c'))
 
 # The user-target is specialised by the guest
 specific_ss.add(when: 'CONFIG_USER_ONLY', if_true: files('user-target.c'))
scripts/make-config-poison.sh +6 -1
index 1892854261..bbbff7c681 100755
@@ -5,10 +5,15 @@ if test $# = 0; then
 fi
 
 # Create list of config switches that should be poisoned in common code...
-# but filter out CONFIG_TCG and CONFIG_USER_ONLY which are special.
+# but filter out those which are special including:
+#   CONFIG_TCG
+#   CONFIG_USER_ONLY
+#   TARGET_[32|64]_BIT
 exec sed -n \
   -e' /CONFIG_TCG/d' \
   -e '/CONFIG_USER_ONLY/d' \
+  -e '/TARGET_64BIT/d' \
+  -e '/TARGET_32BIT/d' \
   -e '/^#define / {' \
   -e    's///' \
   -e    's/ .*//' \
Signature · 1 line
2.39.2
#1 lore raw

gdbstub/meson.build user_ss.add(gdb_user) · line 43

Quoted 12 lines · Alex Bennée
gdbstub/meson.build +10 -2
-# These have to built to the target ABI
-specific_ss.add(files('syscalls.c'))
+# These have to built to the target ABI but are otherwise target
+# independent
+gdb32_ss = ss.source_set()
+gdb64_ss = ss.source_set()
+
+gdb32_ss.add(files('syscalls.c'))
+gdb64_ss.add(files('syscalls.c'))
+
+gdb32_ss = gdb32_ss.apply(config_host, strict: false)
+gdb64_ss = gdb64_ss.apply(config_host, strict: false)

You don't need the source sets.

gdbstub/meson.build user_ss.add(gdb_user) · line 53

Quoted 9 lines
gdbstub/meson.build +9 -0
+libgdb32 = static_library('gdb32', gdb32_ss.sources(),
+                          name_suffix: 'fa',
+                          c_args: ['-DTARGET_LONG_BITS=32'])
+libgdb64 = static_library('gdb64', gdb64_ss.sources(),
+                          name_suffix: 'fa',
+                          c_args: ['-DTARGET_LONG_BITS=64'])
+
+gdb32 = declare_dependency(link_whole: libgdb32)
+gdb64 = declare_dependency(link_whole: libgdb64)

It appears to work with "link_with:".

Both comments apply here and to your gdb_user/gdb_softmmu libraries.

r~

#2 lore raw
Quoted 28 lines · Richard Henderson

gdbstub/meson.build user_ss.add(gdb_user) · line 43

Quoted 12 lines · Alex Bennée
gdbstub/meson.build +10 -2
-# These have to built to the target ABI
-specific_ss.add(files('syscalls.c'))
+# These have to built to the target ABI but are otherwise target
+# independent
+gdb32_ss = ss.source_set()
+gdb64_ss = ss.source_set()
+
+gdb32_ss.add(files('syscalls.c'))
+gdb64_ss.add(files('syscalls.c'))
+
+gdb32_ss = gdb32_ss.apply(config_host, strict: false)
+gdb64_ss = gdb64_ss.apply(config_host, strict: false)

You don't need the source sets.

gdbstub/meson.build user_ss.add(gdb_user) · line 53

Quoted 9 lines
gdbstub/meson.build +9 -0
+libgdb32 = static_library('gdb32', gdb32_ss.sources(),
+                          name_suffix: 'fa',
+                          c_args: ['-DTARGET_LONG_BITS=32'])
+libgdb64 = static_library('gdb64', gdb64_ss.sources(),
+                          name_suffix: 'fa',
+                          c_args: ['-DTARGET_LONG_BITS=64'])
+
+gdb32 = declare_dependency(link_whole: libgdb32)
+gdb64 = declare_dependency(link_whole: libgdb64)

It appears to work with "link_with:".

Quoted 1 line

Both comments apply here and to your gdb_user/gdb_softmmu libraries.

Hmm. It worked for qemu-system-aarch64, but not qemu-system-avr. I'm at a bit of a loss...

r~

#3 lore raw
In reply to Alex Bennée
Quoted 2 lines · Alex Bennée

Instead of building gdb syscalls for every target only build what really matters, 64 or 32 bit support.

Since the *only* usage of target_ulong is in the va_list for gdb_do_syscall, and as that passes on to printf, we could just adjust the interface to always pass uint64_t.

r~