Bug 28130 - DT_DEBUG doesn't work with COPY relocation
Summary: DT_DEBUG doesn't work with COPY relocation
Status: NEW
Alias: None
Product: glibc
Classification: Unclassified
Component: dynamic-link (show other bugs)
Version: 2.34
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-07-24 18:29 UTC by H.J. Lu
Modified: 2021-07-24 21:01 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description H.J. Lu 2021-07-24 18:29:41 UTC
rtld.c has

  /* Initialize _r_debug.  */
  struct r_debug *r = _dl_debug_initialize (GL(dl_rtld_map).l_addr,
                                            LM_ID_BASE);

  if (main_map->l_info[DT_DEBUG] != NULL)
    /* There is a DT_DEBUG entry in the dynamic section.  Fill it in
       with the run-time address of the r_debug structure  */
    main_map->l_info[DT_DEBUG]->d_un.d_ptr = (ElfW(Addr)) r;

With COPY relocation, the real address of _r_debug may be in the executable
if it references _r_debug.  If debugger uses DT_DEBUG, it will reference the
staled original definition of _r_debug in ld.so.
Comment 1 H.J. Lu 2021-07-24 19:00:38 UTC
We can hide _r_debug and add

extern struct r_debug * __r_debug_location (void) __attribute_const__;
#define _r_debug (*__r_debug_location (())
Comment 2 Andreas Schwab 2021-07-24 20:28:28 UTC
Nothing should be using _r_debug.
Comment 3 H.J. Lu 2021-07-24 20:45:30 UTC
(In reply to Andreas Schwab from comment #2)
> Nothing should be using _r_debug.

_r_debug is exported and used by glibc tests.
Comment 4 Andreas Schwab 2021-07-24 21:01:31 UTC
That doesn't matter.