From ad1cd43a86645ba2d4f7c8747240452a349d6bc1 Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Wed, 11 Nov 2015 22:08:23 -0500 Subject: 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. --- src/env/__libc_start_main.c | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) (limited to 'src/env') diff --git a/src/env/__libc_start_main.c b/src/env/__libc_start_main.c index d1f6a5e1..7ffada0b 100644 --- a/src/env/__libc_start_main.c +++ b/src/env/__libc_start_main.c @@ -8,21 +8,15 @@ void __init_tls(size_t *); -#ifndef SHARED -static void dummy() {} -weak_alias(dummy, _init); +extern void _init() __attribute__((weak)); extern void (*const __init_array_start)() __attribute__((weak)); extern void (*const __init_array_end)() __attribute__((weak)); -#endif static void dummy1(void *p) {} weak_alias(dummy1, __init_ssp); #define AUX_CNT 38 -#ifndef SHARED -static -#endif void __init_libc(char **envp, char *pn) { size_t i, *auxv, aux[AUX_CNT] = { 0 }; @@ -57,20 +51,22 @@ void __init_libc(char **envp, char *pn) libc.secure = 1; } +static void libc_start_init(void) +{ + if (_init) _init(); + uintptr_t a = (uintptr_t)&__init_array_start; + for (; a<(uintptr_t)&__init_array_end; a+=sizeof(void(*)())) + (*(void (**)())a)(); +} + +weak_alias(libc_start_init, __libc_start_init); + int __libc_start_main(int (*main)(int,char **,char **), int argc, char **argv) { char **envp = argv+argc+1; -#ifndef SHARED __init_libc(envp, argv[0]); - _init(); - uintptr_t a = (uintptr_t)&__init_array_start; - for (; a<(uintptr_t)&__init_array_end; a+=sizeof(void(*)())) - (*(void (**)())a)(); -#else - void __libc_start_init(void); __libc_start_init(); -#endif /* Pass control to the application */ exit(main(argc, argv, envp)); -- cgit v1.2.3-70-g09d2