public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [PATCH v2] elf: Assume disjointed .rela.dyn and .rela.plt for loader
@ 2021-11-01 20:23 Adhemerval Zanella
  2021-11-01 20:27 ` H.J. Lu
  0 siblings, 1 reply; 2+ messages in thread
From: Adhemerval Zanella @ 2021-11-01 20:23 UTC (permalink / raw)
  To: libc-alpha

The patch removes the the ELF_DURING_STARTUP optimization and assume
both .rel.dyn and .rel.plt might not be subsequent.  This allows some
code simplification since relocation will be handled independently
where it is done on bootstrap.

At least on x86_64_64, I can not measure any performance implications.
Running 10000 time the command

  LD_DEBUG=statistics ./elf/ld.so ./libc.so

And filtering the "total startup time in dynamic loader" result,
the geometric mean is:

                  patched       master
  Ryzen 7 5900x     24140        24952
  i7-4510U          45957        45982

(The results do show some variation, I did not make any statistical
analysis).

It also allows build arm with lld, since it inserts ".ARM.exidx"
between ".rel.dyn" and ".rel.plt" for the loader.

Checked on x86_64-linux-gnu and arm-linux-gnueabihf.
---
 elf/dynamic-link.h | 32 +++++++++-----------------------
 1 file changed, 9 insertions(+), 23 deletions(-)

diff --git a/elf/dynamic-link.h b/elf/dynamic-link.h
index ac4cc70dea..f619615e5c 100644
--- a/elf/dynamic-link.h
+++ b/elf/dynamic-link.h
@@ -65,12 +65,6 @@ elf_machine_lazy_rel (struct link_map *map, struct r_scope_elem *scope[],
 
 #ifdef RESOLVE_MAP
 
-# if defined RTLD_BOOTSTRAP || defined STATIC_PIE_BOOTSTRAP
-#  define ELF_DURING_STARTUP (1)
-# else
-#  define ELF_DURING_STARTUP (0)
-# endif
-
 /* Get the definitions of `elf_dynamic_do_rel' and `elf_dynamic_do_rela'.
    These functions are almost identical, so we use cpp magic to avoid
    duplicating their code.  It cannot be done in a more general function
@@ -106,9 +100,8 @@ elf_machine_lazy_rel (struct link_map *map, struct r_scope_elem *scope[],
 									      \
 	if (ranges[0].start + ranges[0].size == (start + size))		      \
 	  ranges[0].size -= size;					      \
-	if (ELF_DURING_STARTUP						      \
-	    || (!(do_lazy)						      \
-		&& (ranges[0].start + ranges[0].size) == start))	      \
+	if (!(do_lazy)							      \
+	    && (ranges[0].start + ranges[0].size) == start)		      \
 	  {								      \
 	    /* Combine processing the sections.  */			      \
 	    ranges[0].size += size;					      \
@@ -121,20 +114,13 @@ elf_machine_lazy_rel (struct link_map *map, struct r_scope_elem *scope[],
 	  }								      \
       }									      \
 									      \
-    if (ELF_DURING_STARTUP)						      \
-      elf_dynamic_do_##reloc ((map), scope, ranges[0].start, ranges[0].size,  \
-			      ranges[0].nrelative, 0, skip_ifunc);  \
-    else								      \
-      {									      \
-	int ranges_index;						      \
-	for (ranges_index = 0; ranges_index < 2; ++ranges_index)	      \
-	  elf_dynamic_do_##reloc ((map), scope,				      \
-				  ranges[ranges_index].start,		      \
-				  ranges[ranges_index].size,		      \
-				  ranges[ranges_index].nrelative,	      \
-				  ranges[ranges_index].lazy,		      \
-				  skip_ifunc);		      \
-      }									      \
+      for (int ranges_index = 0; ranges_index < 2; ++ranges_index)	      \
+        elf_dynamic_do_##reloc ((map), scope,				      \
+				ranges[ranges_index].start,		      \
+				ranges[ranges_index].size,		      \
+				ranges[ranges_index].nrelative,		      \
+				ranges[ranges_index].lazy,		      \
+				skip_ifunc);				      \
   } while (0)
 
 # if ELF_MACHINE_NO_REL || ELF_MACHINE_NO_RELA
-- 
2.32.0


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

* Re: [PATCH v2] elf: Assume disjointed .rela.dyn and .rela.plt for loader
  2021-11-01 20:23 [PATCH v2] elf: Assume disjointed .rela.dyn and .rela.plt for loader Adhemerval Zanella
