summaryrefslogtreecommitdiff
path: root/src/env/__init_tls.c
diff options
context:
space:
mode:
authorRich Felker <dalias@aerifal.cx>2012-10-07 21:43:46 -0400
committerRich Felker <dalias@aerifal.cx>2012-10-07 21:43:46 -0400
commit0a96a37f06fda78ce3674b425888b1fc090578aa (patch)
tree562b45acc1191a74bca5db876b44fd652678c94f /src/env/__init_tls.c
parent017bf140ffb41e9a016df84dc4c1806e0686b28a (diff)
downloadmusl-0a96a37f06fda78ce3674b425888b1fc090578aa.tar.gz
clean up and refactor program initialization
the code in __libc_start_main is now responsible for parsing auxv, rather than duplicating the parsing all over the place. this should shave off a few cycles and some code size. __init_libc is left as an external-linkage function despite the fact that it could be static, to prevent it from being inlined and permanently wasting stack space when main is called. a few other minor changes are included, like eliminating per-thread ssp canaries (they were likely broken when combined with certain dlopen usages, and completely unnecessary) and some other unnecessary checks. since this code gets linked into every program, it should be as small and simple as possible.
Diffstat (limited to 'src/env/__init_tls.c')
-rw-r--r--src/env/__init_tls.c11
1 files changed, 2 insertions, 9 deletions
diff --git a/src/env/__init_tls.c b/src/env/__init_tls.c
index 6b3cd28b..e70025d7 100644
--- a/src/env/__init_tls.c
+++ b/src/env/__init_tls.c
@@ -46,19 +46,14 @@ typedef Elf32_Phdr Phdr;
typedef Elf64_Phdr Phdr;
#endif
-#define AUX_CNT 6
-
-void __init_tls(size_t *auxv)
+void __init_tls(size_t *aux)
{
- size_t i, aux[AUX_CNT] = { 0 };
unsigned char *p, *mem;
size_t n, d;
Phdr *phdr, *tls_phdr=0;
size_t base = 0;
- for (; auxv[0]; auxv+=2) if (auxv[0]<AUX_CNT) aux[auxv[0]] = auxv[1];
- p = (void *)aux[AT_PHDR];
- for (p=(void *)aux[AT_PHDR]; aux[AT_PHNUM]--; p+=aux[AT_PHENT]) {
+ for (p=(void *)aux[AT_PHDR],n=aux[AT_PHNUM]; n; n--,p+=aux[AT_PHENT]) {
phdr = (void *)p;
if (phdr->p_type == PT_PHDR)
base = aux[AT_PHDR] - phdr->p_vaddr;
@@ -79,8 +74,6 @@ void __init_tls(size_t *auxv)
mem = __mmap(0, libc.tls_size, PROT_READ|PROT_WRITE,
MAP_ANONYMOUS|MAP_PRIVATE, -1, 0);
- if (mem == MAP_FAILED) a_crash();
-
if (!__install_initial_tls(__copy_tls(mem))) a_crash();
}
#else