Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src Upgrade the SVR4 RTLD r_debug protocol to version 1



details:   https://anonhg.NetBSD.org/src/rev/6265f95d0e93
branches:  trunk
changeset: 938951:6265f95d0e93
user:      kamil <kamil%NetBSD.org@localhost>
date:      Mon Sep 21 16:08:57 2020 +0000

description:
Upgrade the SVR4 RTLD r_debug protocol to version 1

Changes:
 - Add a new field r_ldbase in the r_debug struct.
 - Set r_version to 1.

This harmonizes the support with OpenBSD and Linux.
FreeBSD uses version 0 (or no version).
Solaris uses version 2 that is not implemented elsewhere and relies on
SVR4 specific design and interfaces.

Update the code comments as r_debug and link_map is used by other software
than GDB, namely: sanitizers, rump, LLDB.

diffstat:

 include/link_elf.h       |   5 ++++-
 libexec/ld.elf_so/load.c |   6 +++---
 libexec/ld.elf_so/rtld.c |  14 ++++++++------
 libexec/ld.elf_so/rtld.h |   4 ++--
 4 files changed, 17 insertions(+), 12 deletions(-)

diffs (129 lines):

diff -r a948322151cd -r 6265f95d0e93 include/link_elf.h
--- a/include/link_elf.h        Mon Sep 21 15:31:54 2020 +0000
+++ b/include/link_elf.h        Mon Sep 21 16:08:57 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: link_elf.h,v 1.11 2020/09/21 02:20:27 kamil Exp $      */
+/*     $NetBSD: link_elf.h,v 1.12 2020/09/21 16:08:57 kamil Exp $      */
 
 #ifndef _LINK_ELF_H_
 #define        _LINK_ELF_H_
@@ -6,6 +6,8 @@
 #include <sys/types.h>
 #include <sys/exec_elf.h>
 
+#define R_DEBUG_VERSION        1 /* SVR4 Protocol version */
+
 typedef struct link_map {
        caddr_t          l_addr;        /* Base Address of library */
 #ifdef __mips__
@@ -43,6 +45,7 @@
                RT_ADD,                 /* adding a shared library */
                RT_DELETE               /* removing a shared library */
        } r_state;
+       void *r_ldbase;                 /* base address of RTLD */
 };
 
 struct dl_phdr_info
diff -r a948322151cd -r 6265f95d0e93 libexec/ld.elf_so/load.c
--- a/libexec/ld.elf_so/load.c  Mon Sep 21 15:31:54 2020 +0000
+++ b/libexec/ld.elf_so/load.c  Mon Sep 21 16:08:57 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: load.c,v 1.48 2017/01/10 21:08:48 christos Exp $        */
+/*     $NetBSD: load.c,v 1.49 2020/09/21 16:08:57 kamil Exp $   */
 
 /*
  * Copyright 1996 John D. Polstra.
@@ -40,7 +40,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: load.c,v 1.48 2017/01/10 21:08:48 christos Exp $");
+__RCSID("$NetBSD: load.c,v 1.49 2020/09/21 16:08:57 kamil Exp $");
 #endif /* not lint */
 
 #include <sys/types.h>
@@ -180,7 +180,7 @@
                _rtld_objcount++;
                _rtld_objloads++;
 #ifdef RTLD_LOADER
-               _rtld_linkmap_add(obj); /* for GDB */
+               _rtld_linkmap_add(obj); /* for the debugger */
 #endif
                dbg(("  %p .. %p: %s", obj->mapbase,
                    obj->mapbase + obj->mapsize - 1, obj->path));
diff -r a948322151cd -r 6265f95d0e93 libexec/ld.elf_so/rtld.c
--- a/libexec/ld.elf_so/rtld.c  Mon Sep 21 15:31:54 2020 +0000
+++ b/libexec/ld.elf_so/rtld.c  Mon Sep 21 16:08:57 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: rtld.c,v 1.205 2020/04/19 01:06:15 joerg Exp $  */
+/*     $NetBSD: rtld.c,v 1.206 2020/09/21 16:08:57 kamil Exp $  */
 
 /*
  * Copyright 1996 John D. Polstra.
@@ -40,7 +40,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: rtld.c,v 1.205 2020/04/19 01:06:15 joerg Exp $");
+__RCSID("$NetBSD: rtld.c,v 1.206 2020/09/21 16:08:57 kamil Exp $");
 #endif /* not lint */
 
 #include <sys/param.h>
@@ -81,7 +81,7 @@
  */
 static char    *error_message; /* Message for dlopen(), or NULL */
 
-struct r_debug  _rtld_debug;   /* for GDB; */
+struct r_debug  _rtld_debug;   /* The SVR4 interface for the debugger */
 bool            _rtld_trust;   /* False for setuid and setgid programs */
 Obj_Entry      *_rtld_objlist; /* Head of linked list of shared objects */
 Obj_Entry     **_rtld_objtail; /* Link field of last object in list */
@@ -394,8 +394,10 @@
        _rtld_objtail = &_rtld_objlist;
        _rtld_objcount = 0;
 
+       _rtld_debug.r_version = R_DEBUG_VERSION;
        _rtld_debug.r_brk = _rtld_debug_state;
        _rtld_debug.r_state = RT_CONSISTENT;
+       _rtld_debug.r_ldbase = &_rtld_objself.linkmap;
 
        ehdr = (Elf_Ehdr *)mapbase;
        _rtld_objself.phdr = (Elf_Phdr *)((char *)mapbase + ehdr->e_phoff);
@@ -676,8 +678,8 @@
        /*
         * Get the actual dynamic linker pathname from the executable if
         * possible.  (It should always be possible.)  That ensures that
-        * gdb will find the right dynamic linker even if a non-standard
-        * one is being used.
+        * the debugger will find the right dynamic linker even if a
+        * non-standard one is being used.
         */
        if (_rtld_objmain->interp != NULL &&
            strcmp(_rtld_objmain->interp, _rtld_objself.path) != 0) {
@@ -774,7 +776,7 @@
        if (real___mainprog_obj)
                *real___mainprog_obj = _rtld_objmain;
 
-       _rtld_debug_state();    /* say hello to gdb! */
+       _rtld_debug_state();    /* say hello to the debugger! */
 
        _rtld_exclusive_enter(&mask);
 
diff -r a948322151cd -r 6265f95d0e93 libexec/ld.elf_so/rtld.h
--- a/libexec/ld.elf_so/rtld.h  Mon Sep 21 15:31:54 2020 +0000
+++ b/libexec/ld.elf_so/rtld.h  Mon Sep 21 16:08:57 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: rtld.h,v 1.140 2020/04/19 01:06:15 joerg Exp $  */
+/*     $NetBSD: rtld.h,v 1.141 2020/09/21 16:08:57 kamil Exp $  */
 
 /*
  * Copyright 1996 John D. Polstra.
@@ -226,7 +226,7 @@
                        sysv_hash:1,    /* SysV Hash available */
                        gnu_hash:1;     /* GNU Hash available */
 
-       struct link_map linkmap;        /* for GDB */
+       struct link_map linkmap;        /* for the debugger */
 
        /* These items are computed by map_object() or by digest_phdr(). */
        const char     *interp; /* Pathname of the interpreter, if any */



Home | Main Index | Thread Index | Old Index