* [PATCH] static-PIE: Update DT_DEBUG for debugger [BZ #23206]
@ 2018-05-29 12:08 H.J. Lu
2018-05-29 13:21 ` Carlos O'Donell
0 siblings, 1 reply; 2+ messages in thread
From: H.J. Lu @ 2018-05-29 12:08 UTC (permalink / raw)
To: GNU C Library
This is needed to support debugging dlopened shared libraries in static
PIE.
OK for master?
H.J.
[BZ #23206]
* elf/dl-reloc-static-pie.c (_dl_relocate_static_pie): Initialize
_r_debug and update DT_DEBUG for debugger.
---
elf/dl-reloc-static-pie.c | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
diff --git a/elf/dl-reloc-static-pie.c b/elf/dl-reloc-static-pie.c
index bd2d516e5d..ab1ce0eacc 100644
--- a/elf/dl-reloc-static-pie.c
+++ b/elf/dl-reloc-static-pie.c
@@ -48,5 +48,21 @@ _dl_relocate_static_pie (void)
data access using the global offset table. */
ELF_DYNAMIC_RELOCATE (main_map, 0, 0, 0);
main_map->l_relocated = 1;
+
+ /* Initialize _r_debug. */
+ struct r_debug *r = _dl_debug_initialize (0, LM_ID_BASE);
+ r->r_state = RT_CONSISTENT;
+
+ /* Set up debugging before the debugger is notified for the first
+ time. */
+# ifdef ELF_MACHINE_DEBUG_SETUP
+ /* Some machines (e.g. MIPS) don't use DT_DEBUG in this way. */
+ ELF_MACHINE_DEBUG_SETUP (main_map, r);
+# else
+ 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;
+# endif
}
#endif
--
2.17.0
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] static-PIE: Update DT_DEBUG for debugger [BZ #23206]
2018-05-29 12:08 [PATCH] static-PIE: Update DT_DEBUG for debugger [BZ #23206] H.J. Lu
@ 2018-05-29 13:21 ` Carlos O'Donell
0 siblings, 0 replies; 2+ messages in thread
From: Carlos O'Donell @ 2018-05-29 13:21 UTC (permalink / raw)
To: H.J. Lu, GNU C Library
On 05/29/2018 08:08 AM, H.J. Lu wrote:
> This is needed to support debugging dlopened shared libraries in static
> PIE.
>
> OK for master?
>
This looks good. We always need to setup r_debug properly and this looks
like the right solution to me. IIUC we set RT_CONSISTENT at this point because
we are consistent (not doing anything with the link map the debugger needs to
be aware of).
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
> H.J.
> [BZ #23206]
> * elf/dl-reloc-static-pie.c (_dl_relocate_static_pie): Initialize
> _r_debug and update DT_DEBUG for debugger.
> ---
> elf/dl-reloc-static-pie.c | 16 ++++++++++++++++
> 1 file changed, 16 insertions(+)
>
> diff --git a/elf/dl-reloc-static-pie.c b/elf/dl-reloc-static-pie.c
> index bd2d516e5d..ab1ce0eacc 100644
> --- a/elf/dl-reloc-static-pie.c
> +++ b/elf/dl-reloc-static-pie.c
> @@ -48,5 +48,21 @@ _dl_relocate_static_pie (void)
> data access using the global offset table. */
> ELF_DYNAMIC_RELOCATE (main_map, 0, 0, 0);
> main_map->l_relocated = 1;
> +
> + /* Initialize _r_debug. */
> + struct r_debug *r = _dl_debug_initialize (0, LM_ID_BASE);
> + r->r_state = RT_CONSISTENT;
> +
> + /* Set up debugging before the debugger is notified for the first
> + time. */
> +# ifdef ELF_MACHINE_DEBUG_SETUP
> + /* Some machines (e.g. MIPS) don't use DT_DEBUG in this way. */
> + ELF_MACHINE_DEBUG_SETUP (main_map, r);
> +# else
> + 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;
> +# endif
> }
> #endif
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2018-05-29 13:21 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-05-29 12:08 [PATCH] static-PIE: Update DT_DEBUG for debugger [BZ #23206] H.J. Lu
2018-05-29 13:21 ` Carlos O'Donell
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).