From: Szabolcs Nagy <nsz@port70.net>
To: musl@lists.openwall.com
Subject: Re: [PATCH 2/2] add preinit_array support
Date: Sun, 29 Nov 2015 17:59:25 +0100 [thread overview]
Message-ID: <20151129165925.GQ23362@port70.net> (raw)
In-Reply-To: <20151129153322.GO23362@port70.net>
[-- Attachment #1: Type: text/plain, Size: 414 bytes --]
* Szabolcs Nagy <nsz@port70.net> [2015-11-29 16:33:22 +0100]:
> 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(-)
>
src/internal change was missing and legacy _init vs
preinit_array order was wrong.
attached new version, array type is fixed too.
[-- Attachment #2: 0002-add-preinit_array-support.patch --]
[-- Type: text/x-diff, Size: 3087 bytes --]
From 8820faea5a365387c8fe54c8ffa1f796c2084f83 Mon Sep 17 00:00:00 2001
From: Szabolcs Nagy <nsz@port70.net>
Date: Sun, 29 Nov 2015 16:36:24 +0000
Subject: [PATCH 2/2] add preinit_array support
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/internal/dynlink.h | 2 +-
src/ldso/dynlink.c | 12 ++++++++++--
3 files changed, 16 insertions(+), 3 deletions(-)
diff --git a/src/env/__libc_start_main.c b/src/env/__libc_start_main.c
index 14a2825..7502bc3 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) {}
@@ -56,6 +59,8 @@ void __init_libc(char **envp, char *pn)
static void libc_start_init(void)
{
void (*const *f)(void);
+ for (f=&__preinit_array_start; f<&__preinit_array_end; f++)
+ (*f)();
_init();
for (f=&__init_array_start; f<&__init_array_end; f++)
(*f)();
diff --git a/src/internal/dynlink.h b/src/internal/dynlink.h
index 9c494e4..fb706d3 100644
--- a/src/internal/dynlink.h
+++ b/src/internal/dynlink.h
@@ -84,7 +84,7 @@ struct fdpic_dummy_loadmap {
#endif
#define AUX_CNT 32
-#define DYN_CNT 32
+#define DYN_CNT DT_NUM
typedef void (*stage2_func)(unsigned char *, size_t *);
typedef _Noreturn void (*stage3_func)(size_t *);
diff --git a/src/ldso/dynlink.c b/src/ldso/dynlink.c
index 93e7d67..51da820 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);
@@ -1225,6 +1228,11 @@ static void do_init_fini(struct dso *p)
p->fini_next = fini_head;
fini_head = p;
}
+ 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++)();
+ }
#ifndef NO_LEGACY_INITFINI
if ((dyn[0] & (1<<DT_INIT)) && dyn[DT_INIT])
fpaddr(p, dyn[DT_INIT])();
--
2.4.1
next prev parent reply other threads:[~2015-11-29 16:59 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-11-29 15:33 Szabolcs Nagy
2015-11-29 16:59 ` Szabolcs Nagy [this message]
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=20151129165925.GQ23362@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).