|
Message-ID: <20151129153322.GO23362@port70.net> Date: Sun, 29 Nov 2015 16:33:22 +0100 From: Szabolcs Nagy <nsz@...t70.net> To: musl@...ts.openwall.com 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/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
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.