summaryrefslogtreecommitdiff
path: root/src/env
diff options
context:
space:
mode:
authorRich Felker <dalias@aerifal.cx>2015-11-19 20:28:08 -0500
committerRich Felker <dalias@aerifal.cx>2015-11-19 22:10:55 -0500
commit19caa25d0a8e587bb89b79c3f629085548709dd4 (patch)
tree479d4a303ea7a1a0d0efb511fa09d80730a7e513 /src/env
parent4f3a92881aa1fd9a3ebebe2c9940d70c95a7b0e6 (diff)
downloadmusl-19caa25d0a8e587bb89b79c3f629085548709dd4.tar.gz
musl-19caa25d0a8e587bb89b79c3f629085548709dd4.tar.bz2
musl-19caa25d0a8e587bb89b79c3f629085548709dd4.tar.xz
musl-19caa25d0a8e587bb89b79c3f629085548709dd4.zip
remove undef weak refs to init/fini array symbols in libc.so
commit ad1cd43a86645ba2d4f7c8747240452a349d6bc1 eliminated preprocessor-level omission of references to the init/fini array symbols from object files going into libc.so. the references are weak, and the intent was that the linker would resolve them to zero in libc.so, but instead it leaves undefined references that could be satisfied at runtime. normally these references would be harmless, since the code using them does not even get executed, but some older binutils versions produce a linking error: when linking a program against libc.so, ld first tries to use the hidden init/fini array symbols produced by the linker script to satisfy the references in libc.so, then produces an error because the definitions are hidden. ideally ld would have already provided definitions of these symbols when linking libc.so, but the linker script for -shared omits them. to avoid this situation, the dynamic linker now provides its own dummy definitions of the init/fini array symbols for libc.so. since they are hidden, everything binds at ld time and no references remain in the dynamic symbol table. with modern binutils and --gc-sections, both the dummy empty array objects and the code referencing them get dropped at link time, anyway. the _init and _fini symbols are also switched back to using weak definitions rather than weak references since the latter behave somewhat problematically in general, and the weak definition approach was known to work well.
Diffstat (limited to 'src/env')
-rw-r--r--src/env/__libc_start_main.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/src/env/__libc_start_main.c b/src/env/__libc_start_main.c
index 7ffada0b..5c79be28 100644
--- a/src/env/__libc_start_main.c
+++ b/src/env/__libc_start_main.c
@@ -8,9 +8,11 @@
void __init_tls(size_t *);
-extern void _init() __attribute__((weak));
-extern void (*const __init_array_start)() __attribute__((weak));
-extern void (*const __init_array_end)() __attribute__((weak));
+static void dummy(void) {}
+weak_alias(dummy, _init);
+
+__attribute__((__weak__, __visibility__("hidden")))
+extern void (*const __init_array_start)(void), (*const __init_array_end)(void);
static void dummy1(void *p) {}
weak_alias(dummy1, __init_ssp);
@@ -53,7 +55,7 @@ void __init_libc(char **envp, char *pn)
static void libc_start_init(void)
{
- if (_init) _init();
+ _init();
uintptr_t a = (uintptr_t)&__init_array_start;
for (; a<(uintptr_t)&__init_array_end; a+=sizeof(void(*)()))
(*(void (**)())a)();