[binutils-gdb] regdat.sh: generate const_target_desc_up for register descriptions

Keith Seitz via Gdb-cvs <[email protected]> Tue, 7 Jul 2026 19:49:04 +0000 (GMT)
Newsgroups gmane.comp.gdb.cvs
Message-ID <[email protected]>
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=d839c0e5ab5a1c08d0a110b31f54d17946d4fc8b

commit d839c0e5ab5a1c08d0a110b31f54d17946d4fc8b
Author: Keith Seitz <[email protected]>
Date:   Tue Jul 7 12:10:08 2026 -0700

    regdat.sh: generate const_target_desc_up for register descriptions
    
    Late last year, a patch propagated the use of target_desc unique
    pointers (commit 1a5362ce51ef79ffb61caa20c93284dc368dc74a).  At the
    time, the "old regformats/regdat.sh [weren't] changed because their
    target_desc objects are statically allocated in the generated files."
    
    Unfortunately that re-introduced ODR violations on ppc64le:
    
    CXXLD  gdbserver
    ../../src/gdbserver/../gdb/arch/ppc-linux-tdesc.h:46:29: error: ‘tdesc_powerpc_isa207_htm_vsx64l’ violates the C++ One Definition Rule [-Werror=odr]
       46 | extern const_target_desc_up tdesc_powerpc_isa207_htm_vsx64l;
          |                             ^
    powerpc-isa207-htm-vsx64l-generated.cc:26:27: note: ‘tdesc_powerpc_isa207_htm_vsx64l’ was previously declared here
       26 | const struct target_desc *tdesc_powerpc_isa207_htm_vsx64l;
          |                           ^
    powerpc-isa207-htm-vsx64l-generated.cc:26:27: note: code may be misoptimized unless ‘-fno-strict-aliasing’ is used
    
    Update regdat.sh so that generated init_registers_* code matches the
    const-unique_ptr-based target description API, resolving the ODR violation.
    
    A follow-up patch updates various gdbserver architectures to
    accommodate this API change.
    
    Tested on ppc64le and s390x Fedora 43 and mips-linux
    cross build (all with LTO).
    
    Approved-By: Simon Marchi <[email protected]>
    Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=28444

Diff:
---
 gdb/regformats/regdat.sh | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/gdb/regformats/regdat.sh b/gdb/regformats/regdat.sh
index aeb41f6b7ad..b57b76132aa 100755
--- a/gdb/regformats/regdat.sh
+++ b/gdb/regformats/regdat.sh
@@ -125,7 +125,7 @@ do
   if test "${type}" = "name"; then
     name="${entry}"
 
-    echo "const struct target_desc *tdesc_${name};"
+    echo "const_target_desc_up tdesc_${name};"
     echo ""
 
     # This is necessary for -Wmissing-declarations.
@@ -134,9 +134,8 @@ do
     echo "void"
     echo "init_registers_${name} (void)"
     echo "{"
-    echo "  static struct target_desc tdesc_${name}_s;"
-    echo "  struct target_desc *result = &tdesc_${name}_s;"
-    echo "  struct tdesc_feature *feature = tdesc_create_feature (result, \"${name}\");"
+    echo "  target_desc_up result = allocate_target_description ();"
+    echo "  struct tdesc_feature *feature = tdesc_create_feature (result.get (), \"${name}\");"
     continue
   elif test "${type}" = "xmltarget"; then
     xmltarget="${entry}"
@@ -198,9 +197,9 @@ cat <<EOF
   result->xmltarget = xmltarget_${name};
 #endif
 
-  init_target_desc (result, expedite_regs_${name}, ${osabi_enum});
+  init_target_desc (result.get (), expedite_regs_${name}, ${osabi_enum});
 
-  tdesc_${name} = result;
+  tdesc_${name} = std::move (result);
 }
 EOF