/* readelf.c -- display contents of an ELF format file
Copyright 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
- 2008 Free Software Foundation, Inc.
+ 2008, 2009 Free Software Foundation, Inc.
Originally developed by Eric Youngdale <eric@andante.jic.com>
Modifications by Nick Clifton <nickc@redhat.com>
#include "getopt.h"
#include "libiberty.h"
#include "safe-ctype.h"
+#include "filenames.h"
-char *program_name = "readelf";
+char * program_name = "readelf";
int do_wide;
static long archive_file_offset;
static unsigned long archive_file_size;
static unsigned long dynamic_addr;
static bfd_size_type dynamic_size;
static unsigned int dynamic_nent;
-static char *dynamic_strings;
+static char * dynamic_strings;
static unsigned long dynamic_strings_length;
-static char *string_table;
+static char * string_table;
static unsigned long string_table_length;
static unsigned long num_dynamic_syms;
-static Elf_Internal_Sym *dynamic_symbols;
-static Elf_Internal_Syminfo *dynamic_syminfo;
+static Elf_Internal_Sym * dynamic_symbols;
+static Elf_Internal_Syminfo * dynamic_syminfo;
static unsigned long dynamic_syminfo_offset;
static unsigned int dynamic_syminfo_nent;
static char program_interpreter[PATH_MAX];
static bfd_vma dynamic_info_DT_GNU_HASH;
static bfd_vma version_info[16];
static Elf_Internal_Ehdr elf_header;
-static Elf_Internal_Shdr *section_headers;
-static Elf_Internal_Phdr *program_headers;
-static Elf_Internal_Dyn *dynamic_section;
-static Elf_Internal_Shdr *symtab_shndx_hdr;
+static Elf_Internal_Shdr * section_headers;
+static Elf_Internal_Phdr * program_headers;
+static Elf_Internal_Dyn * dynamic_section;
+static Elf_Internal_Shdr * symtab_shndx_hdr;
static int show_name;
static int do_dynamic;
static int do_syms;
struct group_list
{
- struct group_list *next;
+ struct group_list * next;
unsigned int section_index;
};
struct group
{
- struct group_list *root;
+ struct group_list * root;
unsigned int group_index;
};
static size_t group_count;
-static struct group *section_groups;
-static struct group **section_headers_groups;
+static struct group * section_groups;
+static struct group ** section_headers_groups;
/* Flag bits indicating particular types of dump. */
/* A linked list of the section names for which dumps were requested. */
struct dump_list_entry
{
- char *name;
+ char * name;
dump_type type;
- struct dump_list_entry *next;
+ struct dump_list_entry * next;
};
-static struct dump_list_entry *dump_sects_byname;
+static struct dump_list_entry * dump_sects_byname;
/* A dynamic array of flags indicating for which sections a dump
has been requested via command line switches. */
}
print_mode;
-static void (*byte_put) (unsigned char *, bfd_vma, int);
+static void (* byte_put) (unsigned char *, bfd_vma, int);
#define UNKNOWN -1
#define const_strneq(a,b) (strncmp ((a), (b), sizeof (b) - 1) == 0)
\f
static void *
-get_data (void *var, FILE *file, long offset, size_t size, size_t nmemb,
- const char *reason)
+get_data (void * var, FILE * file, long offset, size_t size, size_t nmemb,
+ const char * reason)
{
- void *mvar;
+ void * mvar;
if (size == 0 || nmemb == 0)
return NULL;
}
static void
-byte_put_little_endian (unsigned char *field, bfd_vma value, int size)
+byte_put_little_endian (unsigned char * field, bfd_vma value, int size)
{
switch (size)
{
Returns the number of emitted characters. */
static unsigned int
-print_symbol (int width, const char *symbol)
+print_symbol (int width, const char * symbol)
{
const char * c;
bfd_boolean extra_padding = FALSE;
}
static void
-byte_put_big_endian (unsigned char *field, bfd_vma value, int size)
+byte_put_big_endian (unsigned char * field, bfd_vma value, int size)
{
switch (size)
{
/* Return a pointer to section NAME, or NULL if no such section exists. */
static Elf_Internal_Shdr *
-find_section (const char *name)
+find_section (const char * name)
{
unsigned int i;
}
static int
-slurp_rela_relocs (FILE *file,
+slurp_rela_relocs (FILE * file,
unsigned long rel_offset,
unsigned long rel_size,
- Elf_Internal_Rela **relasp,
- unsigned long *nrelasp)
+ Elf_Internal_Rela ** relasp,
+ unsigned long * nrelasp)
{
- Elf_Internal_Rela *relas;
+ Elf_Internal_Rela * relas;
unsigned long nrelas;
unsigned int i;
if (is_32bit_elf)
{
- Elf32_External_Rela *erelas;
+ Elf32_External_Rela * erelas;
erelas = get_data (NULL, file, rel_offset, 1, rel_size, _("relocs"));
if (!erelas)
}
else
{
- Elf64_External_Rela *erelas;
+ Elf64_External_Rela * erelas;
erelas = get_data (NULL, file, rel_offset, 1, rel_size, _("relocs"));
if (!erelas)
}
static int
-slurp_rel_relocs (FILE *file,
+slurp_rel_relocs (FILE * file,
unsigned long rel_offset,
unsigned long rel_size,
- Elf_Internal_Rela **relsp,
- unsigned long *nrelsp)
+ Elf_Internal_Rela ** relsp,
+ unsigned long * nrelsp)
{
- Elf_Internal_Rela *rels;
+ Elf_Internal_Rela * rels;
unsigned long nrels;
unsigned int i;
if (is_32bit_elf)
{
- Elf32_External_Rel *erels;
+ Elf32_External_Rel * erels;
erels = get_data (NULL, file, rel_offset, 1, rel_size, _("relocs"));
if (!erels)
}
else
{
- Elf64_External_Rel *erels;
+ Elf64_External_Rel * erels;
erels = get_data (NULL, file, rel_offset, 1, rel_size, _("relocs"));
if (!erels)
offset. */
static void
-dump_relocations (FILE *file,
+dump_relocations (FILE * file,
unsigned long rel_offset,
unsigned long rel_size,
- Elf_Internal_Sym *symtab,
+ Elf_Internal_Sym * symtab,
unsigned long nsyms,
- char *strtab,
+ char * strtab,
unsigned long strtablen,
int is_rela)
{
unsigned int i;
- Elf_Internal_Rela *rels;
-
+ Elf_Internal_Rela * rels;
if (is_rela == UNKNOWN)
is_rela = guess_is_rela (elf_header.e_machine);
for (i = 0; i < rel_size; i++)
{
- const char *rtype;
+ const char * rtype;
bfd_vma offset;
bfd_vma info;
bfd_vma symtab_index;
printf (" bad symbol index: %08lx", (unsigned long) symtab_index);
else
{
- Elf_Internal_Sym *psym;
+ Elf_Internal_Sym * psym;
psym = symtab + symtab_index;
if (psym->st_name == 0)
{
- const char *sec_name = "<null>";
+ const char * sec_name = "<null>";
char name_buf[40];
if (ELF_ST_TYPE (psym->st_info) == STT_SECTION)
{
bfd_vma type2 = ELF64_MIPS_R_TYPE2 (info);
bfd_vma type3 = ELF64_MIPS_R_TYPE3 (info);
- const char *rtype2 = elf_mips_reloc_type (type2);
- const char *rtype3 = elf_mips_reloc_type (type3);
+ const char * rtype2 = elf_mips_reloc_type (type2);
+ const char * rtype3 = elf_mips_reloc_type (type3);
printf (" Type2: ");
default:
if ((type >= DT_LOPROC) && (type <= DT_HIPROC))
{
- const char *result;
+ const char * result;
switch (elf_header.e_machine)
{
|| (elf_header.e_machine == EM_PARISC
&& (type >= OLD_DT_LOOS) && (type <= OLD_DT_HIOS)))
{
- const char *result;
+ const char * result;
switch (elf_header.e_machine)
{
strcat (buf, ", fido_a");
else
{
- char const *isa = _("unknown");
- char const *mac = _("unknown mac");
- char const *additional = NULL;
+ char const * isa = _("unknown");
+ char const * mac = _("unknown mac");
+ char const * additional = NULL;
switch (e_flags & EF_M68K_CF_ISA_MASK)
{
default:
if ((p_type >= PT_LOPROC) && (p_type <= PT_HIPROC))
{
- const char *result;
+ const char * result;
switch (elf_header.e_machine)
{
}
else if ((p_type >= PT_LOOS) && (p_type <= PT_HIOS))
{
- const char *result;
+ const char * result;
switch (elf_header.e_machine)
{
default:
if ((sh_type >= SHT_LOPROC) && (sh_type <= SHT_HIPROC))
{
- const char *result;
+ const char * result;
switch (elf_header.e_machine)
{
}
else if ((sh_type >= SHT_LOOS) && (sh_type <= SHT_HIOS))
{
- const char *result;
+ const char * result;
switch (elf_header.e_machine)
{
};
static void
-usage (FILE *stream)
+usage (FILE * stream)
{
fprintf (stream, _("Usage: readelf <option(s)> elf-file(s)\n"));
fprintf (stream, _(" Display information about the contents of ELF format files\n"));
{
if (section >= num_dump_sects)
{
- dump_type *new_dump_sects;
+ dump_type * new_dump_sects;
new_dump_sects = calloc (section + 1, sizeof (* dump_sects));
/* Request a dump by section name. */
static void
-request_dump_byname (const char *section, dump_type type)
+request_dump_byname (const char * section, dump_type type)
{
- struct dump_list_entry *new_request;
+ struct dump_list_entry * new_request;
new_request = malloc (sizeof (struct dump_list_entry));
if (!new_request)
}
static void
-parse_args (int argc, char **argv)
+parse_args (int argc, char ** argv)
{
int c;
while ((c = getopt_long
(argc, argv, "ADHINSVWacdeghi:lnp:rstuvw::x:", options, NULL)) != EOF)
{
- char *cp;
+ char * cp;
int section;
switch (c)
static int
-get_32bit_program_headers (FILE *file, Elf_Internal_Phdr *program_headers)
+get_32bit_program_headers (FILE * file, Elf_Internal_Phdr * program_headers)
{
- Elf32_External_Phdr *phdrs;
- Elf32_External_Phdr *external;
- Elf_Internal_Phdr *internal;
+ Elf32_External_Phdr * phdrs;
+ Elf32_External_Phdr * external;
+ Elf_Internal_Phdr * internal;
unsigned int i;
phdrs = get_data (NULL, file, elf_header.e_phoff,
}
static int
-get_64bit_program_headers (FILE *file, Elf_Internal_Phdr *program_headers)
+get_64bit_program_headers (FILE * file, Elf_Internal_Phdr * program_headers)
{
- Elf64_External_Phdr *phdrs;
- Elf64_External_Phdr *external;
- Elf_Internal_Phdr *internal;
+ Elf64_External_Phdr * phdrs;
+ Elf64_External_Phdr * external;
+ Elf_Internal_Phdr * internal;
unsigned int i;
phdrs = get_data (NULL, file, elf_header.e_phoff,
/* Returns 1 if the program headers were read into `program_headers'. */
static int
-get_program_headers (FILE *file)
+get_program_headers (FILE * file)
{
- Elf_Internal_Phdr *phdrs;
+ Elf_Internal_Phdr * phdrs;
/* Check cache of prior read. */
if (program_headers != NULL)
/* Returns 1 if the program headers were loaded. */
static int
-process_program_headers (FILE *file)
+process_program_headers (FILE * file)
{
- Elf_Internal_Phdr *segment;
+ Elf_Internal_Phdr * segment;
unsigned int i;
if (elf_header.e_phnum == 0)
a section header table, we can easily locate it. */
if (section_headers != NULL)
{
- Elf_Internal_Shdr *sec;
+ Elf_Internal_Shdr * sec;
sec = find_section (".dynamic");
if (sec == NULL || sec->sh_size == 0)
for (i = 0; i < elf_header.e_phnum; i++)
{
unsigned int j;
- Elf_Internal_Shdr *section;
+ Elf_Internal_Shdr * section;
segment = program_headers + i;
section = section_headers + 1;
for (j = 1; j < elf_header.e_shnum; j++, section++)
{
- if (ELF_IS_SECTION_IN_SEGMENT_MEMORY(section, segment))
+ if (ELF_IS_SECTION_IN_SEGMENT_MEMORY (section, segment))
printf ("%s ", SECTION_NAME (section));
}
/* Find the file offset corresponding to VMA by using the program headers. */
static long
-offset_from_vma (FILE *file, bfd_vma vma, bfd_size_type size)
+offset_from_vma (FILE * file, bfd_vma vma, bfd_size_type size)
{
- Elf_Internal_Phdr *seg;
+ Elf_Internal_Phdr * seg;
if (! get_program_headers (file))
{
static int
-get_32bit_section_headers (FILE *file, unsigned int num)
+get_32bit_section_headers (FILE * file, unsigned int num)
{
- Elf32_External_Shdr *shdrs;
- Elf_Internal_Shdr *internal;
+ Elf32_External_Shdr * shdrs;
+ Elf_Internal_Shdr * internal;
unsigned int i;
shdrs = get_data (NULL, file, elf_header.e_shoff,
}
static int
-get_64bit_section_headers (FILE *file, unsigned int num)
+get_64bit_section_headers (FILE * file, unsigned int num)
{
- Elf64_External_Shdr *shdrs;
- Elf_Internal_Shdr *internal;
+ Elf64_External_Shdr * shdrs;
+ Elf_Internal_Shdr * internal;
unsigned int i;
shdrs = get_data (NULL, file, elf_header.e_shoff,
}
static Elf_Internal_Sym *
-get_32bit_elf_symbols (FILE *file, Elf_Internal_Shdr *section)
+get_32bit_elf_symbols (FILE * file, Elf_Internal_Shdr * section)
{
unsigned long number;
- Elf32_External_Sym *esyms;
- Elf_External_Sym_Shndx *shndx;
- Elf_Internal_Sym *isyms;
- Elf_Internal_Sym *psym;
+ Elf32_External_Sym * esyms;
+ Elf_External_Sym_Shndx * shndx;
+ Elf_Internal_Sym * isyms;
+ Elf_Internal_Sym * psym;
unsigned int j;
esyms = get_data (NULL, file, section->sh_offset, 1, section->sh_size,
}
static Elf_Internal_Sym *
-get_64bit_elf_symbols (FILE *file, Elf_Internal_Shdr *section)
+get_64bit_elf_symbols (FILE * file, Elf_Internal_Shdr * section)
{
unsigned long number;
- Elf64_External_Sym *esyms;
- Elf_External_Sym_Shndx *shndx;
- Elf_Internal_Sym *isyms;
- Elf_Internal_Sym *psym;
+ Elf64_External_Sym * esyms;
+ Elf_External_Sym_Shndx * shndx;
+ Elf_Internal_Sym * isyms;
+ Elf_Internal_Sym * psym;
unsigned int j;
esyms = get_data (NULL, file, section->sh_offset, 1, section->sh_size,
get_elf_section_flags (bfd_vma sh_flags)
{
static char buff[1024];
- char *p = buff;
+ char * p = buff;
int field_size = is_32bit_elf ? 8 : 16;
int index, size = sizeof (buff) - (field_size + 4 + 1);
bfd_vma os_flags = 0;
bfd_vma unknown_flags = 0;
static const struct
{
- const char *str;
+ const char * str;
int len;
}
flags [] =
}
static int
-process_section_headers (FILE *file)
+process_section_headers (FILE * file)
{
- Elf_Internal_Shdr *section;
+ Elf_Internal_Shdr * section;
unsigned int i;
section_headers = NULL;
i < elf_header.e_shnum;
i++, section++)
{
- char *name = SECTION_NAME (section);
+ char * name = SECTION_NAME (section);
if (section->sh_type == SHT_DYNSYM)
{
}
static int
-process_section_groups (FILE *file)
+process_section_groups (FILE * file)
{
- Elf_Internal_Shdr *section;
+ Elf_Internal_Shdr * section;
unsigned int i;
- struct group *group;
- Elf_Internal_Shdr *symtab_sec, *strtab_sec;
- Elf_Internal_Sym *symtab;
- char *strtab;
+ struct group * group;
+ Elf_Internal_Shdr * symtab_sec;
+ Elf_Internal_Shdr * strtab_sec;
+ Elf_Internal_Sym * symtab;
+ char * strtab;
size_t strtab_size;
/* Don't process section groups unless needed. */
{
if (section->sh_type == SHT_GROUP)
{
- char *name = SECTION_NAME (section);
- char *group_name;
- unsigned char *start, *indices;
+ char * name = SECTION_NAME (section);
+ char * group_name;
+ unsigned char * start;
+ unsigned char * indices;
unsigned int entry, j, size;
- Elf_Internal_Shdr *sec;
- Elf_Internal_Sym *sym;
+ Elf_Internal_Shdr * sec;
+ Elf_Internal_Sym * sym;
/* Get the symbol table. */
if (section->sh_link >= elf_header.e_shnum
for (j = 0; j < size; j++)
{
- struct group_list *g;
+ struct group_list * g;
entry = byte_get (indices, 4);
indices += 4;
static struct
{
- const char *name;
+ const char * name;
int reloc;
int size;
int rela;
/* Process the reloc section. */
static int
-process_relocs (FILE *file)
+process_relocs (FILE * file)
{
unsigned long rel_size;
unsigned long rel_offset;
if (do_using_dynamic)
{
int is_rela;
- const char *name;
+ const char * name;
int has_dynamic_reloc;
unsigned int i;
}
else
{
- Elf_Internal_Shdr *section;
+ Elf_Internal_Shdr * section;
unsigned long i;
int found = 0;
if (rel_size)
{
- Elf_Internal_Shdr *strsec;
+ Elf_Internal_Shdr * strsec;
int is_rela;
printf (_("\nRelocation section "));
if (section->sh_link != 0
&& section->sh_link < elf_header.e_shnum)
{
- Elf_Internal_Shdr *symsec;
- Elf_Internal_Sym *symtab;
+ Elf_Internal_Shdr * symsec;
+ Elf_Internal_Sym * symtab;
unsigned long nsyms;
unsigned long strtablen = 0;
- char *strtab = NULL;
+ char * strtab = NULL;
symsec = section_headers + section->sh_link;
if (symsec->sh_type != SHT_SYMTAB
}
*table; /* Unwind table. */
unsigned long table_len; /* Length of unwind table. */
- unsigned char *info; /* Unwind info. */
+ unsigned char * info; /* Unwind info. */
unsigned long info_size; /* Size of unwind info. */
bfd_vma info_addr; /* starting address of unwind info. */
bfd_vma seg_base; /* Starting address of segment. */
- Elf_Internal_Sym *symtab; /* The symbol table. */
+ Elf_Internal_Sym * symtab; /* The symbol table. */
unsigned long nsyms; /* Number of symbols. */
- char *strtab; /* The string table. */
+ char * strtab; /* The string table. */
unsigned long strtab_size; /* Size of string table. */
};
static void
-find_symbol_for_address (Elf_Internal_Sym *symtab,
+find_symbol_for_address (Elf_Internal_Sym * symtab,
unsigned long nsyms,
- const char *strtab,
+ const char * strtab,
unsigned long strtab_size,
struct absaddr addr,
- const char **symname,
- bfd_vma *offset)
+ const char ** symname,
+ bfd_vma * offset)
{
bfd_vma dist = 0x100000;
- Elf_Internal_Sym *sym, *best = NULL;
+ Elf_Internal_Sym * sym;
+ Elf_Internal_Sym * best = NULL;
unsigned long i;
for (i = 0, sym = symtab; i < nsyms; ++i, ++sym)
}
static void
-dump_ia64_unwind (struct ia64_unw_aux_info *aux)
+dump_ia64_unwind (struct ia64_unw_aux_info * aux)
{
- struct ia64_unw_table_entry *tp;
+ struct ia64_unw_table_entry * tp;
int in_body;
for (tp = aux->table; tp < aux->table + aux->table_len; ++tp)
{
bfd_vma stamp;
bfd_vma offset;
- const unsigned char *dp;
- const unsigned char *head;
- const char *procname;
+ const unsigned char * dp;
+ const unsigned char * head;
+ const char * procname;
find_symbol_for_address (aux->symtab, aux->nsyms, aux->strtab,
aux->strtab_size, tp->start, &procname, &offset);
}
static int
-slurp_ia64_unwind_table (FILE *file,
- struct ia64_unw_aux_info *aux,
- Elf_Internal_Shdr *sec)
+slurp_ia64_unwind_table (FILE * file,
+ struct ia64_unw_aux_info * aux,
+ Elf_Internal_Shdr * sec)
{
unsigned long size, nrelas, i;
- Elf_Internal_Phdr *seg;
- struct ia64_unw_table_entry *tep;
- Elf_Internal_Shdr *relsec;
- Elf_Internal_Rela *rela, *rp;
- unsigned char *table, *tp;
- Elf_Internal_Sym *sym;
- const char *relname;
+ Elf_Internal_Phdr * seg;
+ struct ia64_unw_table_entry * tep;
+ Elf_Internal_Shdr * relsec;
+ Elf_Internal_Rela * rela;
+ Elf_Internal_Rela * rp;
+ unsigned char * table;
+ unsigned char * tp;
+ Elf_Internal_Sym * sym;
+ const char * relname;
/* First, find the starting address of the segment that includes
this section: */
}
static int
-ia64_process_unwind (FILE *file)
+ia64_process_unwind (FILE * file)
{
- Elf_Internal_Shdr *sec, *unwsec = NULL, *strsec;
+ Elf_Internal_Shdr * sec;
+ Elf_Internal_Shdr * unwsec = NULL;
+ Elf_Internal_Shdr * strsec;
unsigned long i, unwcount = 0, unwstart = 0;
struct ia64_unw_aux_info aux;
while (unwcount-- > 0)
{
- char *suffix;
+ char * suffix;
size_t len, len2;
for (i = unwstart, sec = section_headers + unwstart;
if ((unwsec->sh_flags & SHF_GROUP) != 0)
{
/* We need to find which section group it is in. */
- struct group_list *g = section_headers_groups [i]->root;
+ struct group_list * g = section_headers_groups [i]->root;
for (; g != NULL; g = g->next)
{
*table; /* Unwind table. */
unsigned long table_len; /* Length of unwind table. */
bfd_vma seg_base; /* Starting address of segment. */
- Elf_Internal_Sym *symtab; /* The symbol table. */
+ Elf_Internal_Sym * symtab; /* The symbol table. */
unsigned long nsyms; /* Number of symbols. */
- char *strtab; /* The string table. */
+ char * strtab; /* The string table. */
unsigned long strtab_size; /* Size of string table. */
};
static void
-dump_hppa_unwind (struct hppa_unw_aux_info *aux)
+dump_hppa_unwind (struct hppa_unw_aux_info * aux)
{
- struct hppa_unw_table_entry *tp;
+ struct hppa_unw_table_entry * tp;
for (tp = aux->table; tp < aux->table + aux->table_len; ++tp)
{
bfd_vma offset;
- const char *procname;
+ const char * procname;
find_symbol_for_address (aux->symtab, aux->nsyms, aux->strtab,
aux->strtab_size, tp->start, &procname,
}
static int
-slurp_hppa_unwind_table (FILE *file,
- struct hppa_unw_aux_info *aux,
- Elf_Internal_Shdr *sec)
+slurp_hppa_unwind_table (FILE * file,
+ struct hppa_unw_aux_info * aux,
+ Elf_Internal_Shdr * sec)
{
unsigned long size, unw_ent_size, nentries, nrelas, i;
- Elf_Internal_Phdr *seg;
- struct hppa_unw_table_entry *tep;
- Elf_Internal_Shdr *relsec;
- Elf_Internal_Rela *rela, *rp;
- unsigned char *table, *tp;
- Elf_Internal_Sym *sym;
- const char *relname;
+ Elf_Internal_Phdr * seg;
+ struct hppa_unw_table_entry * tep;
+ Elf_Internal_Shdr * relsec;
+ Elf_Internal_Rela * rela;
+ Elf_Internal_Rela * rp;
+ unsigned char * table;
+ unsigned char * tp;
+ Elf_Internal_Sym * sym;
+ const char * relname;
/* First, find the starting address of the segment that includes
this section. */
}
static int
-hppa_process_unwind (FILE *file)
+hppa_process_unwind (FILE * file)
{
struct hppa_unw_aux_info aux;
- Elf_Internal_Shdr *unwsec = NULL;
- Elf_Internal_Shdr *strsec;
- Elf_Internal_Shdr *sec;
+ Elf_Internal_Shdr * unwsec = NULL;
+ Elf_Internal_Shdr * strsec;
+ Elf_Internal_Shdr * sec;
unsigned long i;
memset (& aux, 0, sizeof (aux));
}
static int
-process_unwind (FILE *file)
+process_unwind (FILE * file)
{
- struct unwind_handler {
+ struct unwind_handler
+ {
int machtype;
- int (*handler)(FILE *file);
- } handlers[] = {
+ int (* handler)(FILE *);
+ } handlers[] =
+ {
{ EM_IA_64, ia64_process_unwind },
{ EM_PARISC, hppa_process_unwind },
{ 0, 0 }
}
static void
-dynamic_section_mips_val (Elf_Internal_Dyn *entry)
+dynamic_section_mips_val (Elf_Internal_Dyn * entry)
{
switch (entry->d_tag)
{
case DT_MIPS_TIME_STAMP:
{
char timebuf[20];
- struct tm *tmp;
+ struct tm * tmp;
time_t time = entry->d_un.d_val;
tmp = gmtime (&time);
static void
-dynamic_section_parisc_val (Elf_Internal_Dyn *entry)
+dynamic_section_parisc_val (Elf_Internal_Dyn * entry)
{
switch (entry->d_tag)
{
static struct
{
long int bit;
- const char *str;
+ const char * str;
}
flags[] =
{
}
static void
-dynamic_section_ia64_val (Elf_Internal_Dyn *entry)
+dynamic_section_ia64_val (Elf_Internal_Dyn * entry)
{
switch (entry->d_tag)
{
}
static int
-get_32bit_dynamic_section (FILE *file)
+get_32bit_dynamic_section (FILE * file)
{
- Elf32_External_Dyn *edyn, *ext;
- Elf_Internal_Dyn *entry;
+ Elf32_External_Dyn * edyn;
+ Elf32_External_Dyn * ext;
+ Elf_Internal_Dyn * entry;
edyn = get_data (NULL, file, dynamic_addr, 1, dynamic_size,
_("dynamic section"));
break;
}
- dynamic_section = cmalloc (dynamic_nent, sizeof (*entry));
+ dynamic_section = cmalloc (dynamic_nent, sizeof (* entry));
if (dynamic_section == NULL)
{
error (_("Out of memory\n"));
}
static int
-get_64bit_dynamic_section (FILE *file)
+get_64bit_dynamic_section (FILE * file)
{
- Elf64_External_Dyn *edyn, *ext;
- Elf_Internal_Dyn *entry;
+ Elf64_External_Dyn * edyn;
+ Elf64_External_Dyn * ext;
+ Elf_Internal_Dyn * entry;
edyn = get_data (NULL, file, dynamic_addr, 1, dynamic_size,
_("dynamic section"));
break;
}
- dynamic_section = cmalloc (dynamic_nent, sizeof (*entry));
+ dynamic_section = cmalloc (dynamic_nent, sizeof (* entry));
if (dynamic_section == NULL)
{
error (_("Out of memory\n"));
/* Parse and display the contents of the dynamic section. */
static int
-process_dynamic_section (FILE *file)
+process_dynamic_section (FILE * file)
{
- Elf_Internal_Dyn *entry;
+ Elf_Internal_Dyn * entry;
if (dynamic_size == 0)
{
if (dynamic_syminfo_offset != 0 && syminsz != 0)
{
- Elf_External_Syminfo *extsyminfo, *extsym;
- Elf_Internal_Syminfo *syminfo;
+ Elf_External_Syminfo * extsyminfo;
+ Elf_External_Syminfo * extsym;
+ Elf_Internal_Syminfo * syminfo;
/* There is a syminfo section. Read the data. */
extsyminfo = get_data (NULL, file, dynamic_syminfo_offset, 1,
{
if (do_dynamic)
{
- const char *dtype;
+ const char * dtype;
putchar (' ');
print_vma (entry->d_tag, FULL_HEX);
if (do_dynamic)
{
- char *name;
+ char * name;
if (VALID_DYNAMIC_NAME (entry->d_un.d_val))
name = GET_DYNAMIC_NAME (entry->d_un.d_val);
if (entry->d_tag == DT_USED
&& VALID_DYNAMIC_NAME (entry->d_un.d_val))
{
- char *name = GET_DYNAMIC_NAME (entry->d_un.d_val);
+ char * name = GET_DYNAMIC_NAME (entry->d_un.d_val);
if (*name)
{
case DT_GNU_PRELINKED:
if (do_dynamic)
{
- struct tm *tmp;
+ struct tm * tmp;
time_t time = entry->d_un.d_val;
tmp = gmtime (&time);
/* Display the contents of the version sections. */
static int
-process_version_sections (FILE *file)
+process_version_sections (FILE * file)
{
- Elf_Internal_Shdr *section;
+ Elf_Internal_Shdr * section;
unsigned i;
int found = 0;
{
case SHT_GNU_verdef:
{
- Elf_External_Verdef *edefs;
+ Elf_External_Verdef * edefs;
unsigned int idx;
unsigned int cnt;
- char *endbuf;
+ char * endbuf;
found = 1;
for (idx = cnt = 0; cnt < section->sh_info; ++cnt)
{
- char *vstart;
- Elf_External_Verdef *edef;
+ char * vstart;
+ Elf_External_Verdef * edef;
Elf_Internal_Verdef ent;
- Elf_External_Verdaux *eaux;
+ Elf_External_Verdaux * eaux;
Elf_Internal_Verdaux aux;
int j;
int isum;
case SHT_GNU_verneed:
{
- Elf_External_Verneed *eneed;
+ Elf_External_Verneed * eneed;
unsigned int idx;
unsigned int cnt;
- char *endbuf;
+ char * endbuf;
found = 1;
for (idx = cnt = 0; cnt < section->sh_info; ++cnt)
{
- Elf_External_Verneed *entry;
+ Elf_External_Verneed * entry;
Elf_Internal_Verneed ent;
int j;
int isum;
- char *vstart;
+ char * vstart;
vstart = ((char *) eneed) + idx;
if (vstart + sizeof (*entry) > endbuf)
for (j = 0, isum = idx + ent.vn_aux; j < ent.vn_cnt; ++j)
{
- Elf_External_Vernaux *eaux;
+ Elf_External_Vernaux * eaux;
Elf_Internal_Vernaux aux;
if (vstart + sizeof (*eaux) > endbuf)
case SHT_GNU_versym:
{
- Elf_Internal_Shdr *link_section;
+ Elf_Internal_Shdr * link_section;
int total;
int cnt;
- unsigned char *edata;
- unsigned short *data;
- char *strtab;
- Elf_Internal_Sym *symbols;
- Elf_Internal_Shdr *string_sec;
+ unsigned char * edata;
+ unsigned short * data;
+ char * strtab;
+ Elf_Internal_Sym * symbols;
+ Elf_Internal_Shdr * string_sec;
long off;
if (section->sh_link >= elf_header.e_shnum)
{
int j, nn;
int check_def, check_need;
- char *name;
+ char * name;
printf (" %03x:", cnt);
}
static bfd_vma *
-get_dynamic_data (FILE *file, unsigned int number, unsigned int ent_size)
+get_dynamic_data (FILE * file, unsigned int number, unsigned int ent_size)
{
- unsigned char *e_data;
- bfd_vma *i_data;
+ unsigned char * e_data;
+ bfd_vma * i_data;
e_data = cmalloc (number, ent_size);
static void
print_dynamic_symbol (bfd_vma si, unsigned long hn)
{
- Elf_Internal_Sym *psym;
+ Elf_Internal_Sym * psym;
int n;
psym = dynamic_symbols + si;
/* Dump the symbol table. */
static int
-process_symbol_table (FILE *file)
+process_symbol_table (FILE * file)
{
- Elf_Internal_Shdr *section;
+ Elf_Internal_Shdr * section;
bfd_vma nbuckets = 0;
bfd_vma nchains = 0;
- bfd_vma *buckets = NULL;
- bfd_vma *chains = NULL;
+ bfd_vma * buckets = NULL;
+ bfd_vma * chains = NULL;
bfd_vma ngnubuckets = 0;
- bfd_vma *gnubuckets = NULL;
- bfd_vma *gnuchains = NULL;
+ bfd_vma * gnubuckets = NULL;
+ bfd_vma * gnuchains = NULL;
bfd_vma gnusymidx = 0;
if (! do_syms && !do_histogram)
i++, section++)
{
unsigned int si;
- char *strtab = NULL;
+ char * strtab = NULL;
unsigned long int strtab_size = 0;
- Elf_Internal_Sym *symtab;
- Elf_Internal_Sym *psym;
-
+ Elf_Internal_Sym * symtab;
+ Elf_Internal_Sym * psym;
if ( section->sh_type != SHT_SYMTAB
&& section->sh_type != SHT_DYNSYM)
}
else if (section->sh_link < elf_header.e_shnum)
{
- Elf_Internal_Shdr *string_sec;
+ Elf_Internal_Shdr * string_sec;
string_sec = section_headers + section->sh_link;
if (do_histogram && buckets != NULL)
{
- unsigned long *lengths;
- unsigned long *counts;
+ unsigned long * lengths;
+ unsigned long * counts;
unsigned long hn;
bfd_vma si;
unsigned long maxlength = 0;
if (do_histogram && dynamic_info_DT_GNU_HASH)
{
- unsigned long *lengths;
- unsigned long *counts;
+ unsigned long * lengths;
+ unsigned long * counts;
unsigned long hn;
unsigned long maxlength = 0;
unsigned long nzero_counts = 0;
}
static int
-process_syminfo (FILE *file ATTRIBUTE_UNUSED)
+process_syminfo (FILE * file ATTRIBUTE_UNUSED)
{
unsigned int i;
#ifdef SUPPORT_DISASSEMBLY
static int
-disassemble_section (Elf_Internal_Shdr *section, FILE *file)
+disassemble_section (Elf_Internal_Shdr * section, FILE * file)
{
printf (_("\nAssembly dump of section %s\n"),
SECTION_NAME (section));
#endif
static int
-dump_section_as_strings (Elf_Internal_Shdr *section, FILE *file)
+dump_section_as_strings (Elf_Internal_Shdr * section, FILE * file)
{
- Elf_Internal_Shdr *relsec;
+ Elf_Internal_Shdr * relsec;
bfd_size_type num_bytes;
bfd_vma addr;
- char *data;
- char *end;
- char *start;
- char *name = SECTION_NAME (section);
+ char * data;
+ char * end;
+ char * start;
+ char * name = SECTION_NAME (section);
bfd_boolean some_strings_shown;
num_bytes = section->sh_size;
static int
-dump_section_as_bytes (Elf_Internal_Shdr *section, FILE *file)
+dump_section_as_bytes (Elf_Internal_Shdr * section, FILE * file)
{
- Elf_Internal_Shdr *relsec;
+ Elf_Internal_Shdr * relsec;
bfd_size_type bytes;
bfd_vma addr;
- unsigned char *data;
- unsigned char *start;
+ unsigned char * data;
+ unsigned char * start;
bytes = section->sh_size;
This is a copy of bfd_uncompress_section_contents, in bfd/compress.c */
static int
-uncompress_section_contents (unsigned char **buffer, dwarf_size_type *size)
+uncompress_section_contents (unsigned char ** buffer, dwarf_size_type * size)
{
#ifndef HAVE_ZLIB_H
/* These are just to quiet gcc. */
/* Apply relocations to a debug section. */
static void
-debug_apply_relocations (void *file,
- Elf_Internal_Shdr *section,
- unsigned char *start)
+debug_apply_relocations (void * file,
+ Elf_Internal_Shdr * section,
+ unsigned char * start)
{
- Elf_Internal_Shdr *relsec;
- unsigned char *end = start + section->sh_size;
+ Elf_Internal_Shdr * relsec;
+ unsigned char * end = start + section->sh_size;
if (elf_header.e_type != ET_REL)
return;
{
bfd_boolean is_rela;
unsigned long num_relocs;
- Elf_Internal_Rela *relocs, *rp;
- Elf_Internal_Shdr *symsec;
- Elf_Internal_Sym *symtab;
- Elf_Internal_Sym *sym;
+ Elf_Internal_Rela * relocs;
+ Elf_Internal_Rela * rp;
+ Elf_Internal_Shdr * symsec;
+ Elf_Internal_Sym * symtab;
+ Elf_Internal_Sym * sym;
if ((relsec->sh_type != SHT_RELA && relsec->sh_type != SHT_REL)
|| relsec->sh_info >= elf_header.e_shnum
static int
load_specific_debug_section (enum dwarf_section_display_enum debug,
- Elf_Internal_Shdr *sec, void *file)
+ Elf_Internal_Shdr * sec, void * file)
{
- struct dwarf_section *section = &debug_displays [debug].section;
+ struct dwarf_section * section = &debug_displays [debug].section;
char buf [64];
int section_is_compressed;
}
int
-load_debug_section (enum dwarf_section_display_enum debug, void *file)
+load_debug_section (enum dwarf_section_display_enum debug, void * file)
{
- struct dwarf_section *section = &debug_displays [debug].section;
- Elf_Internal_Shdr *sec;
+ struct dwarf_section * section = &debug_displays [debug].section;
+ Elf_Internal_Shdr * sec;
/* Locate the debug section. */
sec = find_section (section->uncompressed_name);
void
free_debug_section (enum dwarf_section_display_enum debug)
{
- struct dwarf_section *section = &debug_displays [debug].section;
+ struct dwarf_section * section = &debug_displays [debug].section;
if (section->start == NULL)
return;
}
static int
-display_debug_section (Elf_Internal_Shdr *section, FILE *file)
+display_debug_section (Elf_Internal_Shdr * section, FILE * file)
{
- char *name = SECTION_NAME (section);
+ char * name = SECTION_NAME (section);
bfd_size_type length;
int result = 1;
enum dwarf_section_display_enum i;
if (streq (debug_displays[i].section.uncompressed_name, name)
|| streq (debug_displays[i].section.compressed_name, name))
{
- struct dwarf_section *sec = &debug_displays [i].section;
+ struct dwarf_section * sec = &debug_displays [i].section;
int secondary = (section != find_section (name));
if (secondary)
static void
initialise_dumps_byname (void)
{
- struct dump_list_entry *cur;
+ struct dump_list_entry * cur;
for (cur = dump_sects_byname; cur; cur = cur->next)
{
}
static void
-process_section_contents (FILE *file)
+process_section_contents (FILE * file)
{
- Elf_Internal_Shdr *section;
+ Elf_Internal_Shdr * section;
unsigned int i;
if (! do_dump)
typedef struct
{
int tag;
- const char *name;
+ const char * name;
/* 0 = special, 1 = string, 2 = uleb123, > 0x80 == table lookup. */
int type;
- const char **table;
+ const char ** table;
} arm_attr_public_tag;
-static const char *arm_attr_tag_CPU_arch[] =
+static const char * arm_attr_tag_CPU_arch[] =
{"Pre-v4", "v4", "v4T", "v5T", "v5TE", "v5TEJ", "v6", "v6KZ", "v6T2",
"v6K", "v7", "v6-M", "v6S-M"};
-static const char *arm_attr_tag_ARM_ISA_use[] = {"No", "Yes"};
-static const char *arm_attr_tag_THUMB_ISA_use[] =
+static const char * arm_attr_tag_ARM_ISA_use[] = {"No", "Yes"};
+static const char * arm_attr_tag_THUMB_ISA_use[] =
{"No", "Thumb-1", "Thumb-2"};
-static const char *arm_attr_tag_VFP_arch[] =
+static const char * arm_attr_tag_VFP_arch[] =
{"No", "VFPv1", "VFPv2", "VFPv3", "VFPv3-D16"};
-static const char *arm_attr_tag_WMMX_arch[] = {"No", "WMMXv1", "WMMXv2"};
-static const char *arm_attr_tag_Advanced_SIMD_arch[] = {"No", "NEONv1"};
-static const char *arm_attr_tag_PCS_config[] =
+static const char * arm_attr_tag_WMMX_arch[] = {"No", "WMMXv1", "WMMXv2"};
+static const char * arm_attr_tag_Advanced_SIMD_arch[] = {"No", "NEONv1"};
+static const char * arm_attr_tag_PCS_config[] =
{"None", "Bare platform", "Linux application", "Linux DSO", "PalmOS 2004",
"PalmOS (reserved)", "SymbianOS 2004", "SymbianOS (reserved)"};
-static const char *arm_attr_tag_ABI_PCS_R9_use[] =
+static const char * arm_attr_tag_ABI_PCS_R9_use[] =
{"V6", "SB", "TLS", "Unused"};
-static const char *arm_attr_tag_ABI_PCS_RW_data[] =
+static const char * arm_attr_tag_ABI_PCS_RW_data[] =
{"Absolute", "PC-relative", "SB-relative", "None"};
-static const char *arm_attr_tag_ABI_PCS_RO_data[] =
+static const char * arm_attr_tag_ABI_PCS_RO_data[] =
{"Absolute", "PC-relative", "None"};
-static const char *arm_attr_tag_ABI_PCS_GOT_use[] =
+static const char * arm_attr_tag_ABI_PCS_GOT_use[] =
{"None", "direct", "GOT-indirect"};
-static const char *arm_attr_tag_ABI_PCS_wchar_t[] =
+static const char * arm_attr_tag_ABI_PCS_wchar_t[] =
{"None", "??? 1", "2", "??? 3", "4"};
-static const char *arm_attr_tag_ABI_FP_rounding[] = {"Unused", "Needed"};
-static const char *arm_attr_tag_ABI_FP_denormal[] =
+static const char * arm_attr_tag_ABI_FP_rounding[] = {"Unused", "Needed"};
+static const char * arm_attr_tag_ABI_FP_denormal[] =
{"Unused", "Needed", "Sign only"};
-static const char *arm_attr_tag_ABI_FP_exceptions[] = {"Unused", "Needed"};
-static const char *arm_attr_tag_ABI_FP_user_exceptions[] = {"Unused", "Needed"};
-static const char *arm_attr_tag_ABI_FP_number_model[] =
+static const char * arm_attr_tag_ABI_FP_exceptions[] = {"Unused", "Needed"};
+static const char * arm_attr_tag_ABI_FP_user_exceptions[] = {"Unused", "Needed"};
+static const char * arm_attr_tag_ABI_FP_number_model[] =
{"Unused", "Finite", "RTABI", "IEEE 754"};
-static const char *arm_attr_tag_ABI_align8_needed[] = {"No", "Yes", "4-byte"};
-static const char *arm_attr_tag_ABI_align8_preserved[] =
+static const char * arm_attr_tag_ABI_align8_needed[] = {"No", "Yes", "4-byte"};
+static const char * arm_attr_tag_ABI_align8_preserved[] =
{"No", "Yes, except leaf SP", "Yes"};
-static const char *arm_attr_tag_ABI_enum_size[] =
+static const char * arm_attr_tag_ABI_enum_size[] =
{"Unused", "small", "int", "forced to int"};
-static const char *arm_attr_tag_ABI_HardFP_use[] =
+static const char * arm_attr_tag_ABI_HardFP_use[] =
{"As Tag_VFP_arch", "SP only", "DP only", "SP and DP"};
-static const char *arm_attr_tag_ABI_VFP_args[] =
+static const char * arm_attr_tag_ABI_VFP_args[] =
{"AAPCS", "VFP registers", "custom"};
-static const char *arm_attr_tag_ABI_WMMX_args[] =
+static const char * arm_attr_tag_ABI_WMMX_args[] =
{"AAPCS", "WMMX registers", "custom"};
-static const char *arm_attr_tag_ABI_optimization_goals[] =
+static const char * arm_attr_tag_ABI_optimization_goals[] =
{"None", "Prefer Speed", "Aggressive Speed", "Prefer Size",
"Aggressive Size", "Prefer Debug", "Aggressive Debug"};
-static const char *arm_attr_tag_ABI_FP_optimization_goals[] =
+static const char * arm_attr_tag_ABI_FP_optimization_goals[] =
{"None", "Prefer Speed", "Aggressive Speed", "Prefer Size",
"Aggressive Size", "Prefer Accuracy", "Aggressive Accuracy"};
-static const char *arm_attr_tag_CPU_unaligned_access[] = {"None", "v6"};
-static const char *arm_attr_tag_VFP_HP_extension[] =
+static const char * arm_attr_tag_CPU_unaligned_access[] = {"None", "v6"};
+static const char * arm_attr_tag_VFP_HP_extension[] =
{"Not Allowed", "Allowed"};
-static const char *arm_attr_tag_ABI_FP_16bit_format[] =
+static const char * arm_attr_tag_ABI_FP_16bit_format[] =
{"None", "IEEE 754", "Alternative Format"};
-static const char *arm_attr_tag_T2EE_use[] = {"Not Allowed", "Allowed"};
-static const char *arm_attr_tag_Virtualization_use[] =
+static const char * arm_attr_tag_T2EE_use[] = {"Not Allowed", "Allowed"};
+static const char * arm_attr_tag_Virtualization_use[] =
{"Not Allowed", "Allowed"};
-static const char *arm_attr_tag_MPextension_use[] = {"Not Allowed", "Allowed"};
+static const char * arm_attr_tag_MPextension_use[] = {"Not Allowed", "Allowed"};
#define LOOKUP(id, name) \
{id, #name, 0x80 | ARRAY_SIZE(arm_attr_tag_##name), arm_attr_tag_##name}
/* Read an unsigned LEB128 encoded value from p. Set *PLEN to the number of
bytes read. */
+
static unsigned int
-read_uleb128 (unsigned char *p, unsigned int *plen)
+read_uleb128 (unsigned char * p, unsigned int * plen)
{
unsigned char c;
unsigned int val;
}
static unsigned char *
-display_arm_attribute (unsigned char *p)
+display_arm_attribute (unsigned char * p)
{
int tag;
unsigned int len;
int val;
- arm_attr_public_tag *attr;
+ arm_attr_public_tag * attr;
unsigned i;
int type;
tag = read_uleb128 (p, &len);
p += len;
attr = NULL;
- for (i = 0; i < ARRAY_SIZE(arm_attr_public_tags); i++)
+ for (i = 0; i < ARRAY_SIZE (arm_attr_public_tags); i++)
{
if (arm_attr_public_tags[i].tag == tag)
{
val = read_uleb128 (p, &len);
p += len;
printf ("flag = %d, vendor = %s\n", val, p);
- p += strlen((char *)p) + 1;
+ p += strlen ((char *) p) + 1;
break;
case 64: /* Tag_nodefaults. */
{
val = read_uleb128 (p, &len);
p += len;
- if ((unsigned int)val >= ARRAY_SIZE(arm_attr_tag_CPU_arch))
+ if ((unsigned int)val >= ARRAY_SIZE (arm_attr_tag_CPU_arch))
printf ("??? (%d)\n", val);
else
printf ("%s\n", arm_attr_tag_CPU_arch[val]);
break;
default:
- abort();
+ abort ();
}
return p;
if (type == 1)
{
printf ("\"%s\"\n", p);
- p += strlen((char *)p) + 1;
+ p += strlen ((char *) p) + 1;
}
else
{
}
static unsigned char *
-display_power_gnu_attribute (unsigned char *p, int tag)
+display_power_gnu_attribute (unsigned char * p, int tag)
{
int type;
unsigned int len;
}
static unsigned char *
-display_mips_gnu_attribute (unsigned char *p, int tag)
+display_mips_gnu_attribute (unsigned char * p, int tag)
{
int type;
unsigned int len;
unsigned char * (* display_pub_attribute) (unsigned char *),
unsigned char * (* display_proc_gnu_attribute) (unsigned char *, int))
{
- Elf_Internal_Shdr *sect;
- unsigned char *contents;
- unsigned char *p;
- unsigned char *end;
+ Elf_Internal_Shdr * sect;
+ unsigned char * contents;
+ unsigned char * p;
+ unsigned char * end;
bfd_vma section_len;
bfd_vma len;
unsigned i;
}
static int
-process_arm_specific (FILE *file)
+process_arm_specific (FILE * file)
{
return process_attributes (file, "aeabi", SHT_ARM_ATTRIBUTES,
display_arm_attribute, NULL);
}
static int
-process_power_specific (FILE *file)
+process_power_specific (FILE * file)
{
return process_attributes (file, NULL, SHT_GNU_ATTRIBUTES, NULL,
display_power_gnu_attribute);
and return the VMA of the next entry. */
static bfd_vma
-print_mips_got_entry (unsigned char *data, bfd_vma pltgot, bfd_vma addr)
+print_mips_got_entry (unsigned char * data, bfd_vma pltgot, bfd_vma addr)
{
printf (" ");
print_vma (addr, LONG_HEX);
ADDR and return the VMA of the next entry. */
static bfd_vma
-print_mips_pltgot_entry (unsigned char *data, bfd_vma pltgot, bfd_vma addr)
+print_mips_pltgot_entry (unsigned char * data, bfd_vma pltgot, bfd_vma addr)
{
printf (" ");
print_vma (addr, LONG_HEX);
}
static int
-process_mips_specific (FILE *file)
+process_mips_specific (FILE * file)
{
- Elf_Internal_Dyn *entry;
+ Elf_Internal_Dyn * entry;
size_t liblist_offset = 0;
size_t liblistno = 0;
size_t conflictsno = 0;
if (liblist_offset != 0 && liblistno != 0 && do_dynamic)
{
- Elf32_External_Lib *elib;
+ Elf32_External_Lib * elib;
size_t cnt;
elib = get_data (NULL, file, liblist_offset,
Elf32_Lib liblist;
time_t time;
char timebuf[20];
- struct tm *tmp;
+ struct tm * tmp;
liblist.l_name = BYTE_GET (elib[cnt].l_name);
time = BYTE_GET (elib[cnt].l_time_stamp);
{
static const struct
{
- const char *name;
+ const char * name;
int bit;
}
l_flags_vals[] =
if (options_offset != 0)
{
- Elf_External_Options *eopt;
- Elf_Internal_Shdr *sect = section_headers;
- Elf_Internal_Options *iopt;
- Elf_Internal_Options *option;
+ Elf_External_Options * eopt;
+ Elf_Internal_Shdr * sect = section_headers;
+ Elf_Internal_Options * iopt;
+ Elf_Internal_Options * option;
size_t offset;
int cnt;
_("options"));
if (eopt)
{
- iopt = cmalloc ((sect->sh_size / sizeof (eopt)), sizeof (*iopt));
+ iopt = cmalloc ((sect->sh_size / sizeof (eopt)), sizeof (* iopt));
if (iopt == NULL)
{
error (_("Out of memory\n"));
while (offset < sect->sh_size)
{
- Elf_External_Options *eoption;
+ Elf_External_Options * eoption;
eoption = (Elf_External_Options *) ((char *) eopt + offset);
if (elf_header.e_machine == EM_MIPS)
{
/* 32bit form. */
- Elf32_External_RegInfo *ereg;
+ Elf32_External_RegInfo * ereg;
Elf32_RegInfo reginfo;
ereg = (Elf32_External_RegInfo *) (option + 1);
else
{
/* 64 bit form. */
- Elf64_External_RegInfo *ereg;
+ Elf64_External_RegInfo * ereg;
Elf64_Internal_RegInfo reginfo;
ereg = (Elf64_External_RegInfo *) (option + 1);
break;
}
- len = sizeof (*eopt);
+ len = sizeof (* eopt);
while (len < option->size)
if (((char *) option)[len] >= ' '
&& ((char *) option)[len] < 0x7f)
if (conflicts_offset != 0 && conflictsno != 0)
{
- Elf32_Conflict *iconf;
+ Elf32_Conflict * iconf;
size_t cnt;
if (dynamic_symbols == NULL)
return 0;
}
- iconf = cmalloc (conflictsno, sizeof (*iconf));
+ iconf = cmalloc (conflictsno, sizeof (* iconf));
if (iconf == NULL)
{
error (_("Out of memory\n"));
if (is_32bit_elf)
{
- Elf32_External_Conflict *econf32;
+ Elf32_External_Conflict * econf32;
econf32 = get_data (NULL, file, conflicts_offset,
- conflictsno, sizeof (*econf32), _("conflict"));
+ conflictsno, sizeof (* econf32), _("conflict"));
if (!econf32)
return 0;
}
else
{
- Elf64_External_Conflict *econf64;
+ Elf64_External_Conflict * econf64;
econf64 = get_data (NULL, file, conflicts_offset,
- conflictsno, sizeof (*econf64), _("conflict"));
+ conflictsno, sizeof (* econf64), _("conflict"));
if (!econf64)
return 0;
for (cnt = 0; cnt < conflictsno; ++cnt)
{
- Elf_Internal_Sym *psym = & dynamic_symbols[iconf[cnt]];
+ Elf_Internal_Sym * psym = & dynamic_symbols[iconf[cnt]];
printf ("%5lu: %8lu ", (unsigned long) cnt, iconf[cnt]);
print_vma (psym->st_value, FULL_HEX);
{
bfd_vma entry, local_end, global_end;
size_t i, offset;
- unsigned char *data;
+ unsigned char * data;
int addr_size;
entry = pltgot;
sym_width = (is_32bit_elf ? 80 : 160) - 28 - addr_size * 6 - 1;
for (i = gotsym; i < symtabno; i++)
{
- Elf_Internal_Sym *psym;
+ Elf_Internal_Sym * psym;
psym = dynamic_symbols + i;
entry = print_mips_got_entry (data, pltgot, entry);
bfd_vma entry, end;
size_t offset, rel_offset;
unsigned long count, i;
- unsigned char *data;
+ unsigned char * data;
int addr_size, sym_width;
- Elf_Internal_Rela *rels;
+ Elf_Internal_Rela * rels;
rel_offset = offset_from_vma (file, jmprel, pltrelsz);
if (pltrel == DT_RELA)
sym_width = (is_32bit_elf ? 80 : 160) - 17 - addr_size * 6 - 1;
for (i = 0; i < count; i++)
{
- Elf_Internal_Sym *psym;
+ Elf_Internal_Sym * psym;
psym = dynamic_symbols + get_reloc_symindex (rels[i].r_info);
entry = print_mips_pltgot_entry (data, mips_pltgot, entry);
}
static int
-process_gnu_liblist (FILE *file)
+process_gnu_liblist (FILE * file)
{
- Elf_Internal_Shdr *section, *string_sec;
- Elf32_External_Lib *elib;
- char *strtab;
+ Elf_Internal_Shdr * section;
+ Elf_Internal_Shdr * string_sec;
+ Elf32_External_Lib * elib;
+ char * strtab;
size_t strtab_size;
size_t cnt;
unsigned i;
Elf32_Lib liblist;
time_t time;
char timebuf[20];
- struct tm *tmp;
+ struct tm * tmp;
liblist.l_name = BYTE_GET (elib[cnt].l_name);
time = BYTE_GET (elib[cnt].l_time_stamp);
If the value of namesz is zero, there is no name present. */
static int
-process_note (Elf_Internal_Note *pnote)
+process_note (Elf_Internal_Note * pnote)
{
- const char *name = pnote->namesz ? pnote->namedata : "(NONE)";
- const char *nt;
+ const char * name = pnote->namesz ? pnote->namedata : "(NONE)";
+ const char * nt;
if (pnote->namesz == 0)
/* If there is no note name, then use the default set of
static int
-process_corefile_note_segment (FILE *file, bfd_vma offset, bfd_vma length)
+process_corefile_note_segment (FILE * file, bfd_vma offset, bfd_vma length)
{
- Elf_External_Note *pnotes;
- Elf_External_Note *external;
+ Elf_External_Note * pnotes;
+ Elf_External_Note * external;
int res = 1;
if (length <= 0)
(unsigned long) offset, (unsigned long) length);
printf (_(" Owner\t\tData size\tDescription\n"));
- while (external < (Elf_External_Note *)((char *) pnotes + length))
+ while (external < (Elf_External_Note *) ((char *) pnotes + length))
{
- Elf_External_Note *next;
+ Elf_External_Note * next;
Elf_Internal_Note inote;
- char *temp = NULL;
+ char * temp = NULL;
inote.type = BYTE_GET (external->type);
inote.namesz = BYTE_GET (external->namesz);
inote.descdata = inote.namedata + align_power (inote.namesz, 2);
inote.descpos = offset + (inote.descdata - (char *) pnotes);
- next = (Elf_External_Note *)(inote.descdata + align_power (inote.descsz, 2));
+ next = (Elf_External_Note *) (inote.descdata + align_power (inote.descsz, 2));
if (((char *) next) > (((char *) pnotes) + length))
{
}
static int
-process_corefile_note_segments (FILE *file)
+process_corefile_note_segments (FILE * file)
{
- Elf_Internal_Phdr *segment;
+ Elf_Internal_Phdr * segment;
unsigned int i;
int res = 1;
}
static int
-process_note_sections (FILE *file)
+process_note_sections (FILE * file)
{
- Elf_Internal_Shdr *section;
+ Elf_Internal_Shdr * section;
unsigned long i;
int res = 1;
}
static int
-process_notes (FILE *file)
+process_notes (FILE * file)
{
/* If we have not been asked to display the notes then do nothing. */
if (! do_notes)
}
static int
-process_arch_specific (FILE *file)
+process_arch_specific (FILE * file)
{
if (! do_arch)
return 1;
}
static int
-get_file_header (FILE *file)
+get_file_header (FILE * file)
{
/* Read in the identity array. */
if (fread (elf_header.e_ident, EI_NIDENT, 1, file) != 1)
positioned at the start of the ELF object. */
static int
-process_object (char *file_name, FILE *file)
+process_object (char * file_name, FILE * file)
{
unsigned int i;
if (section_groups)
{
- struct group_list *g, *next;
+ struct group_list * g;
+ struct group_list * next;
for (i = 0; i < group_count; i++)
{
return 0;
}
-/* Process an ELF archive.
- On entry the file is positioned just after the ARMAG string. */
+/* Return the path name for a proxy entry in a thin archive, adjusted relative
+ to the path name of the thin archive itself if necessary. Always returns
+ a pointer to malloc'ed memory. */
+
+static char *
+adjust_relative_path (char * file_name, char * name, int name_len)
+{
+ char * member_file_name;
+ const char * base_name = lbasename (file_name);
+
+ /* This is a proxy entry for a thin archive member.
+ If the extended name table contains an absolute path
+ name, or if the archive is in the current directory,
+ use the path name as given. Otherwise, we need to
+ find the member relative to the directory where the
+ archive is located. */
+ if (IS_ABSOLUTE_PATH (name) || base_name == file_name)
+ {
+ member_file_name = malloc (name_len + 1);
+ if (member_file_name == NULL)
+ {
+ error (_("Out of memory\n"));
+ return NULL;
+ }
+ memcpy (member_file_name, name, name_len);
+ member_file_name[name_len] = '\0';
+ }
+ else
+ {
+ /* Concatenate the path components of the archive file name
+ to the relative path name from the extended name table. */
+ size_t prefix_len = base_name - file_name;
+ member_file_name = malloc (prefix_len + name_len + 1);
+ if (member_file_name == NULL)
+ {
+ error (_("Out of memory\n"));
+ return NULL;
+ }
+ memcpy (member_file_name, file_name, prefix_len);
+ memcpy (member_file_name + prefix_len, name, name_len);
+ member_file_name[prefix_len + name_len] = '\0';
+ }
+ return member_file_name;
+}
+
+/* Structure to hold information about an archive file. */
+
+struct archive_info
+{
+ char * file_name; /* Archive file name. */
+ FILE * file; /* Open file descriptor. */
+ unsigned long index_num; /* Number of symbols in table. */
+ unsigned long * index_array; /* The array of member offsets. */
+ char * sym_table; /* The symbol table. */
+ unsigned long sym_size; /* Size of the symbol table. */
+ char * longnames; /* The long file names table. */
+ unsigned long longnames_size; /* Size of the long file names table. */
+ unsigned long nested_member_origin; /* Origin in the nested archive of the current member. */
+ unsigned long next_arhdr_offset; /* Offset of the next archive header. */
+ bfd_boolean is_thin_archive; /* TRUE if this is a thin archive. */
+ struct ar_hdr arhdr; /* Current archive header. */
+};
+
+/* Read the symbol table and long-name table from an archive. */
static int
-process_archive (char *file_name, FILE *file)
+setup_archive (struct archive_info * arch, char * file_name, FILE * file,
+ bfd_boolean is_thin_archive, bfd_boolean read_symbols)
{
- struct ar_hdr arhdr;
size_t got;
unsigned long size;
- unsigned long index_num = 0;
- unsigned long *index_array = NULL;
- char *sym_table = NULL;
- unsigned long sym_size = 0;
- char *longnames = NULL;
- unsigned long longnames_size = 0;
- size_t file_name_size;
- int ret;
- show_name = 1;
-
- got = fread (&arhdr, 1, sizeof arhdr, file);
- if (got != sizeof arhdr)
+ arch->file_name = strdup (file_name);
+ arch->file = file;
+ arch->index_num = 0;
+ arch->index_array = NULL;
+ arch->sym_table = NULL;
+ arch->sym_size = 0;
+ arch->longnames = NULL;
+ arch->longnames_size = 0;
+ arch->nested_member_origin = 0;
+ arch->is_thin_archive = is_thin_archive;
+ arch->next_arhdr_offset = SARMAG;
+
+ /* Read the first archive member header. */
+ if (fseek (file, SARMAG, SEEK_SET) != 0)
+ {
+ error (_("%s: failed to seek to first archive header\n"), file_name);
+ return 1;
+ }
+ got = fread (&arch->arhdr, 1, sizeof arch->arhdr, file);
+ if (got != sizeof arch->arhdr)
{
if (got == 0)
return 0;
}
/* See if this is the archive symbol table. */
- if (const_strneq (arhdr.ar_name, "/ ")
- || const_strneq (arhdr.ar_name, "/SYM64/ "))
+ if (const_strneq (arch->arhdr.ar_name, "/ ")
+ || const_strneq (arch->arhdr.ar_name, "/SYM64/ "))
{
- size = strtoul (arhdr.ar_size, NULL, 10);
+ size = strtoul (arch->arhdr.ar_size, NULL, 10);
size = size + (size & 1);
- if (do_archive_index)
+ arch->next_arhdr_offset += sizeof arch->arhdr + size;
+
+ if (read_symbols)
{
unsigned long i;
/* A buffer used to hold numbers read in from an archive index.
error (_("%s: failed to read archive index\n"), file_name);
return 1;
}
- index_num = byte_get_big_endian (integer_buffer, sizeof integer_buffer);
+ arch->index_num = byte_get_big_endian (integer_buffer, sizeof integer_buffer);
size -= SIZEOF_AR_INDEX_NUMBERS;
/* Read in the archive index. */
- if (size < index_num * SIZEOF_AR_INDEX_NUMBERS)
+ if (size < arch->index_num * SIZEOF_AR_INDEX_NUMBERS)
{
error (_("%s: the archive index is supposed to have %ld entries, but the size in the header is too small\n"),
- file_name, index_num);
+ file_name, arch->index_num);
return 1;
}
- index_buffer = malloc (index_num * SIZEOF_AR_INDEX_NUMBERS);
+ index_buffer = malloc (arch->index_num * SIZEOF_AR_INDEX_NUMBERS);
if (index_buffer == NULL)
{
error (_("Out of memory whilst trying to read archive symbol index\n"));
return 1;
}
- got = fread (index_buffer, SIZEOF_AR_INDEX_NUMBERS, index_num, file);
- if (got != index_num)
+ got = fread (index_buffer, SIZEOF_AR_INDEX_NUMBERS, arch->index_num, file);
+ if (got != arch->index_num)
{
free (index_buffer);
error (_("%s: failed to read archive index\n"), file_name);
- ret = 1;
- goto out;
+ return 1;
}
- size -= index_num * SIZEOF_AR_INDEX_NUMBERS;
+ size -= arch->index_num * SIZEOF_AR_INDEX_NUMBERS;
/* Convert the index numbers into the host's numeric format. */
- index_array = malloc (index_num * sizeof (* index_array));
- if (index_array == NULL)
+ arch->index_array = malloc (arch->index_num * sizeof (* arch->index_array));
+ if (arch->index_array == NULL)
{
free (index_buffer);
error (_("Out of memory whilst trying to convert the archive symbol index\n"));
return 1;
}
- for (i = 0; i < index_num; i++)
- index_array[i] = byte_get_big_endian ((unsigned char *)(index_buffer + (i * SIZEOF_AR_INDEX_NUMBERS)),
- SIZEOF_AR_INDEX_NUMBERS);
+ for (i = 0; i < arch->index_num; i++)
+ arch->index_array[i] = byte_get_big_endian ((unsigned char *) (index_buffer + (i * SIZEOF_AR_INDEX_NUMBERS)),
+ SIZEOF_AR_INDEX_NUMBERS);
free (index_buffer);
/* The remaining space in the header is taken up by the symbol table. */
if (size < 1)
{
error (_("%s: the archive has an index but no symbols\n"), file_name);
- ret = 1;
- goto out;
+ return 1;
}
- sym_table = malloc (size);
- sym_size = size;
- if (sym_table == NULL)
+ arch->sym_table = malloc (size);
+ arch->sym_size = size;
+ if (arch->sym_table == NULL)
{
error (_("Out of memory whilst trying to read archive index symbol table\n"));
- ret = 1;
- goto out;
+ return 1;
}
- got = fread (sym_table, 1, size, file);
+ got = fread (arch->sym_table, 1, size, file);
if (got != size)
{
error (_("%s: failed to read archive index symbol table\n"), file_name);
- ret = 1;
- goto out;
+ return 1;
}
}
else
}
}
- got = fread (& arhdr, 1, sizeof arhdr, file);
- if (got != sizeof arhdr)
+ /* Read the next archive header. */
+ got = fread (&arch->arhdr, 1, sizeof arch->arhdr, file);
+ if (got != sizeof arch->arhdr)
{
if (got == 0)
- {
- ret = 0;
- goto out;
- }
-
+ return 0;
error (_("%s: failed to read archive header following archive index\n"), file_name);
- ret = 1;
- goto out;
+ return 1;
}
}
- else if (do_archive_index)
+ else if (read_symbols)
printf (_("%s has no archive index\n"), file_name);
- if (const_strneq (arhdr.ar_name, "// "))
+ if (const_strneq (arch->arhdr.ar_name, "// "))
{
- /* This is the archive string table holding long member
- names. */
+ /* This is the archive string table holding long member names. */
+ arch->longnames_size = strtoul (arch->arhdr.ar_size, NULL, 10);
+ arch->next_arhdr_offset += sizeof arch->arhdr + arch->longnames_size;
- longnames_size = strtoul (arhdr.ar_size, NULL, 10);
- longnames = malloc (longnames_size);
- if (longnames == NULL)
+ arch->longnames = malloc (arch->longnames_size);
+ if (arch->longnames == NULL)
{
error (_("Out of memory reading long symbol names in archive\n"));
- ret = 1;
- goto out;
+ return 1;
}
- if (fread (longnames, longnames_size, 1, file) != 1)
+ if (fread (arch->longnames, arch->longnames_size, 1, file) != 1)
{
- free (longnames);
+ free (arch->longnames);
+ arch->longnames = NULL;
error (_("%s: failed to read long symbol name string table\n"), file_name);
- ret = 1;
- goto out;
+ return 1;
}
- if ((longnames_size & 1) != 0)
+ if ((arch->longnames_size & 1) != 0)
getc (file);
+ }
- got = fread (& arhdr, 1, sizeof arhdr, file);
- if (got != sizeof arhdr)
- {
- if (got == 0)
- ret = 0;
- else
- {
- error (_("%s: failed to read archive header following long symbol names\n"), file_name);
- ret = 1;
- }
- goto out;
- }
+ return 0;
+}
+
+/* Release the memory used for the archive information. */
+
+static void
+release_archive (struct archive_info * arch)
+{
+ if (arch->file_name != NULL)
+ free (arch->file_name);
+ if (arch->index_array != NULL)
+ free (arch->index_array);
+ if (arch->sym_table != NULL)
+ free (arch->sym_table);
+ if (arch->longnames != NULL)
+ free (arch->longnames);
+}
+
+/* Open and setup a nested archive, if not already open. */
+
+static int
+setup_nested_archive (struct archive_info * nested_arch, char * member_file_name)
+{
+ FILE * member_file;
+
+ /* Have we already setup this archive? */
+ if (nested_arch->file_name != NULL
+ && streq (nested_arch->file_name, member_file_name))
+ return 0;
+
+ /* Close previous file and discard cached information. */
+ if (nested_arch->file != NULL)
+ fclose (nested_arch->file);
+ release_archive (nested_arch);
+
+ member_file = fopen (member_file_name, "rb");
+ if (member_file == NULL)
+ return 1;
+ return setup_archive (nested_arch, member_file_name, member_file, FALSE, FALSE);
+}
+
+static char *
+get_archive_member_name_at (struct archive_info * arch,
+ unsigned long offset,
+ struct archive_info * nested_arch);
+
+/* Get the name of an archive member from the current archive header.
+ For simple names, this will modify the ar_name field of the current
+ archive header. For long names, it will return a pointer to the
+ longnames table. For nested archives, it will open the nested archive
+ and get the name recursively. NESTED_ARCH is a single-entry cache so
+ we don't keep rereading the same information from a nested archive. */
+
+static char *
+get_archive_member_name (struct archive_info * arch,
+ struct archive_info * nested_arch)
+{
+ unsigned long j, k;
+
+ if (arch->arhdr.ar_name[0] == '/')
+ {
+ /* We have a long name. */
+ char * endp;
+ char * member_file_name;
+ char * member_name;
+
+ arch->nested_member_origin = 0;
+ k = j = strtoul (arch->arhdr.ar_name + 1, &endp, 10);
+ if (arch->is_thin_archive && endp != NULL && * endp == ':')
+ arch->nested_member_origin = strtoul (endp + 1, NULL, 10);
+
+ while ((j < arch->longnames_size)
+ && (arch->longnames[j] != '\n')
+ && (arch->longnames[j] != '\0'))
+ j++;
+ if (arch->longnames[j-1] == '/')
+ j--;
+ arch->longnames[j] = '\0';
+
+ if (!arch->is_thin_archive || arch->nested_member_origin == 0)
+ return arch->longnames + k;
+
+ /* This is a proxy for a member of a nested archive.
+ Find the name of the member in that archive. */
+ member_file_name = adjust_relative_path (arch->file_name, arch->longnames + k, j - k);
+ if (member_file_name != NULL
+ && setup_nested_archive (nested_arch, member_file_name) == 0
+ && (member_name = get_archive_member_name_at (nested_arch, arch->nested_member_origin, NULL)) != NULL)
+ {
+ free (member_file_name);
+ return member_name;
+ }
+ free (member_file_name);
+
+ /* Last resort: just return the name of the nested archive. */
+ return arch->longnames + k;
+ }
+
+ /* We have a normal (short) name. */
+ j = 0;
+ while ((arch->arhdr.ar_name[j] != '/') && (j < 16))
+ j++;
+ arch->arhdr.ar_name[j] = '\0';
+ return arch->arhdr.ar_name;
+}
+
+/* Get the name of an archive member at a given OFFSET within an archive ARCH. */
+
+static char *
+get_archive_member_name_at (struct archive_info * arch,
+ unsigned long offset,
+ struct archive_info * nested_arch)
+{
+ size_t got;
+
+ if (fseek (arch->file, offset, SEEK_SET) != 0)
+ {
+ error (_("%s: failed to seek to next file name\n"), arch->file_name);
+ return NULL;
+ }
+ got = fread (&arch->arhdr, 1, sizeof arch->arhdr, arch->file);
+ if (got != sizeof arch->arhdr)
+ {
+ error (_("%s: failed to read archive header\n"), arch->file_name);
+ return NULL;
+ }
+ if (memcmp (arch->arhdr.ar_fmag, ARFMAG, 2) != 0)
+ {
+ error (_("%s: did not find a valid archive header\n"), arch->file_name);
+ return NULL;
+ }
+
+ return get_archive_member_name (arch, nested_arch);
+}
+
+/* Construct a string showing the name of the archive member, qualified
+ with the name of the containing archive file. For thin archives, we
+ use square brackets to denote the indirection. For nested archives,
+ we show the qualified name of the external member inside the square
+ brackets (e.g., "thin.a[normal.a(foo.o)]"). */
+
+static char *
+make_qualified_name (struct archive_info * arch,
+ struct archive_info * nested_arch,
+ char * member_name)
+{
+ size_t len;
+ char * name;
+
+ len = strlen (arch->file_name) + strlen (member_name) + 3;
+ if (arch->is_thin_archive && arch->nested_member_origin != 0)
+ len += strlen (nested_arch->file_name) + 2;
+
+ name = malloc (len);
+ if (name == NULL)
+ {
+ error (_("Out of memory\n"));
+ return NULL;
+ }
+
+ if (arch->is_thin_archive && arch->nested_member_origin != 0)
+ snprintf (name, len, "%s[%s(%s)]", arch->file_name, nested_arch->file_name, member_name);
+ else if (arch->is_thin_archive)
+ snprintf (name, len, "%s[%s]", arch->file_name, member_name);
+ else
+ snprintf (name, len, "%s(%s)", arch->file_name, member_name);
+
+ return name;
+}
+
+/* Process an ELF archive.
+ On entry the file is positioned just after the ARMAG string. */
+
+static int
+process_archive (char * file_name, FILE * file, bfd_boolean is_thin_archive)
+{
+ struct archive_info arch;
+ struct archive_info nested_arch;
+ size_t got;
+ size_t file_name_size;
+ int ret;
+
+ show_name = 1;
+
+ /* The ARCH structure is used to hold information about this archive. */
+ arch.file_name = NULL;
+ arch.file = NULL;
+ arch.index_array = NULL;
+ arch.sym_table = NULL;
+ arch.longnames = NULL;
+
+ /* The NESTED_ARCH structure is used as a single-item cache of information
+ about a nested archive (when members of a thin archive reside within
+ another regular archive file). */
+ nested_arch.file_name = NULL;
+ nested_arch.file = NULL;
+ nested_arch.index_array = NULL;
+ nested_arch.sym_table = NULL;
+ nested_arch.longnames = NULL;
+
+ if (setup_archive (&arch, file_name, file, is_thin_archive, do_archive_index) != 0)
+ {
+ ret = 1;
+ goto out;
}
if (do_archive_index)
{
- if (sym_table == NULL)
+ if (arch.sym_table == NULL)
error (_("%s: unable to dump the index as none was found\n"), file_name);
else
{
- unsigned int i, j, k, l;
- char elf_name[16];
+ unsigned int i, l;
unsigned long current_pos;
printf (_("Index of archive %s: (%ld entries, 0x%lx bytes in the symbol table)\n"),
- file_name, index_num, sym_size);
+ file_name, arch.index_num, arch.sym_size);
current_pos = ftell (file);
- for (i = l = 0; i < index_num; i++)
+ for (i = l = 0; i < arch.index_num; i++)
{
- if ((i == 0) || ((i > 0) && (index_array[i] != index_array[i - 1])))
- {
- if (fseek (file, index_array[i], SEEK_SET) != 0)
- {
- error (_("%s: failed to seek to next file name\n"), file_name);
- ret = 1;
- goto out;
- }
- got = fread (elf_name, 1, 16, file);
- if (got != 16)
- {
- error (_("%s: failed to read file name\n"), file_name);
- ret = 1;
- goto out;
- }
+ if ((i == 0) || ((i > 0) && (arch.index_array[i] != arch.index_array[i - 1])))
+ {
+ char * member_name;
- if (elf_name[0] == '/')
- {
- /* We have a long name. */
- k = j = strtoul (elf_name + 1, NULL, 10);
- while ((j < longnames_size) && (longnames[j] != '/'))
- j++;
- longnames[j] = '\0';
- printf (_("Binary %s contains:\n"), longnames + k);
- longnames[j] = '/';
- }
- else
- {
- j = 0;
- while ((elf_name[j] != '/') && (j < 16))
- j++;
- elf_name[j] = '\0';
- printf(_("Binary %s contains:\n"), elf_name);
+ member_name = get_archive_member_name_at (&arch, arch.index_array[i], &nested_arch);
+
+ if (member_name != NULL)
+ {
+ char * qualified_name = make_qualified_name (&arch, &nested_arch, member_name);
+
+ if (qualified_name != NULL)
+ {
+ printf (_("Binary %s contains:\n"), qualified_name);
+ free (qualified_name);
+ }
}
}
- if (l >= sym_size)
+
+ if (l >= arch.sym_size)
{
error (_("%s: end of the symbol table reached before the end of the index\n"),
file_name);
break;
}
- printf ("\t%s\n", sym_table + l);
- l += strlen (sym_table + l) + 1;
+ printf ("\t%s\n", arch.sym_table + l);
+ l += strlen (arch.sym_table + l) + 1;
}
- if (l < sym_size)
+ if (l & 01)
+ ++l;
+ if (l < arch.sym_size)
error (_("%s: symbols remain in the index symbol table, but without corresponding entries in the index table\n"),
file_name);
- free (index_array);
- index_array = NULL;
- free (sym_table);
- sym_table = NULL;
if (fseek (file, current_pos, SEEK_SET) != 0)
{
error (_("%s: failed to seek back to start of object files in the archive\n"), file_name);
- return 1;
+ ret = 1;
+ goto out;
}
}
&& !do_segments && !do_header && !do_dump && !do_version
&& !do_histogram && !do_debugging && !do_arch && !do_notes
&& !do_section_groups)
- return 0; /* Archive index only. */
+ {
+ ret = 0; /* Archive index only. */
+ goto out;
+ }
}
file_name_size = strlen (file_name);
while (1)
{
- char *name;
- char *nameend;
- char *namealc;
-
- if (arhdr.ar_name[0] == '/')
- {
- unsigned long off;
-
- off = strtoul (arhdr.ar_name + 1, NULL, 10);
- if (off >= longnames_size)
- {
- error (_("%s: invalid archive string table offset %lu\n"), file_name, off);
- ret = 1;
- break;
- }
-
- name = longnames + off;
- nameend = memchr (name, '/', longnames_size - off);
- }
- else
- {
- name = arhdr.ar_name;
- nameend = memchr (name, '/', 16);
- }
-
- if (nameend == NULL)
+ char * name;
+ size_t namelen;
+ char * qualified_name;
+
+ /* Read the next archive header. */
+ if (fseek (file, arch.next_arhdr_offset, SEEK_SET) != 0)
+ {
+ error (_("%s: failed to seek to next archive header\n"), file_name);
+ return 1;
+ }
+ got = fread (&arch.arhdr, 1, sizeof arch.arhdr, file);
+ if (got != sizeof arch.arhdr)
+ {
+ if (got == 0)
+ break;
+ error (_("%s: failed to read archive header\n"), file_name);
+ ret = 1;
+ break;
+ }
+ if (memcmp (arch.arhdr.ar_fmag, ARFMAG, 2) != 0)
+ {
+ error (_("%s: did not find a valid archive header\n"), arch.file_name);
+ ret = 1;
+ break;
+ }
+
+ arch.next_arhdr_offset += sizeof arch.arhdr;
+
+ archive_file_size = strtoul (arch.arhdr.ar_size, NULL, 10);
+ if (archive_file_size & 01)
+ ++archive_file_size;
+
+ name = get_archive_member_name (&arch, &nested_arch);
+ if (name == NULL)
{
error (_("%s: bad archive file name\n"), file_name);
ret = 1;
break;
}
+ namelen = strlen (name);
- namealc = malloc (file_name_size + (nameend - name) + 3);
- if (namealc == NULL)
+ qualified_name = make_qualified_name (&arch, &nested_arch, name);
+ if (qualified_name == NULL)
{
- error (_("Out of memory\n"));
+ error (_("%s: bad archive file name\n"), file_name);
ret = 1;
break;
}
- memcpy (namealc, file_name, file_name_size);
- namealc[file_name_size] = '(';
- memcpy (namealc + file_name_size + 1, name, nameend - name);
- namealc[file_name_size + 1 + (nameend - name)] = ')';
- namealc[file_name_size + 2 + (nameend - name)] = '\0';
-
- archive_file_offset = ftell (file);
- archive_file_size = strtoul (arhdr.ar_size, NULL, 10);
-
- ret |= process_object (namealc, file);
-
- free (namealc);
-
- if (fseek (file,
- (archive_file_offset
- + archive_file_size
- + (archive_file_size & 1)),
- SEEK_SET) != 0)
- {
- error (_("%s: failed to seek to next archive header\n"), file_name);
- ret = 1;
- break;
- }
+ if (is_thin_archive && arch.nested_member_origin == 0)
+ {
+ /* This is a proxy for an external member of a thin archive. */
+ FILE * member_file;
+ char * member_file_name = adjust_relative_path (file_name, name, namelen);
+ if (member_file_name == NULL)
+ {
+ ret = 1;
+ break;
+ }
+
+ member_file = fopen (member_file_name, "rb");
+ if (member_file == NULL)
+ {
+ error (_("Input file '%s' is not readable.\n"), member_file_name);
+ free (member_file_name);
+ ret = 1;
+ break;
+ }
+
+ archive_file_offset = arch.nested_member_origin;
+
+ ret |= process_object (qualified_name, member_file);
+
+ fclose (member_file);
+ free (member_file_name);
+ }
+ else if (is_thin_archive)
+ {
+ /* This is a proxy for a member of a nested archive. */
+ archive_file_offset = arch.nested_member_origin + sizeof arch.arhdr;
+
+ /* The nested archive file will have been opened and setup by
+ get_archive_member_name. */
+ if (fseek (nested_arch.file, archive_file_offset, SEEK_SET) != 0)
+ {
+ error (_("%s: failed to seek to archive member.\n"), nested_arch.file_name);
+ ret = 1;
+ break;
+ }
+
+ ret |= process_object (qualified_name, nested_arch.file);
+ }
+ else
+ {
+ archive_file_offset = arch.next_arhdr_offset;
+ arch.next_arhdr_offset += archive_file_size;
- got = fread (&arhdr, 1, sizeof arhdr, file);
- if (got != sizeof arhdr)
- {
- if (got == 0)
- break;
+ ret |= process_object (qualified_name, file);
+ }
- error (_("%s: failed to read archive header\n"), file_name);
- ret = 1;
- break;
- }
+ free (qualified_name);
}
out:
- if (index_array != NULL)
- free (index_array);
- if (sym_table != NULL)
- free (sym_table);
- if (longnames != NULL)
- free (longnames);
+ if (nested_arch.file != NULL)
+ fclose (nested_arch.file);
+ release_archive (&nested_arch);
+ release_archive (&arch);
return ret;
}
static int
-process_file (char *file_name)
+process_file (char * file_name)
{
- FILE *file;
+ FILE * file;
struct stat statbuf;
char armag[SARMAG];
int ret;
}
if (memcmp (armag, ARMAG, SARMAG) == 0)
- ret = process_archive (file_name, file);
+ ret = process_archive (file_name, file, FALSE);
+ else if (memcmp (armag, ARMAGT, SARMAG) == 0)
+ ret = process_archive (file_name, file, TRUE);
else
{
if (do_archive_index)
symbols. */
void
-print_address (unsigned int addr, FILE *outfile)
+print_address (unsigned int addr, FILE * outfile)
{
fprintf (outfile,"0x%8.8x", addr);
}
#endif
int
-main (int argc, char **argv)
+main (int argc, char ** argv)
{
int err;