simplify dlstart code by using integer type for base address
authorRich Felker <dalias@aerifal.cx>
Mon, 21 Sep 2015 20:42:44 +0000 (20:42 +0000)
committerRich Felker <dalias@aerifal.cx>
Mon, 21 Sep 2015 20:42:44 +0000 (20:42 +0000)
src/ldso/dlstart.c

index a968baab9ca3134eb4fa792cc4e60216d2422f12..e84e073e252ca0a9bb7baa8ba2a0b3984ed25c6b 100644 (file)
@@ -21,6 +21,7 @@ __attribute__((__visibility__("hidden")))
 void _dlstart_c(size_t *sp, size_t *dynv)
 {
        size_t i, aux[AUX_CNT], dyn[DYN_CNT];
+       size_t *rel, rel_size, base;
 
        int argc = *sp;
        char **argv = (void *)(sp+1);
@@ -40,14 +41,14 @@ void _dlstart_c(size_t *sp, size_t *dynv)
         * address is not available in the aux vector. Instead, compute
         * the load address as the difference between &_DYNAMIC and the
         * virtual address in the PT_DYNAMIC program header. */
-       unsigned char *base = (void *)aux[AT_BASE];
+       base = aux[AT_BASE];
        if (!base) {
                size_t phnum = aux[AT_PHNUM];
                size_t phentsize = aux[AT_PHENT];
                Phdr *ph = (void *)aux[AT_PHDR];
                for (i=phnum; i--; ph = (void *)((char *)ph + phentsize)) {
                        if (ph->p_type == PT_DYNAMIC) {
-                               base = (void *)((size_t)dynv - ph->p_vaddr);
+                               base = (size_t)dynv - ph->p_vaddr;
                                break;
                        }
                }
@@ -61,17 +62,15 @@ void _dlstart_c(size_t *sp, size_t *dynv)
                size_t *got = (void *)(base + dyn[DT_PLTGOT]);
                for (i=0; dynv[i]; i+=2) if (dynv[i]==DT_MIPS_LOCAL_GOTNO)
                        local_cnt = dynv[i+1];
-               for (i=0; i<local_cnt; i++) got[i] += (size_t)base;
+               for (i=0; i<local_cnt; i++) got[i] += base;
        }
 
-       size_t *rel, rel_size;
-
        rel = (void *)(base+dyn[DT_REL]);
        rel_size = dyn[DT_RELSZ];
        for (; rel_size; rel+=2, rel_size-=2*sizeof(size_t)) {
                if (!IS_RELATIVE(rel[1])) continue;
                size_t *rel_addr = (void *)(base + rel[0]);
-               *rel_addr += (size_t)base;
+               *rel_addr += base;
        }
 
        rel = (void *)(base+dyn[DT_RELA]);
@@ -79,12 +78,12 @@ void _dlstart_c(size_t *sp, size_t *dynv)
        for (; rel_size; rel+=3, rel_size-=3*sizeof(size_t)) {
                if (!IS_RELATIVE(rel[1])) continue;
                size_t *rel_addr = (void *)(base + rel[0]);
-               *rel_addr = (size_t)base + rel[2];
+               *rel_addr = base + rel[2];
        }
 
        stage2_func dls2;
        GETFUNCSYM(&dls2, __dls2, base+dyn[DT_PLTGOT]);
-       dls2(base, sp);
+       dls2((void *)base, sp);
 }
 
 #endif