[3/7] stdlib: Move _IO_cleanup to call_function_static_weak

Message ID 20221115193159.173838-4-adhemerval.zanella@linaro.org
State Committed
Commit 5dcd2d0ad02ff12c76355ef4f40947c1857ac482
Headers
Series Fixing remaining lld issues |

Checks

Context Check Description
dj/TryBot-apply_patch success Patch applied to master at the time it was sent

Commit Message

Adhemerval Zanella Nov. 15, 2022, 7:31 p.m. UTC
  ---
 Makerules      | 3 ---
 libio/genops.c | 2 --
 stdlib/exit.c  | 6 ++----
 3 files changed, 2 insertions(+), 9 deletions(-)
  

Comments

Florian Weimer Dec. 12, 2022, 10:52 a.m. UTC | #1
* Adhemerval Zanella via Libc-alpha:

> ---
>  Makerules      | 3 ---
>  libio/genops.c | 2 --
>  stdlib/exit.c  | 6 ++----
>  3 files changed, 2 insertions(+), 9 deletions(-)
>
> diff --git a/Makerules b/Makerules
> index a41491429e..3226b7a12b 100644
> --- a/Makerules
> +++ b/Makerules
> @@ -568,9 +568,6 @@ $(common-objpfx)shlib.lds: $(common-objpfx)config.make $(..)Makerules
>  		 PROVIDE(__start___libc_subfreeres = .);\
>  		 __libc_subfreeres : { *(__libc_subfreeres) }\
>  		 PROVIDE(__stop___libc_subfreeres = .);\
> -		 PROVIDE(__start___libc_atexit = .);\
> -		 __libc_atexit : { *(__libc_atexit) }\
> -		 PROVIDE(__stop___libc_atexit = .);\
>  		 PROVIDE(__start___libc_IO_vtables = .);\
>  		 __libc_IO_vtables : { *(__libc_IO_vtables) }\
>  		 PROVIDE(__stop___libc_IO_vtables = .);\
> diff --git a/libio/genops.c b/libio/genops.c
> index 1b629eb695..8a7fc4f7c5 100644
> --- a/libio/genops.c
> +++ b/libio/genops.c
> @@ -1115,5 +1115,3 @@ _IO_list_resetlock (void)
>  #endif
>  }
>  libc_hidden_def (_IO_list_resetlock)
> -
> -text_set_element(__libc_atexit, _IO_cleanup);
> diff --git a/stdlib/exit.c b/stdlib/exit.c
> index 10c44e1449..98579fbda8 100644
> --- a/stdlib/exit.c
> +++ b/stdlib/exit.c
> @@ -20,11 +20,9 @@
>  #include <unistd.h>
>  #include <pointer_guard.h>
>  #include <libc-lock.h>
> +#include <libio/libioP.h>
>  #include "exit.h"
>  
> -#include "set-hooks.h"
> -DEFINE_HOOK (__libc_atexit, (void))
> -
>  /* Initialize the flag that indicates exit function processing
>     is complete. See concurrency notes in stdlib/exit.h where
>     __exit_funcs_lock is declared.  */
> @@ -128,7 +126,7 @@ __run_exit_handlers (int status, struct exit_function_list **listp,
>    __libc_lock_unlock (__exit_funcs_lock);
>  
>    if (run_list_atexit)
> -    RUN_HOOK (__libc_atexit, ());
> +    call_function_static_weak (_IO_cleanup);
>  
>    _exit (status);
>  }

This change looks okay to me.

Reviewed-by: Florian Weimer <fweimer@redhat.com>

Thanks,
Florian
  
Joseph Myers Dec. 13, 2022, 4:52 p.m. UTC | #2
This commit has exposed a LoongArch linker bug (affecting several IFUNC 
testcases); I don't know why.

https://sourceware.org/pipermail/libc-testresults/2022q4/010595.html

collect2: fatal error: ld terminated with signal 11 [Segmentation fault], core dumped
compilation terminated.
make[3]: *** [../Rules:301: /scratch/jmyers/glibc/many12/build/glibcs/loongarch64-linux-gnu-lp64d/glibc/elf/ifuncmain1static] Error 1

Maybe the LoongArch people could investigate to see if there is some fix 
that could be applied to binutils 2.39 branch?  (At least in combination 
with GCC mainline, this doesn't appear with binutils mainline, so it will 
probably also be resolved when we move build-many-glibcs.py to binutils 
2.40 branch after 2.40 is released in mid-January, if not fixed before 
then.)
  

Patch

diff --git a/Makerules b/Makerules
index a41491429e..3226b7a12b 100644
--- a/Makerules
+++ b/Makerules
@@ -568,9 +568,6 @@  $(common-objpfx)shlib.lds: $(common-objpfx)config.make $(..)Makerules
 		 PROVIDE(__start___libc_subfreeres = .);\
 		 __libc_subfreeres : { *(__libc_subfreeres) }\
 		 PROVIDE(__stop___libc_subfreeres = .);\
-		 PROVIDE(__start___libc_atexit = .);\
-		 __libc_atexit : { *(__libc_atexit) }\
-		 PROVIDE(__stop___libc_atexit = .);\
 		 PROVIDE(__start___libc_IO_vtables = .);\
 		 __libc_IO_vtables : { *(__libc_IO_vtables) }\
 		 PROVIDE(__stop___libc_IO_vtables = .);\
diff --git a/libio/genops.c b/libio/genops.c
index 1b629eb695..8a7fc4f7c5 100644
--- a/libio/genops.c
+++ b/libio/genops.c
@@ -1115,5 +1115,3 @@  _IO_list_resetlock (void)
 #endif
 }
 libc_hidden_def (_IO_list_resetlock)
-
-text_set_element(__libc_atexit, _IO_cleanup);
diff --git a/stdlib/exit.c b/stdlib/exit.c
index 10c44e1449..98579fbda8 100644
--- a/stdlib/exit.c
+++ b/stdlib/exit.c
@@ -20,11 +20,9 @@ 
 #include <unistd.h>
 #include <pointer_guard.h>
 #include <libc-lock.h>
+#include <libio/libioP.h>
 #include "exit.h"
 
-#include "set-hooks.h"
-DEFINE_HOOK (__libc_atexit, (void))
-
 /* Initialize the flag that indicates exit function processing
    is complete. See concurrency notes in stdlib/exit.h where
    __exit_funcs_lock is declared.  */
@@ -128,7 +126,7 @@  __run_exit_handlers (int status, struct exit_function_list **listp,
   __libc_lock_unlock (__exit_funcs_lock);
 
   if (run_list_atexit)
-    RUN_HOOK (__libc_atexit, ());
+    call_function_static_weak (_IO_cleanup);
 
   _exit (status);
 }