elf: Simplify _dl_aux_init with inhibit_loop_to_libcall

Message ID 20220330041104.931987-1-maskray@google.com
State Rejected
Headers
Series elf: Simplify _dl_aux_init with inhibit_loop_to_libcall |

Checks

Context Check Description
dj/TryBot-apply_patch success Patch applied to master at the time it was sent
dj/TryBot-32bit success Build for i686

Commit Message

Fangrui Song March 30, 2022, 4:11 a.m. UTC
  ---
 elf/Makefile     | 5 -----
 elf/dl-support.c | 9 ++++-----
 2 files changed, 4 insertions(+), 10 deletions(-)
  

Comments

Szabolcs Nagy March 31, 2022, 8:56 a.m. UTC | #1
The 03/29/2022 21:11, Fangrui Song wrote:
> +/* Inhibit memset for auxv_values initialization because memset may not
> +   be available yet.  */
> +inhibit_loop_to_libcall
>  void
>  _dl_aux_init (ElfW(auxv_t) *av)
>  {
> @@ -254,11 +257,7 @@ _dl_aux_init (ElfW(auxv_t) *av)
>  #endif
>  
>    _dl_auxv = av;
> -  dl_parse_auxv_t auxv_values;
> -  /* Use an explicit initialization loop here because memset may not
> -     be available yet.  */
> -  for (int i = 0; i < array_length (auxv_values); ++i)
> -    auxv_values[i] = 0;
> +  dl_parse_auxv_t auxv_values = { 0 };
>    _dl_parse_auxv (av, auxv_values);

this does not work for me
https://godbolt.org/z/s49TMP3z7
  

Patch

diff --git a/elf/Makefile b/elf/Makefile
index c96924e9c2..281551d380 100644
--- a/elf/Makefile
+++ b/elf/Makefile
@@ -160,11 +160,6 @@  ifeq (yes,$(have-loop-to-function))
 CFLAGS-rtld.c += -fno-tree-loop-distribute-patterns
 endif
 
-ifeq (yes,$(have-loop-to-function))
-# Likewise, during static library startup, memset is not yet available.
-CFLAGS-dl-support.c = -fno-tree-loop-distribute-patterns
-endif
-
 # Compile rtld itself without stack protection.
 # Also compile all routines in the static library that are elided from
 # the shared libc because they are in libc.a in the same way.
diff --git a/elf/dl-support.c b/elf/dl-support.c
index 153dd57ad2..b886a1462c 100644
--- a/elf/dl-support.c
+++ b/elf/dl-support.c
@@ -245,6 +245,9 @@  __rtld_lock_define_initialized_recursive (, _dl_load_tls_lock)
 
 int _dl_clktck;
 
+/* Inhibit memset for auxv_values initialization because memset may not
+   be available yet.  */
+inhibit_loop_to_libcall
 void
 _dl_aux_init (ElfW(auxv_t) *av)
 {
@@ -254,11 +257,7 @@  _dl_aux_init (ElfW(auxv_t) *av)
 #endif
 
   _dl_auxv = av;
-  dl_parse_auxv_t auxv_values;
-  /* Use an explicit initialization loop here because memset may not
-     be available yet.  */
-  for (int i = 0; i < array_length (auxv_values); ++i)
-    auxv_values[i] = 0;
+  dl_parse_auxv_t auxv_values = { 0 };
   _dl_parse_auxv (av, auxv_values);
 }
 #endif