path: root/src/exit
diff options
authorRich Felker <>2015-11-11 22:08:23 -0500
committerRich Felker <>2015-11-11 22:08:23 -0500
commitad1cd43a86645ba2d4f7c8747240452a349d6bc1 (patch)
treedb609558e4f10ed6554517d30b47bababec06c76 /src/exit
parent4aaf879eb08a22c501b43d8604e67614f7dbc55f (diff)
unify static and dynamic libc init/fini code paths
use weak definitions that the dynamic linker can override instead of preprocessor conditionals on SHARED so that the same libc start and exit code can be used for both static and dynamic linking.
Diffstat (limited to 'src/exit')
1 files changed, 10 insertions, 10 deletions
diff --git a/src/exit/exit.c b/src/exit/exit.c
index 163d8f1b..b391f338 100644
--- a/src/exit/exit.c
+++ b/src/exit/exit.c
@@ -11,24 +11,24 @@ static void dummy()
weak_alias(dummy, __funcs_on_exit);
weak_alias(dummy, __stdio_exit);
-#ifndef SHARED
-weak_alias(dummy, _fini);
+extern void _fini() __attribute__((weak));
extern void (*const __fini_array_start)() __attribute__((weak));
extern void (*const __fini_array_end)() __attribute__((weak));
-_Noreturn void exit(int code)
+static void libc_exit_fini(void)
- __funcs_on_exit();
-#ifndef SHARED
uintptr_t a = (uintptr_t)&__fini_array_end;
for (; a>(uintptr_t)&__fini_array_start; a-=sizeof(void(*)()))
(*(void (**)())(a-sizeof(void(*)())))();
- _fini();
+ if (_fini) _fini();
- __stdio_exit();
+weak_alias(libc_exit_fini, __libc_exit_fini);
+_Noreturn void exit(int code)
+ __funcs_on_exit();
+ __libc_exit_fini();
+ __stdio_exit();