[PATCH] gdb: Don't assume r_ldsomap when r_version > 1 on Linux

H.J. Lu hjl.tools@gmail.com
Tue Aug 17 13:44:22 GMT 2021


On Tue, Aug 17, 2021 at 6:09 AM Simon Marchi <simon.marchi@polymtl.ca> wrote:
>
>
>
> On 2021-08-16 9:15 p.m., H.J. Lu via Gdb-patches wrote:
> > glibc is planning to add a field to support multiple namespaces.  But
> > there will be no r_ldsomap when r_version is bumped to 2.  Add
> > linux_[ilp32|lp64]_fetch_link_map_offsets to set r_ldsomap_offset to -1
> > and use them for Linux targets.
>
> As Carlos mentioned in the Buzilla thread, r_ldsomap is specific to
> Solaris.  It would be good to mention that in the commit message,
> because that helps understand the patch (and is probably not very well
> known).

I will send out the v2 patch with the updated commit message.

> Just to be clear, is this new version 2 specific to Linux or glibc?  A
> system using another libc won't use that layout, unless that other libc
> copies what glibc does?  I'm thinking that another libc could use
> version == 2, but for a different layout, in which case we would have to
> have callbacks specific to each libc.  Or, is there coordination between
> various libcs about how to evolve this layout?

We will discuss this with other Linux libcs to address.  I am extending
struct r_debug with:

   /* The following field is added by r_version == 2.  */

    /* Link to the next r_debug_extended structure.  Each r_debug_extended
       structure represents a different namespace.  The first
       r_debug_extended structure is for the default namespace.  */
    struct r_debug_extended *r_next;

If a Linux libc bumps r_version to 2, it needs to add r_next and set it
to NULL even if it is unused,

> >       PR gdb/28236
> >       * aarch64-linux-tdep.c (aarch64_linux_init_abi): Replace
> >       svr4_[ilp32|lp64]_fetch_link_map_offsets with
> >       linux_[ilp32|lp64]_fetch_link_map_offsets.
> >       * alpha-linux-tdep.c (alpha_linux_init_abi): Likewise.
> >       * amd64-linux-tdep.c (amd64_linux_init_abi): Likewise.
> >       (amd64_x32_linux_init_abi): Likewise.
> >       * ia64-linux-tdep.c (ia64_linux_init_abi): Likewise.
> >       * mips-linux-tdep.c (mips_linux_init_abi): Likewise.
> >       * ppc-linux-tdep.c (ppc_linux_init_abi): Likewise.
> >       * riscv-linux-tdep.c (riscv_linux_init_abi): Likewise.
> >       * s390-linux-tdep.c (s390_linux_init_abi_31): Likewise.
> >       (s390_linux_init_abi_64): Likewise.
> >       * sparc64-linux-tdep.c (sparc64_linux_init_abi): Likewise.
> >       * tilegx-linux-tdep.c (tilegx_linux_init_abi): Likewise.
> >       * linux-tdep.c: Include "solib-svr4.h".
> >       (linux_ilp32_fetch_link_map_offsets): New.
> >       (linux_lp64_fetch_link_map_offsets): Likewise.
> >       * linux-tdep.h (linux_ilp32_fetch_link_map_offsets): New.
> >       (linux_lp64_fetch_link_map_offsets): Likewise.
>
> Note that GDB doesn't use ChangeLogs anymore.  You can use
>
> Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=28236
>
> At the bottom to link to the Bugzilla entry.
>
> > ---
> >  gdb/aarch64-linux-tdep.c |  2 +-
> >  gdb/alpha-linux-tdep.c   |  2 +-
> >  gdb/amd64-linux-tdep.c   |  4 +--
> >  gdb/ia64-linux-tdep.c    |  2 +-
> >  gdb/linux-tdep.c         | 60 ++++++++++++++++++++++++++++++++++++++++
> >  gdb/linux-tdep.h         |  5 ++++
> >  gdb/mips-linux-tdep.c    |  6 ++--
> >  gdb/ppc-linux-tdep.c     |  4 +--
> >  gdb/riscv-linux-tdep.c   |  4 +--
> >  gdb/s390-linux-tdep.c    |  4 +--
> >  gdb/sparc64-linux-tdep.c |  2 +-
> >  gdb/tilegx-linux-tdep.c  |  4 +--
>
> I don't understand why some *-linux-tdep.c are changed but not all.  Do
> the following files need to be changed too?
>
>  - arc-linux-tdep.c
>  - arm-linux-tdep.c
>  - cris-linux-tdep.c
>  - csky-linux-tdep.c
>  - i386-linux-tdep.c
>  - m32r-linux-tdep.c
>  - m68k-linux-tdep.c
>  - microblaze-linux-tdep.c
>  - mn10300-linux-tdep.c
>  - nios2-linux-tdep.c
>  - or1k-linux-tdep.c
>  - sh-linux-tdep.c
>  - sparc-linux-tdep.c
>  - xtensa-linux-tdep.c

Will be fixed in the v2 patch.

