From: Szabolcs Nagy <nsz@port70.net>
To: musl@lists.openwall.com
Subject: [PATCH 2/2] add preinit_array support
Date: Sun, 29 Nov 2015 16:33:22 +0100 [thread overview]
Message-ID: <20151129153322.GO23362@port70.net> (raw)
handle DT_PREINIT_ARRAY{SZ} in case of dynamic linking and
__preinit_array_{start,end} in case of static linking.
redefined DYN_CNT because 32 is not enough for DT_PREINIT_ARRAY.
---
src/env/__libc_start_main.c | 5 +++++
src/ldso/dynlink.c | 12 ++++++++++--
2 files changed, 15 insertions(+), 2 deletions(-)
diff --git a/src/env/__libc_start_main.c b/src/env/__libc_start_main.c
index f9c7ca5..d4cc0ef 100644
--- a/src/env/__libc_start_main.c
+++ b/src/env/__libc_start_main.c
@@ -12,6 +12,9 @@ static void dummy(void) {}
weak_alias(dummy, _init);
__attribute__((__weak__, __visibility__("hidden")))
+extern void (*const __preinit_array_start[])(void), (*const __preinit_array_end[])(void);
+
+__attribute__((__weak__, __visibility__("hidden")))
extern void (*const __init_array_start[])(void), (*const __init_array_end[])(void);
static void dummy1(void *p) {}
@@ -57,6 +60,8 @@ static void libc_start_init(void)
{
void (*const *f)(void);
_init();
+ for (f=__preinit_array_start; f<__preinit_array_end; f++)
+ (*f)();
for (f=__init_array_start; f<__init_array_end; f++)
(*f)();
}
diff --git a/src/ldso/dynlink.c b/src/ldso/dynlink.c
index 93e7d67..623818a 100644
--- a/src/ldso/dynlink.c
+++ b/src/ldso/dynlink.c
@@ -135,11 +135,14 @@ static struct fdpic_dummy_loadmap app_dummy_loadmap;
struct debug *_dl_debug_addr = &debug;
__attribute__((__visibility__("hidden")))
-void (*const __init_array_start)(void)=0, (*const __fini_array_start)(void)=0;
+void (*const __init_array_start)(void)=0, (*const __fini_array_start)(void)=0,
+(*const __preinit_array_start)(void)=0;
__attribute__((__visibility__("hidden")))
-extern void (*const __init_array_end)(void), (*const __fini_array_end)(void);
+extern void (*const __init_array_end)(void), (*const __fini_array_end)(void),
+(*const __preinit_array_end)(void);
+weak_alias(__preinit_array_start, __preinit_array_end);
weak_alias(__init_array_start, __init_array_end);
weak_alias(__fini_array_start, __fini_array_end);
@@ -1229,6 +1232,11 @@ static void do_init_fini(struct dso *p)
if ((dyn[0] & (1<<DT_INIT)) && dyn[DT_INIT])
fpaddr(p, dyn[DT_INIT])();
#endif
+ if (dyn[0] & (1UL<<DT_PREINIT_ARRAY)) {
+ size_t n = dyn[DT_PREINIT_ARRAYSZ]/sizeof(size_t);
+ size_t *fn = laddr(p, dyn[DT_PREINIT_ARRAY]);
+ while (n--) ((void (*)(void))*fn++)();
+ }
if (dyn[0] & (1<<DT_INIT_ARRAY)) {
size_t n = dyn[DT_INIT_ARRAYSZ]/sizeof(size_t);
size_t *fn = laddr(p, dyn[DT_INIT_ARRAY]);
--
2.4.1
next reply other threads:[~2015-11-29 15:33 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-11-29 15:33 Szabolcs Nagy [this message]
2015-11-29 16:59 ` Szabolcs Nagy
2015-11-29 23:43 ` Rich Felker
2016-05-17 21:52 ` Szabolcs Nagy
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20151129153322.GO23362@port70.net \
--to=nsz@port70.net \
--cc=musl@lists.openwall.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).