static void load_symbols(struct elfhdr *hdr, int fd)

{

    unsigned int i, nsyms;

    struct elf_shdr sechdr, symtab, strtab;

    char *strings;

    struct syminfo *s;

    struct elf_sym *syms;



    lseek(fd, hdr->e_shoff, SEEK_SET);

    for (i = 0; i < hdr->e_shnum; i++) {

        if (read(fd, &sechdr, sizeof(sechdr)) != sizeof(sechdr))

            return;

#ifdef BSWAP_NEEDED

        bswap_shdr(&sechdr);

#endif

        if (sechdr.sh_type == SHT_SYMTAB) {

            symtab = sechdr;

            lseek(fd, hdr->e_shoff

                  + sizeof(sechdr) * sechdr.sh_link, SEEK_SET);

            if (read(fd, &strtab, sizeof(strtab))

                != sizeof(strtab))

                return;

#ifdef BSWAP_NEEDED

            bswap_shdr(&strtab);

#endif

            goto found;

        }

    }

    return; /* Shouldn't happen... */



 found:

    /* Now know where the strtab and symtab are.  Snarf them. */

    s = malloc(sizeof(*s));

    syms = malloc(symtab.sh_size);

    if (!syms)

        return;

    s->disas_strtab = strings = malloc(strtab.sh_size);

    if (!s->disas_strtab)

        return;



    lseek(fd, symtab.sh_offset, SEEK_SET);

    if (read(fd, syms, symtab.sh_size) != symtab.sh_size)

        return;



    nsyms = symtab.sh_size / sizeof(struct elf_sym);



    i = 0;

    while (i < nsyms) {

#ifdef BSWAP_NEEDED

        bswap_sym(syms + i);

#endif

        // Throw away entries which we do not need.

        if (syms[i].st_shndx == SHN_UNDEF ||

            syms[i].st_shndx >= SHN_LORESERVE ||

            ELF_ST_TYPE(syms[i].st_info) != STT_FUNC) {

            nsyms--;

            if (i < nsyms) {

                syms[i] = syms[nsyms];

            }

            continue;

        }

#if defined(TARGET_ARM) || defined (TARGET_MIPS)

        /* The bottom address bit marks a Thumb or MIPS16 symbol.  */

        syms[i].st_value &= ~(target_ulong)1;

#endif

        i++;

    }

    syms = realloc(syms, nsyms * sizeof(*syms));



    qsort(syms, nsyms, sizeof(*syms), symcmp);



    lseek(fd, strtab.sh_offset, SEEK_SET);

    if (read(fd, strings, strtab.sh_size) != strtab.sh_size)

        return;

    s->disas_num_syms = nsyms;

#if ELF_CLASS == ELFCLASS32

    s->disas_symtab.elf32 = syms;

    s->lookup_symbol = lookup_symbolxx;

#else

    s->disas_symtab.elf64 = syms;

    s->lookup_symbol = lookup_symbolxx;

#endif

    s->next = syminfos;

    syminfos = s;

}

static void load_symbols(struct elfhdr *hdr, int fd)

