7 #define START "_dlstart"
12 __attribute__((__visibility__("hidden")))
13 void _dlstart_c(size_t *sp, size_t *dynv)
15 size_t i, aux[AUX_CNT], dyn[DYN_CNT];
18 char **argv = (void *)(sp+1);
20 for (i=argc+1; argv[i]; i++);
21 size_t *auxv = (void *)(argv+i+1);
23 for (i=0; i<AUX_CNT; i++) aux[i] = 0;
24 for (i=0; auxv[i]; i+=2) if (auxv[i]<AUX_CNT)
25 aux[auxv[i]] = auxv[i+1];
27 for (i=0; i<DYN_CNT; i++) dyn[i] = 0;
28 for (i=0; dynv[i]; i+=2) if (dynv[i]<DYN_CNT)
29 dyn[dynv[i]] = dynv[i+1];
31 /* If the dynamic linker is invoked as a command, its load
32 * address is not available in the aux vector. Instead, compute
33 * the load address as the difference between &_DYNAMIC and the
34 * virtual address in the PT_DYNAMIC program header. */
35 unsigned char *base = (void *)aux[AT_BASE];
37 size_t phnum = aux[AT_PHNUM];
38 size_t phentsize = aux[AT_PHENT];
39 Phdr *ph = (void *)aux[AT_PHDR];
40 for (i=phnum; i--; ph = (void *)((char *)ph + phentsize)) {
41 if (ph->p_type == PT_DYNAMIC) {
42 base = (void *)((size_t)dynv - ph->p_vaddr);
48 /* MIPS uses an ugly packed form for GOT relocations. Since we
49 * can't make function calls yet and the code is tiny anyway,
50 * it's simply inlined here. */
51 if (NEED_MIPS_GOT_RELOCS) {
53 size_t *got = (void *)(base + dyn[DT_PLTGOT]);
54 for (i=0; dynv[i]; i+=2) if (dynv[i]==DT_MIPS_LOCAL_GOTNO)
55 local_cnt = dynv[i+1];
56 for (i=0; i<local_cnt; i++) got[i] += (size_t)base;
59 size_t *rel, rel_size;
61 rel = (void *)(base+dyn[DT_REL]);
62 rel_size = dyn[DT_RELSZ];
63 for (; rel_size; rel+=2, rel_size-=2*sizeof(size_t)) {
64 if (!IS_RELATIVE(rel[1])) continue;
65 size_t *rel_addr = (void *)(base + rel[0]);
66 *rel_addr += (size_t)base;
69 rel = (void *)(base+dyn[DT_RELA]);
70 rel_size = dyn[DT_RELASZ];
71 for (; rel_size; rel+=3, rel_size-=3*sizeof(size_t)) {
72 if (!IS_RELATIVE(rel[1])) continue;
73 size_t *rel_addr = (void *)(base + rel[0]);
74 *rel_addr = (size_t)base + rel[2];
78 const char *strings = (void *)(base + dyn[DT_STRTAB]);
79 const Sym *syms = (void *)(base + dyn[DT_SYMTAB]);
81 /* Call dynamic linker stage-2, __dls2 */
83 const char *s = strings + syms[i].st_name;
84 if (s[0]=='_' && s[1]=='_' && s[2]=='d'
85 && s[3]=='l' && s[4]=='s' && s[5]=='2' && !s[6])
88 ((stage2_func)(base + syms[i].st_value))(base, sp);
91 GETFUNCSYM(&dls2, __dls2, base+dyn[DT_PLTGOT]);