> >  12 files changed, 82 insertions(+), 17 deletions(-)
> >
> > diff --git a/gdb/aarch64-linux-tdep.c b/gdb/aarch64-linux-tdep.c
> > index 63c200b47f7..b1225438d9d 100644
> > --- a/gdb/aarch64-linux-tdep.c
> > +++ b/gdb/aarch64-linux-tdep.c
> > @@ -1795,7 +1795,7 @@ aarch64_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
> >    linux_init_abi (info, gdbarch, 1);
> >
> >    set_solib_svr4_fetch_link_map_offsets (gdbarch,
> > -                                      svr4_lp64_fetch_link_map_offsets);
> > +                                      linux_lp64_fetch_link_map_offsets);
> >
> >    /* Enable TLS support.  */
> >    set_gdbarch_fetch_tls_load_module_address (gdbarch,
> > diff --git a/gdb/alpha-linux-tdep.c b/gdb/alpha-linux-tdep.c
> > index c2cffc13c20..0a00fc1f310 100644
> > --- a/gdb/alpha-linux-tdep.c
> > +++ b/gdb/alpha-linux-tdep.c
> > @@ -374,7 +374,7 @@ alpha_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
> >    set_gdbarch_skip_trampoline_code (gdbarch, find_solib_trampoline_target);
> >
> >    set_solib_svr4_fetch_link_map_offsets
> > -    (gdbarch, svr4_lp64_fetch_link_map_offsets);
> > +    (gdbarch, linux_lp64_fetch_link_map_offsets);
> >
> >    /* Enable TLS support.  */
> >    set_gdbarch_fetch_tls_load_module_address (gdbarch,
> > diff --git a/gdb/amd64-linux-tdep.c b/gdb/amd64-linux-tdep.c
> > index ac6843c1fdd..715add8a7b0 100644
> > --- a/gdb/amd64-linux-tdep.c
> > +++ b/gdb/amd64-linux-tdep.c
> > @@ -2042,7 +2042,7 @@ amd64_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
> >
> >    /* GNU/Linux uses SVR4-style shared libraries.  */
> >    set_solib_svr4_fetch_link_map_offsets
> > -    (gdbarch, svr4_lp64_fetch_link_map_offsets);
> > +    (gdbarch, linux_lp64_fetch_link_map_offsets);
> >
> >    /* Register DTrace handlers.  */
> >    set_gdbarch_dtrace_parse_probe_argument (gdbarch, amd64_dtrace_parse_probe_argument);
> > @@ -2256,7 +2256,7 @@ amd64_x32_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
> >
> >    /* GNU/Linux uses SVR4-style shared libraries.  */
> >    set_solib_svr4_fetch_link_map_offsets
> > -    (gdbarch, svr4_ilp32_fetch_link_map_offsets);
> > +    (gdbarch, linux_ilp32_fetch_link_map_offsets);
> >  }
> >
> >  void _initialize_amd64_linux_tdep ();
> > diff --git a/gdb/ia64-linux-tdep.c b/gdb/ia64-linux-tdep.c
> > index a17ec590002..71767ddf83e 100644
> > --- a/gdb/ia64-linux-tdep.c
> > +++ b/gdb/ia64-linux-tdep.c
> > @@ -237,7 +237,7 @@ ia64_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
> >    set_gdbarch_skip_trampoline_code (gdbarch, find_solib_trampoline_target);
> >
> >    set_solib_svr4_fetch_link_map_offsets
> > -    (gdbarch, svr4_lp64_fetch_link_map_offsets);
> > +    (gdbarch, linux_lp64_fetch_link_map_offsets);
> >
> >    /* Enable TLS support.  */
> >    set_gdbarch_fetch_tls_load_module_address (gdbarch,
> > diff --git a/gdb/linux-tdep.c b/gdb/linux-tdep.c
> > index 637d3d36a0b..92ecedfd1cf 100644
> > --- a/gdb/linux-tdep.c
> > +++ b/gdb/linux-tdep.c
> > @@ -41,6 +41,7 @@
> >  #include "gdbsupport/gdb_optional.h"
> >  #include "gcore.h"
> >  #include "gcore-elf.h"
> > +#include "solib-svr4.h"
> >
> >  #include <ctype.h>
> >
> > @@ -2724,3 +2725,62 @@ more information about this file, refer to the manpage of proc(5) and core(5).")
> >                          NULL, show_dump_excluded_mappings,
> >                          &setlist, &showlist);
> >  }
> > +
> > +/* Fetch (and possibly build) an appropriate `struct link_map_offsets'
> > +   for ILP32/LP64 Linux systems which don't have the r_ldsomap field.  */
> > +
> > +struct link_map_offsets *
>
> Remove the `struct` keyword where possible.

Fixed.

> > +linux_ilp32_fetch_link_map_offsets (void)
>
> Remove void (here and at all other spots it appears).

Fixed.

> > +{
> > +  static struct link_map_offsets lmo;
> > +  static struct link_map_offsets *lmp = NULL;
>
> Replace NULL with nullptr throughout.

Fixed.

> Simon

Thanks.

-- 
H.J.


More information about the Gdb-patches mailing list