Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20151129153051.GN23362@port70.net>
Date: Sun, 29 Nov 2015 16:30:51 +0100
From: Szabolcs Nagy <nsz@...t70.net>
To: musl@...ts.openwall.com
Subject: [PATCH 1/2] init_array/fini_array cleanup

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

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.