{

    unsigned int i, nsyms;

    struct elf_shdr sechdr, symtab, strtab;

    char *strings;

    struct syminfo *s;

    struct elf_sym *syms;



    lseek(fd, hdr->e_shoff, SEEK_SET);

    for (i = 0; i < hdr->e_shnum; i++) {

        if (read(fd, &sechdr, sizeof(sechdr)) != sizeof(sechdr))

            return;

#ifdef BSWAP_NEEDED

        bswap_shdr(&sechdr);

#endif

        if (sechdr.sh_type == SHT_SYMTAB) {

            symtab = sechdr;

            lseek(fd, hdr->e_shoff

                  + sizeof(sechdr) * sechdr.sh_link, SEEK_SET);

            if (read(fd, &strtab, sizeof(strtab))

                != sizeof(strtab))

                return;

#ifdef BSWAP_NEEDED

            bswap_shdr(&strtab);

#endif

            goto found;

        }

    }

    return; 



 found:

    

    s = malloc(sizeof(*s));

    syms = malloc(symtab.sh_size);

    if (!syms)

        return;

    s->disas_strtab = strings = malloc(strtab.sh_size);

    if (!s->disas_strtab)

        return;



    lseek(fd, symtab.sh_offset, SEEK_SET);

    if (read(fd, syms, symtab.sh_size) != symtab.sh_size)

        return;



    nsyms = symtab.sh_size / sizeof(struct elf_sym);



    i = 0;

    while (i < nsyms) {

#ifdef BSWAP_NEEDED

        bswap_sym(syms + i);

#endif

        

        if (syms[i].st_shndx == SHN_UNDEF ||

            syms[i].st_shndx >= SHN_LORESERVE ||

            ELF_ST_TYPE(syms[i].st_info) != STT_FUNC) {

            nsyms--;

            if (i < nsyms) {

                syms[i] = syms[nsyms];

            }

            continue;

        }

#if defined(TARGET_ARM) || defined (TARGET_MIPS)

        

        syms[i].st_value &= ~(target_ulong)1;

#endif

        i++;

    }

    syms = realloc(syms, nsyms * sizeof(*syms));



    qsort(syms, nsyms, sizeof(*syms), symcmp);



    lseek(fd, strtab.sh_offset, SEEK_SET);

    if (read(fd, strings, strtab.sh_size) != strtab.sh_size)

        return;

    s->disas_num_syms = nsyms;

#if ELF_CLASS == ELFCLASS32

    s->disas_symtab.elf32 = syms;

    s->lookup_symbol = lookup_symbolxx;

#else

    s->disas_symtab.elf64 = syms;

    s->lookup_symbol = lookup_symbolxx;

#endif

    s->next = syminfos;

    syminfos = s;

}

static void FUNC_0(struct elfhdr *VAR_0, int VAR_1)

{

    unsigned int VAR_2, VAR_3;

    struct elf_shdr VAR_4, VAR_5, VAR_6;

    char *VAR_7;

    struct syminfo *VAR_8;

    struct elf_sym *VAR_9;



    lseek(VAR_1, VAR_0->e_shoff, SEEK_SET);

    for (VAR_2 = 0; VAR_2 < VAR_0->e_shnum; VAR_2++) {

        if (read(VAR_1, &VAR_4, sizeof(VAR_4)) != sizeof(VAR_4))

            return;

#ifdef BSWAP_NEEDED

        bswap_shdr(&VAR_4);

#endif

        if (VAR_4.sh_type == SHT_SYMTAB) {

            VAR_5 = VAR_4;

            lseek(VAR_1, VAR_0->e_shoff

                  + sizeof(VAR_4) * VAR_4.sh_link, SEEK_SET);

            if (read(VAR_1, &VAR_6, sizeof(VAR_6))

                != sizeof(VAR_6))

                return;

#ifdef BSWAP_NEEDED

            bswap_shdr(&VAR_6);

#endif

            goto found;

        }

    }

    return; 



 found:

    

    VAR_8 = malloc(sizeof(*VAR_8));

    VAR_9 = malloc(VAR_5.sh_size);

    if (!VAR_9)

        return;

    VAR_8->disas_strtab = VAR_7 = malloc(VAR_6.sh_size);

    if (!VAR_8->disas_strtab)

        return;



    lseek(VAR_1, VAR_5.sh_offset, SEEK_SET);

    if (read(VAR_1, VAR_9, VAR_5.sh_size) != VAR_5.sh_size)

        return;



    VAR_3 = VAR_5.sh_size / sizeof(struct elf_sym);



    VAR_2 = 0;

    while (VAR_2 < VAR_3) {

#ifdef BSWAP_NEEDED

        bswap_sym(VAR_9 + VAR_2);

#endif

        

        if (VAR_9[VAR_2].st_shndx == SHN_UNDEF ||

            VAR_9[VAR_2].st_shndx >= SHN_LORESERVE ||

            ELF_ST_TYPE(VAR_9[VAR_2].st_info) != STT_FUNC) {

            VAR_3--;

            if (VAR_2 < VAR_3) {

                VAR_9[VAR_2] = VAR_9[VAR_3];

            }

            continue;

        }

#if defined(TARGET_ARM) || defined (TARGET_MIPS)

        

        VAR_9[VAR_2].st_value &= ~(target_ulong)1;

#endif

        VAR_2++;

    }

    VAR_9 = realloc(VAR_9, VAR_3 * sizeof(*VAR_9));



    qsort(VAR_9, VAR_3, sizeof(*VAR_9), symcmp);



    lseek(VAR_1, VAR_6.sh_offset, SEEK_SET);

    if (read(VAR_1, VAR_7, VAR_6.sh_size) != VAR_6.sh_size)

        return;

    VAR_8->disas_num_syms = VAR_3;

#if ELF_CLASS == ELFCLASS32

    VAR_8->disas_symtab.elf32 = VAR_9;

    VAR_8->lookup_symbol = lookup_symbolxx;

#else

    VAR_8->disas_symtab.elf64 = VAR_9;

    VAR_8->lookup_symbol = lookup_symbolxx;

#endif

    VAR_8->next = syminfos;

    syminfos = VAR_8;

}

