about summary refs log tree commit diff
path: root/src/env/__libc_start_main.c
diff options
context:
space:
mode:
authorRich Felker <dalias@aerifal.cx>2018-10-17 22:28:51 -0400
committerRich Felker <dalias@aerifal.cx>2018-10-17 22:28:51 -0400
commit7136836e14e5286afe74a354c289601375bd472d (patch)
treee97e94acd8098038229e0ccccb410352c93a941f /src/env/__libc_start_main.c
parent4390383b32250a941ec616e8bff6f568a801b1c0 (diff)
downloadmusl-7136836e14e5286afe74a354c289601375bd472d.tar.gz
musl-7136836e14e5286afe74a354c289601375bd472d.tar.xz
musl-7136836e14e5286afe74a354c289601375bd472d.zip
document and make explicit desired noinline property for __init_libc
on multiple occasions I've started to flatten/inline the code in
__init_libc, only to rediscover the reason it was not inlined: GCC
fails to deallocate its stack (and now, with the changes in commit
4390383b32250a941ec616e8bff6f568a801b1c0, fails to produce a tail call
to the stage 2 function; see PR #87639) before calling main if it was
inlined.

document this with a comment and use an explicit noinline attribute if
__GNUC__ is defined so that even with CFLAGS that heavily favor
inlining it won't get inlined.
Diffstat (limited to 'src/env/__libc_start_main.c')
-rw-r--r--src/env/__libc_start_main.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/src/env/__libc_start_main.c b/src/env/__libc_start_main.c
index ba4d2135..2e5f9dcb 100644
--- a/src/env/__libc_start_main.c
+++ b/src/env/__libc_start_main.c
@@ -17,6 +17,9 @@ weak_alias(dummy1, __init_ssp);
 
 #define AUX_CNT 38
 
+#ifdef __GNUC__
+__attribute__((__noinline__))
+#endif
 void __init_libc(char **envp, char *pn)
 {
 	size_t i, *auxv, aux[AUX_CNT] = { 0 };
@@ -69,6 +72,9 @@ int __libc_start_main(int (*main)(int,char **,char **), int argc, char **argv)
 {
 	char **envp = argv+argc+1;
 
+	/* External linkage, and explicit noinline attribute if available,
+	 * are used to prevent the stack frame used during init from
+	 * persisting for the entire process lifetime. */
 	__init_libc(envp, argv[0]);
 
 	/* Barrier against hoisting application code or anything using ssp