public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] elf: Initialize GLRO(dl_lazy) before relocating libc in dynamic startup
@ 2023-12-08  9:12 Florian Weimer
  2023-12-08 13:26 ` Carlos O'Donell
  0 siblings, 1 reply; 2+ messages in thread
From: Florian Weimer @ 2023-12-08  9:12 UTC (permalink / raw)
  To: libc-alpha

GLRO(dl_lazy) is used to set the parameters for the early
_dl_relocate_object call, so the consider_profiling setting has to
be applied before the call.

Fixes commit 78ca44da0160a0b442f0ca1f253e3360f044b2ec ("elf: Relocate
libc.so early during startup and dlmopen (bug 31083)").

---
 elf/rtld.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/elf/rtld.c b/elf/rtld.c
index f0b0f3328d..326286f3b2 100644
--- a/elf/rtld.c
+++ b/elf/rtld.c
@@ -2278,14 +2278,14 @@ dl_main (const ElfW(Phdr) *phdr,
 
   int consider_profiling = GLRO(dl_profile) != NULL;
 
+  /* If we are profiling we also must do lazy reloaction.  */
+  GLRO(dl_lazy) |= consider_profiling;
+
   if (GL(dl_ns)[LM_ID_BASE].libc_map != NULL)
     _dl_relocate_object (GL(dl_ns)[LM_ID_BASE].libc_map,
 			 GL(dl_ns)[LM_ID_BASE].libc_map->l_scope,
 			 GLRO(dl_lazy) ? RTLD_LAZY : 0, consider_profiling);
 
-  /* If we are profiling we also must do lazy reloaction.  */
-  GLRO(dl_lazy) |= consider_profiling;
-
   RTLD_TIMING_VAR (start);
   rtld_timer_start (&start);
   {

base-commit: 958478889c6a7a12b35b857b9788b7ad8706a01e


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] elf: Initialize GLRO(dl_lazy) before relocating libc in dynamic startup
  2023-12-08  9:12 [PATCH] elf: Initialize GLRO(dl_lazy) before relocating libc in dynamic startup Florian Weimer
@ 2023-12-08 13:26 ` Carlos O'Donell
  0 siblings, 0 replies; 2+ messages in thread
From: Carlos O'Donell @ 2023-12-08 13:26 UTC (permalink / raw)
  To: Florian Weimer, libc-alpha

On 12/8/23 04:12, Florian Weimer wrote:
> GLRO(dl_lazy) is used to set the parameters for the early
> _dl_relocate_object call, so the consider_profiling setting has to
> be applied before the call.

Yes, GLRO(dl_lazy) must be set early enough for this to work for relocation,
and it should turn on if profiling is enabled. In the old code this wasn't
a problem because we only did the relocation later in a loop, but with early
init we need to set this earlier too.

> 
> Fixes commit 78ca44da0160a0b442f0ca1f253e3360f044b2ec ("elf: Relocate
> libc.so early during startup and dlmopen (bug 31083)").

Reviewed-by: Carlos O'Donell <carlos@redhat.com>


> ---
>  elf/rtld.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/elf/rtld.c b/elf/rtld.c
> index f0b0f3328d..326286f3b2 100644
> --- a/elf/rtld.c
> +++ b/elf/rtld.c
> @@ -2278,14 +2278,14 @@ dl_main (const ElfW(Phdr) *phdr,
>  
>    int consider_profiling = GLRO(dl_profile) != NULL;
>  
> +  /* If we are profiling we also must do lazy reloaction.  */
> +  GLRO(dl_lazy) |= consider_profiling;

OK. Agreed, this needs to move ahead of the *first* call to _dl_relocate_object().

> +
>    if (GL(dl_ns)[LM_ID_BASE].libc_map != NULL)
>      _dl_relocate_object (GL(dl_ns)[LM_ID_BASE].libc_map,
>  			 GL(dl_ns)[LM_ID_BASE].libc_map->l_scope,
>  			 GLRO(dl_lazy) ? RTLD_LAZY : 0, consider_profiling);
>  
> -  /* If we are profiling we also must do lazy reloaction.  */
> -  GLRO(dl_lazy) |= consider_profiling;
> -

OK.

>    RTLD_TIMING_VAR (start);
>    rtld_timer_start (&start);
>    {
> 
> base-commit: 958478889c6a7a12b35b857b9788b7ad8706a01e
> 

-- 
Cheers,
Carlos.


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-12-08 13:26 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-12-08  9:12 [PATCH] elf: Initialize GLRO(dl_lazy) before relocating libc in dynamic startup Florian Weimer
2023-12-08 13:26 ` 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).