summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRich Felker <dalias@aerifal.cx>2015-09-22 20:24:28 +0000
committerRich Felker <dalias@aerifal.cx>2015-09-22 20:24:28 +0000
commitc87a52103399135d2f57a91a8bcc749d8cb2ca83 (patch)
tree07d5dbff936447fba9d92c26126d4652c73a8a44 /src
parent78f430295c92ae15510082c04e537da4256aa7a7 (diff)
downloadmusl-c87a52103399135d2f57a91a8bcc749d8cb2ca83.tar.gz
musl-c87a52103399135d2f57a91a8bcc749d8cb2ca83.tar.bz2
musl-c87a52103399135d2f57a91a8bcc749d8cb2ca83.tar.xz
musl-c87a52103399135d2f57a91a8bcc749d8cb2ca83.zip
move calls to application init functions after crt1 entry point
this change is needed to be compatible with fdpic, where some of the main application's relocations may be performed as part of the crt1 entry point. if we call init functions before passing control, these relocations will not yet have been performed, and the init code will potentially make use of invalid pointers. conceptually, no code provided by the application or third-party libraries should run before the application entry point. the difference is not observable to programs using the crt1 we provide, but it could come into play if custom entry point code is used, so it's better to be doing this right anyway.
Diffstat (limited to 'src')
-rw-r--r--src/env/__libc_start_main.c3
-rw-r--r--src/ldso/dynlink.c6
2 files changed, 8 insertions, 1 deletions
diff --git a/src/env/__libc_start_main.c b/src/env/__libc_start_main.c
index f6f3b14a..d1f6a5e1 100644
--- a/src/env/__libc_start_main.c
+++ b/src/env/__libc_start_main.c
@@ -67,6 +67,9 @@ int __libc_start_main(int (*main)(int,char **,char **), int argc, char **argv)
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 */
diff --git a/src/ldso/dynlink.c b/src/ldso/dynlink.c
index 8967505a..f144aa59 100644
--- a/src/ldso/dynlink.c
+++ b/src/ldso/dynlink.c
@@ -1203,6 +1203,11 @@ static void do_init_fini(struct dso *p)
if (need_locking) pthread_mutex_unlock(&init_fini_lock);
}
+void __libc_start_init(void)
+{
+ do_init_fini(tail);
+}
+
static void dl_debug_state(void)
{
}
@@ -1630,7 +1635,6 @@ _Noreturn void __dls3(size_t *sp)
__init_libc(envp, argv[0]);
atexit(do_fini);
errno = 0;
- do_init_fini(tail);
CRTJMP((void *)aux[AT_ENTRY], argv-1);
for(;;);