@ 2021-11-01 20:27 ` H.J. Lu
  0 siblings, 0 replies; 2+ messages in thread
From: H.J. Lu @ 2021-11-01 20:27 UTC (permalink / raw)
  To: Adhemerval Zanella; +Cc: GNU C Library

On Mon, Nov 1, 2021 at 1:23 PM Adhemerval Zanella
<adhemerval.zanella@linaro.org> wrote:
>
> The patch removes the the ELF_DURING_STARTUP optimization and assume
> both .rel.dyn and .rel.plt might not be subsequent.  This allows some
> code simplification since relocation will be handled independently
> where it is done on bootstrap.
>
> At least on x86_64_64, I can not measure any performance implications.
> Running 10000 time the command
>
>   LD_DEBUG=statistics ./elf/ld.so ./libc.so
>
> And filtering the "total startup time in dynamic loader" result,
> the geometric mean is:
>
>                   patched       master
>   Ryzen 7 5900x     24140        24952
>   i7-4510U          45957        45982
>
> (The results do show some variation, I did not make any statistical
> analysis).
>
> It also allows build arm with lld, since it inserts ".ARM.exidx"
> between ".rel.dyn" and ".rel.plt" for the loader.
>
> Checked on x86_64-linux-gnu and arm-linux-gnueabihf.
> ---
>  elf/dynamic-link.h | 32 +++++++++-----------------------
>  1 file changed, 9 insertions(+), 23 deletions(-)
>
> diff --git a/elf/dynamic-link.h b/elf/dynamic-link.h
> index ac4cc70dea..f619615e5c 100644
> --- a/elf/dynamic-link.h
> +++ b/elf/dynamic-link.h
> @@ -65,12 +65,6 @@ elf_machine_lazy_rel (struct link_map *map, struct r_scope_elem *scope[],
>
>  #ifdef RESOLVE_MAP
>
> -# if defined RTLD_BOOTSTRAP || defined STATIC_PIE_BOOTSTRAP
> -#  define ELF_DURING_STARTUP (1)
> -# else
> -#  define ELF_DURING_STARTUP (0)
> -# endif
> -
>  /* Get the definitions of `elf_dynamic_do_rel' and `elf_dynamic_do_rela'.
>     These functions are almost identical, so we use cpp magic to avoid
>     duplicating their code.  It cannot be done in a more general function
> @@ -106,9 +100,8 @@ elf_machine_lazy_rel (struct link_map *map, struct r_scope_elem *scope[],
>                                                                               \
>         if (ranges[0].start + ranges[0].size == (start + size))               \
>           ranges[0].size -= size;                                             \
> -       if (ELF_DURING_STARTUP                                                \
> -           || (!(do_lazy)                                                    \
> -               && (ranges[0].start + ranges[0].size) == start))              \
> +       if (!(do_lazy)                                                        \
> +           && (ranges[0].start + ranges[0].size) == start)                   \
>           {                                                                   \
>             /* Combine processing the sections.  */                           \
>             ranges[0].size += size;                                           \
> @@ -121,20 +114,13 @@ elf_machine_lazy_rel (struct link_map *map, struct r_scope_elem *scope[],
>           }                                                                   \
>        }                                                                              \
>                                                                               \
> -    if (ELF_DURING_STARTUP)                                                  \
> -      elf_dynamic_do_##reloc ((map), scope, ranges[0].start, ranges[0].size,  \
> -                             ranges[0].nrelative, 0, skip_ifunc);  \
> -    else                                                                     \
> -      {                                                                              \
> -       int ranges_index;                                                     \
> -       for (ranges_index = 0; ranges_index < 2; ++ranges_index)              \
> -         elf_dynamic_do_##reloc ((map), scope,                               \
> -                                 ranges[ranges_index].start,                 \
> -                                 ranges[ranges_index].size,                  \
> -                                 ranges[ranges_index].nrelative,             \
> -                                 ranges[ranges_index].lazy,                  \
> -                                 skip_ifunc);                \
> -      }                                                                              \
> +      for (int ranges_index = 0; ranges_index < 2; ++ranges_index)           \
> +        elf_dynamic_do_##reloc ((map), scope,                                \
> +                               ranges[ranges_index].start,                   \
> +                               ranges[ranges_index].size,                    \
> +                               ranges[ranges_index].nrelative,               \
> +                               ranges[ranges_index].lazy,                    \
> +                               skip_ifunc);                                  \
>    } while (0)
>
>  # if ELF_MACHINE_NO_REL || ELF_MACHINE_NO_RELA
> --
> 2.32.0
>

LGTM.

Reviewed-by: H.J. Lu <hjl.tools@gmail.com>

Thanks.

-- 
H.J.

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

end of thread, other threads:[~2021-11-01 20:27 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-01 20:23 [PATCH v2] elf: Assume disjointed .rela.dyn and .rela.plt for loader Adhemerval Zanella
2021-11-01 20:27 ` H.J. Lu

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).