mailing list of musl libc
 help / color / mirror / code / Atom feed
* [PATCH 1/2] init_array/fini_array cleanup
@ 2015-11-29 15:30 Szabolcs Nagy
  2015-11-29 16:47 ` Szabolcs Nagy
  0 siblings, 1 reply; 3+ messages in thread
From: Szabolcs Nagy @ 2015-11-29 15:30 UTC (permalink / raw)
  To: musl

use correct types to access the array (not consistent with dynlink.c).
---
not sure if the declarations in dynlink.c can be changed as well
while keeping the end->start weak alias.

 src/env/__libc_start_main.c | 8 ++++----
 src/exit/exit.c             | 8 ++++----
 2 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/src/env/__libc_start_main.c b/src/env/__libc_start_main.c
index 5c79be2..f9c7ca5 100644
--- a/src/env/__libc_start_main.c
+++ b/src/env/__libc_start_main.c
@@ -12,7 +12,7 @@ static void dummy(void) {}
 weak_alias(dummy, _init);
 
 __attribute__((__weak__, __visibility__("hidden")))
-extern void (*const __init_array_start)(void), (*const __init_array_end)(void);
+extern void (*const __init_array_start[])(void), (*const __init_array_end[])(void);
 
 static void dummy1(void *p) {}
 weak_alias(dummy1, __init_ssp);
@@ -55,10 +55,10 @@ void __init_libc(char **envp, char *pn)
 
 static void libc_start_init(void)
 {
+	void (*const *f)(void);
 	_init();
-	uintptr_t a = (uintptr_t)&__init_array_start;
-	for (; a<(uintptr_t)&__init_array_end; a+=sizeof(void(*)()))
-		(*(void (**)())a)();
+	for (f=__init_array_start; f<__init_array_end; f++)
+		(*f)();
 }
 
 weak_alias(libc_start_init, __libc_start_init);
diff --git a/src/exit/exit.c b/src/exit/exit.c
index bf7835a..5c17290 100644
--- a/src/exit/exit.c
+++ b/src/exit/exit.c
@@ -13,13 +13,13 @@ weak_alias(dummy, __stdio_exit);
 weak_alias(dummy, _fini);
 
 __attribute__((__weak__, __visibility__("hidden")))
-extern void (*const __fini_array_start)(void), (*const __fini_array_end)(void);
+extern void (*const __fini_array_start[])(void), (*const __fini_array_end[])(void);
 
 static void libc_exit_fini(void)
 {
-	uintptr_t a = (uintptr_t)&__fini_array_end;
-	for (; a>(uintptr_t)&__fini_array_start; a-=sizeof(void(*)()))
-		(*(void (**)())(a-sizeof(void(*)())))();
+	void (*const *f)(void);
+	for (f=__fini_array_end; f>__fini_array_start; f--)
+		f[-1]();
 	_fini();
 }
 
-- 
2.4.1



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2015-11-29 23:25 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-11-29 15:30 [PATCH 1/2] init_array/fini_array cleanup Szabolcs Nagy
2015-11-29 16:47 ` Szabolcs Nagy
2015-11-29 23:25   ` Rich Felker

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).