static void FUNC_0(struct elfhdr *VAR_0, int VAR_1)
{ unsigned int VAR_2, VAR_3; struct elf_shdr VAR_4, VAR_5, VAR_6; char *VAR_7; struct syminfo *VAR_8; struct elf_sym *VAR_9; lseek(VAR_1, VAR_0->e_shoff, SEEK_SET); for (VAR_2 = 0; VAR_2 < VAR_0->e_shnum; VAR_2++) { if (read(VAR_1, &VAR_4, sizeof(VAR_4)) != sizeof(VAR_4))
return; #ifdef BSWAP_NEEDED
bswap_shdr(&VAR_4); #endif
if (VAR_4.sh_type == SHT_SYMTAB) { VAR_5 = VAR_4; lseek(VAR_1, VAR_0->e_shoff
+ sizeof(VAR_4) * VAR_4.sh_link, SEEK_SET); if (read(VAR_1, &VAR_6, sizeof(VAR_6))
!= sizeof(VAR_6))
return; #ifdef BSWAP_NEEDED
bswap_shdr(&VAR_6); #endif
goto found; } } return; found:
VAR_8 = malloc(sizeof(*VAR_8)); VAR_9 = malloc(VAR_5.sh_size); if (!VAR_9)
return; VAR_8->disas_strtab = VAR_7 = malloc(VAR_6.sh_size); if (!VAR_8->disas_strtab)
return; lseek(VAR_1, VAR_5.sh_offset, SEEK_SET); if (read(VAR_1, VAR_9, VAR_5.sh_size) != VAR_5.sh_size)
return; VAR_3 = VAR_5.sh_size / sizeof(struct elf_sym); VAR_2 = 0; while (VAR_2 < VAR_3) { #ifdef BSWAP_NEEDED
bswap_sym(VAR_9 + VAR_2); #endif
if (VAR_9[VAR_2].st_shndx == SHN_UNDEF ||
VAR_9[VAR_2].st_shndx >= SHN_LORESERVE ||
ELF_ST_TYPE(VAR_9[VAR_2].st_info) != STT_FUNC) { VAR_3--; if (VAR_2 < VAR_3) { VAR_9[VAR_2] = VAR_9[VAR_3]; } continue; } #if defined(TARGET_ARM) || defined (TARGET_MIPS)
VAR_9[VAR_2].st_value &= ~(target_ulong)1; #endif
VAR_2++; } VAR_9 = realloc(VAR_9, VAR_3 * sizeof(*VAR_9)); qsort(VAR_9, VAR_3, sizeof(*VAR_9), symcmp); lseek(VAR_1, VAR_6.sh_offset, SEEK_SET); if (read(VAR_1, VAR_7, VAR_6.sh_size) != VAR_6.sh_size)
return; VAR_8->disas_num_syms = VAR_3; #if ELF_CLASS == ELFCLASS32
VAR_8->disas_symtab.elf32 = VAR_9; VAR_8->lookup_symbol = lookup_symbolxx; #else
VAR_8->disas_symtab.elf64 = VAR_9; VAR_8->lookup_symbol = lookup_symbolxx; #endif
VAR_8->next = syminfos; syminfos = VAR_8; }