diff options
author | Nick Clifton <nickc@redhat.com> | 2009-03-02 16:06:50 +0000 |
---|---|---|
committer | Nick Clifton <nickc@redhat.com> | 2009-03-02 16:06:50 +0000 |
commit | 2cf0635d9d31c1963c4546ae44895ec3b5bf024c (patch) | |
tree | d1f44e077521b1e98298da5d2d6964577319e0f8 | |
parent | 83cf10fd4ad07a883ae243f1323125f60ad92deb (diff) | |
download | gdb-2cf0635d9d31c1963c4546ae44895ec3b5bf024c.zip gdb-2cf0635d9d31c1963c4546ae44895ec3b5bf024c.tar.gz gdb-2cf0635d9d31c1963c4546ae44895ec3b5bf024c.tar.bz2 |
* readelf.c (adjust_relative_path): New function.
(struct archive_info): New type.
(setup_archive): New function.
(release_archive): New function.
(setup_nested_archive): New function.
(get_archive_member_name): New function.
(get_archive_member_name_at): New function.
(make_qualified_name): New function.
(process_archive): Factor out code for reading archive index and
long filename table to setup_archive. Add support for thin archives.
-rw-r--r-- | binutils/ChangeLog | 13 | ||||
-rw-r--r-- | binutils/readelf.c | 1408 |
2 files changed, 859 insertions, 562 deletions
diff --git a/binutils/ChangeLog b/binutils/ChangeLog index 468d32b..e4ab6cd 100644 --- a/binutils/ChangeLog +++ b/binutils/ChangeLog @@ -1,3 +1,16 @@ +2009-03-02 Cary Coutant <ccoutant@google.com> + + * readelf.c (adjust_relative_path): New function. + (struct archive_info): New type. + (setup_archive): New function. + (release_archive): New function. + (setup_nested_archive): New function. + (get_archive_member_name): New function. + (get_archive_member_name_at): New function. + (make_qualified_name): New function. + (process_archive): Factor out code for reading archive index and + long filename table to setup_archive. Add support for thin archives. + 2009-03-02 Nick Clifton <nickc@redhat.com> * po/sk.po: Updated Slovak translation. diff --git a/binutils/readelf.c b/binutils/readelf.c index 16aae47..3431249 100644 --- a/binutils/readelf.c +++ b/binutils/readelf.c @@ -1,6 +1,6 @@ /* 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> @@ -145,21 +145,22 @@ #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]; @@ -167,10 +168,10 @@ static bfd_vma dynamic_info[DT_JMPREL + 1]; 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; @@ -193,19 +194,19 @@ static int is_32bit_elf; 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. */ @@ -219,11 +220,11 @@ typedef unsigned char dump_type; /* 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. */ @@ -252,7 +253,7 @@ typedef enum print_mode } print_mode; -static void (*byte_put) (unsigned char *, bfd_vma, int); +static void (* byte_put) (unsigned char *, bfd_vma, int); #define UNKNOWN -1 @@ -281,10 +282,10 @@ static void (*byte_put) (unsigned char *, bfd_vma, int); #define const_strneq(a,b) (strncmp ((a), (b), sizeof (b) - 1) == 0) 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; @@ -327,7 +328,7 @@ get_data (void *var, FILE *file, long offset, size_t size, size_t nmemb, } 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) { @@ -405,7 +406,7 @@ print_vma (bfd_vma vma, print_mode mode) 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; @@ -488,7 +489,7 @@ print_symbol (int width, const char *symbol) } 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) { @@ -522,7 +523,7 @@ byte_put_big_endian (unsigned char *field, bfd_vma value, int 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; @@ -637,19 +638,19 @@ guess_is_rela (unsigned int e_machine) } 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) @@ -677,7 +678,7 @@ slurp_rela_relocs (FILE *file, } else { - Elf64_External_Rela *erelas; + Elf64_External_Rela * erelas; erelas = get_data (NULL, file, rel_offset, 1, rel_size, _("relocs")); if (!erelas) @@ -731,19 +732,19 @@ slurp_rela_relocs (FILE *file, } 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) @@ -771,7 +772,7 @@ slurp_rel_relocs (FILE *file, } else { - Elf64_External_Rel *erels; + Elf64_External_Rel * erels; erels = get_data (NULL, file, rel_offset, 1, rel_size, _("relocs")); if (!erels) @@ -858,18 +859,17 @@ get_reloc_symindex (bfd_vma reloc_info) 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); @@ -922,7 +922,7 @@ dump_relocations (FILE *file, for (i = 0; i < rel_size; i++) { - const char *rtype; + const char * rtype; bfd_vma offset; bfd_vma info; bfd_vma symtab_index; @@ -1232,7 +1232,7 @@ dump_relocations (FILE *file, printf (" bad symbol index: %08lx", (unsigned long) symtab_index); else { - Elf_Internal_Sym *psym; + Elf_Internal_Sym * psym; psym = symtab + symtab_index; @@ -1244,7 +1244,7 @@ dump_relocations (FILE *file, 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) @@ -1320,8 +1320,8 @@ dump_relocations (FILE *file, { 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: "); @@ -1625,7 +1625,7 @@ get_dynamic_type (unsigned long type) default: if ((type >= DT_LOPROC) && (type <= DT_HIPROC)) { - const char *result; + const char * result; switch (elf_header.e_machine) { @@ -1665,7 +1665,7 @@ get_dynamic_type (unsigned long type) || (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) { @@ -2089,9 +2089,9 @@ get_machine_flags (unsigned e_flags, unsigned 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) { @@ -2516,7 +2516,7 @@ get_segment_type (unsigned long p_type) default: if ((p_type >= PT_LOPROC) && (p_type <= PT_HIPROC)) { - const char *result; + const char * result; switch (elf_header.e_machine) { @@ -2545,7 +2545,7 @@ get_segment_type (unsigned long p_type) } else if ((p_type >= PT_LOOS) && (p_type <= PT_HIOS)) { - const char *result; + const char * result; switch (elf_header.e_machine) { @@ -2731,7 +2731,7 @@ get_section_type_name (unsigned int sh_type) default: if ((sh_type >= SHT_LOPROC) && (sh_type <= SHT_HIPROC)) { - const char *result; + const char * result; switch (elf_header.e_machine) { @@ -2763,7 +2763,7 @@ get_section_type_name (unsigned int sh_type) } else if ((sh_type >= SHT_LOOS) && (sh_type <= SHT_HIOS)) { - const char *result; + const char * result; switch (elf_header.e_machine) { @@ -2828,7 +2828,7 @@ static struct option options[] = }; 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")); @@ -2887,7 +2887,7 @@ request_dump_bynumber (unsigned int section, dump_type type) { if (section >= num_dump_sects) { - dump_type *new_dump_sects; + dump_type * new_dump_sects; new_dump_sects = calloc (section + 1, sizeof (* dump_sects)); @@ -2914,9 +2914,9 @@ request_dump_bynumber (unsigned int section, dump_type type) /* 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) @@ -2933,7 +2933,7 @@ request_dump_byname (const char *section, dump_type type) } static void -parse_args (int argc, char **argv) +parse_args (int argc, char ** argv) { int c; @@ -2943,7 +2943,7 @@ parse_args (int argc, char **argv) while ((c = getopt_long (argc, argv, "ADHINSVWacdeghi:lnp:rstuvw::x:", options, NULL)) != EOF) { - char *cp; + char * cp; int section; switch (c) @@ -3227,11 +3227,11 @@ process_file_header (void) 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, @@ -3260,11 +3260,11 @@ get_32bit_program_headers (FILE *file, Elf_Internal_Phdr *program_headers) } 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, @@ -3295,9 +3295,9 @@ get_64bit_program_headers (FILE *file, Elf_Internal_Phdr *program_headers) /* 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) @@ -3326,9 +3326,9 @@ get_program_headers (FILE *file) /* 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) @@ -3474,7 +3474,7 @@ process_program_headers (FILE *file) 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) @@ -3537,7 +3537,7 @@ process_program_headers (FILE *file) 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; @@ -3546,7 +3546,7 @@ process_program_headers (FILE *file) 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)); } @@ -3561,9 +3561,9 @@ process_program_headers (FILE *file) /* 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)) { @@ -3590,10 +3590,10 @@ offset_from_vma (FILE *file, bfd_vma vma, bfd_size_type size) 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, @@ -3631,10 +3631,10 @@ get_32bit_section_headers (FILE *file, unsigned int num) } 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, @@ -3672,13 +3672,13 @@ get_64bit_section_headers (FILE *file, unsigned int num) } 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, @@ -3737,13 +3737,13 @@ get_32bit_elf_symbols (FILE *file, Elf_Internal_Shdr *section) } 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, @@ -3805,7 +3805,7 @@ static const char * 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; @@ -3813,7 +3813,7 @@ get_elf_section_flags (bfd_vma sh_flags) bfd_vma unknown_flags = 0; static const struct { - const char *str; + const char * str; int len; } flags [] = @@ -4006,9 +4006,9 @@ get_elf_section_flags (bfd_vma sh_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; @@ -4123,7 +4123,7 @@ process_section_headers (FILE *file) i < elf_header.e_shnum; i++, section++) { - char *name = SECTION_NAME (section); + char * name = SECTION_NAME (section); if (section->sh_type == SHT_DYNSYM) { @@ -4406,14 +4406,15 @@ get_group_flags (unsigned int flags) } 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. */ @@ -4478,12 +4479,13 @@ process_section_groups (FILE *file) { 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 @@ -4566,7 +4568,7 @@ process_section_groups (FILE *file) for (j = 0; j < size; j++) { - struct group_list *g; + struct group_list * g; entry = byte_get (indices, 4); indices += 4; @@ -4632,7 +4634,7 @@ process_section_groups (FILE *file) static struct { - const char *name; + const char * name; int reloc; int size; int rela; @@ -4646,7 +4648,7 @@ static struct /* Process the reloc section. */ static int -process_relocs (FILE *file) +process_relocs (FILE * file) { unsigned long rel_size; unsigned long rel_offset; @@ -4658,7 +4660,7 @@ process_relocs (FILE *file) if (do_using_dynamic) { int is_rela; - const char *name; + const char * name; int has_dynamic_reloc; unsigned int i; @@ -4706,7 +4708,7 @@ process_relocs (FILE *file) } else { - Elf_Internal_Shdr *section; + Elf_Internal_Shdr * section; unsigned long i; int found = 0; @@ -4723,7 +4725,7 @@ process_relocs (FILE *file) if (rel_size) { - Elf_Internal_Shdr *strsec; + Elf_Internal_Shdr * strsec; int is_rela; printf (_("\nRelocation section ")); @@ -4741,11 +4743,11 @@ process_relocs (FILE *file) 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 @@ -4819,27 +4821,28 @@ struct ia64_unw_aux_info } *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) @@ -4868,18 +4871,18 @@ find_symbol_for_address (Elf_Internal_Sym *symtab, } 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); @@ -4924,18 +4927,20 @@ dump_ia64_unwind (struct ia64_unw_aux_info *aux) } 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: */ @@ -5046,9 +5051,11 @@ slurp_ia64_unwind_table (FILE *file, } 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; @@ -5076,7 +5083,7 @@ ia64_process_unwind (FILE *file) while (unwcount-- > 0) { - char *suffix; + char * suffix; size_t len, len2; for (i = unwstart, sec = section_headers + unwstart; @@ -5093,7 +5100,7 @@ ia64_process_unwind (FILE *file) 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) { @@ -5223,21 +5230,21 @@ struct hppa_unw_aux_info *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, @@ -5296,18 +5303,20 @@ dump_hppa_unwind (struct hppa_unw_aux_info *aux) } 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. */ @@ -5447,12 +5456,12 @@ slurp_hppa_unwind_table (FILE *file, } 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)); @@ -5510,12 +5519,14 @@ hppa_process_unwind (FILE *file) } 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 } @@ -5534,7 +5545,7 @@ process_unwind (FILE *file) } static void -dynamic_section_mips_val (Elf_Internal_Dyn *entry) +dynamic_section_mips_val (Elf_Internal_Dyn * entry) { switch (entry->d_tag) { @@ -5573,7 +5584,7 @@ dynamic_section_mips_val (Elf_Internal_Dyn *entry) 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); @@ -5607,7 +5618,7 @@ dynamic_section_mips_val (Elf_Internal_Dyn *entry) static void -dynamic_section_parisc_val (Elf_Internal_Dyn *entry) +dynamic_section_parisc_val (Elf_Internal_Dyn * entry) { switch (entry->d_tag) { @@ -5616,7 +5627,7 @@ dynamic_section_parisc_val (Elf_Internal_Dyn *entry) static struct { long int bit; - const char *str; + const char * str; } flags[] = { @@ -5669,7 +5680,7 @@ dynamic_section_parisc_val (Elf_Internal_Dyn *entry) } static void -dynamic_section_ia64_val (Elf_Internal_Dyn *entry) +dynamic_section_ia64_val (Elf_Internal_Dyn * entry) { switch (entry->d_tag) { @@ -5688,10 +5699,11 @@ dynamic_section_ia64_val (Elf_Internal_Dyn *entry) } 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")); @@ -5710,7 +5722,7 @@ get_32bit_dynamic_section (FILE *file) break; } - dynamic_section = cmalloc (dynamic_nent, sizeof (*entry)); + dynamic_section = cmalloc (dynamic_nent, sizeof (* entry)); if (dynamic_section == NULL) { error (_("Out of memory\n")); @@ -5732,10 +5744,11 @@ get_32bit_dynamic_section (FILE *file) } 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")); @@ -5754,7 +5767,7 @@ get_64bit_dynamic_section (FILE *file) break; } - dynamic_section = cmalloc (dynamic_nent, sizeof (*entry)); + dynamic_section = cmalloc (dynamic_nent, sizeof (* entry)); if (dynamic_section == NULL) { error (_("Out of memory\n")); @@ -5808,9 +5821,9 @@ print_dynamic_flags (bfd_vma flags) /* 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) { @@ -5943,8 +5956,9 @@ process_dynamic_section (FILE *file) 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, @@ -5984,7 +5998,7 @@ process_dynamic_section (FILE *file) { if (do_dynamic) { - const char *dtype; + const char * dtype; putchar (' '); print_vma (entry->d_tag, FULL_HEX); @@ -6213,7 +6227,7 @@ process_dynamic_section (FILE *file) 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); @@ -6299,7 +6313,7 @@ process_dynamic_section (FILE *file) 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) { @@ -6322,7 +6336,7 @@ process_dynamic_section (FILE *file) case DT_GNU_PRELINKED: if (do_dynamic) { - struct tm *tmp; + struct tm * tmp; time_t time = entry->d_un.d_val; tmp = gmtime (&time); @@ -6402,9 +6416,9 @@ get_ver_flags (unsigned int flags) /* 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; @@ -6419,10 +6433,10 @@ process_version_sections (FILE *file) { case SHT_GNU_verdef: { - Elf_External_Verdef *edefs; + Elf_External_Verdef * edefs; unsigned int idx; unsigned int cnt; - char *endbuf; + char * endbuf; found = 1; @@ -6447,10 +6461,10 @@ process_version_sections (FILE *file) 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; @@ -6522,10 +6536,10 @@ process_version_sections (FILE *file) case SHT_GNU_verneed: { - Elf_External_Verneed *eneed; + Elf_External_Verneed * eneed; unsigned int idx; unsigned int cnt; - char *endbuf; + char * endbuf; found = 1; @@ -6549,11 +6563,11 @@ process_version_sections (FILE *file) 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) @@ -6580,7 +6594,7 @@ process_version_sections (FILE *file) 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) @@ -6620,14 +6634,14 @@ process_version_sections (FILE *file) 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) @@ -6682,7 +6696,7 @@ process_version_sections (FILE *file) { int j, nn; int check_def, check_need; - char *name; + char * name; printf (" %03x:", cnt); @@ -7004,10 +7018,10 @@ get_symbol_index_type (unsigned int type) } 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); @@ -7043,7 +7057,7 @@ get_dynamic_data (FILE *file, unsigned int number, unsigned int 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; @@ -7075,16 +7089,16 @@ print_dynamic_symbol (bfd_vma si, unsigned long hn) /* 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) @@ -7297,11 +7311,10 @@ process_symbol_table (FILE *file) 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) @@ -7326,7 +7339,7 @@ process_symbol_table (FILE *file) } 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; @@ -7506,8 +7519,8 @@ process_symbol_table (FILE *file) 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; @@ -7570,8 +7583,8 @@ process_symbol_table (FILE *file) 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; @@ -7636,7 +7649,7 @@ process_symbol_table (FILE *file) } static int -process_syminfo (FILE *file ATTRIBUTE_UNUSED) +process_syminfo (FILE * file ATTRIBUTE_UNUSED) { unsigned int i; @@ -7703,7 +7716,7 @@ process_syminfo (FILE *file ATTRIBUTE_UNUSED) #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)); @@ -7715,15 +7728,15 @@ disassemble_section (Elf_Internal_Shdr *section, FILE *file) #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; @@ -7796,13 +7809,13 @@ dump_section_as_strings (Elf_Internal_Shdr *section, FILE *file) 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; @@ -8211,7 +8224,7 @@ is_none_reloc (unsigned int reloc_type) 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. */ @@ -8283,12 +8296,12 @@ uncompress_section_contents (unsigned char **buffer, dwarf_size_type *size) /* 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; @@ -8300,10 +8313,11 @@ debug_apply_relocations (void *file, { 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 @@ -8415,9 +8429,9 @@ debug_apply_relocations (void *file, 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; @@ -8446,10 +8460,10 @@ load_specific_debug_section (enum dwarf_section_display_enum debug, } 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); @@ -8470,7 +8484,7 @@ load_debug_section (enum dwarf_section_display_enum debug, void *file) 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; @@ -8482,9 +8496,9 @@ free_debug_section (enum dwarf_section_display_enum debug) } 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; @@ -8504,7 +8518,7 @@ display_debug_section (Elf_Internal_Shdr *section, FILE *file) 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) @@ -8540,7 +8554,7 @@ display_debug_section (Elf_Internal_Shdr *section, FILE *file) 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) { @@ -8561,9 +8575,9 @@ initialise_dumps_byname (void) } 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) @@ -8621,68 +8635,68 @@ process_mips_fpe_exception (int mask) 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} @@ -8731,8 +8745,9 @@ static arm_attr_public_tag arm_attr_public_tags[] = /* 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; @@ -8756,19 +8771,19 @@ read_uleb128 (unsigned char *p, unsigned int *plen) } 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) { @@ -8802,7 +8817,7 @@ display_arm_attribute (unsigned char *p) 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. */ @@ -8817,7 +8832,7 @@ display_arm_attribute (unsigned char *p) { 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]); @@ -8828,7 +8843,7 @@ display_arm_attribute (unsigned char *p) break; default: - abort(); + abort (); } return p; @@ -8861,7 +8876,7 @@ display_arm_attribute (unsigned char *p) if (type == 1) { printf ("\"%s\"\n", p); - p += strlen((char *)p) + 1; + p += strlen ((char *) p) + 1; } else { @@ -8921,7 +8936,7 @@ display_gnu_attribute (unsigned char * p, } 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; @@ -9025,7 +9040,7 @@ display_power_gnu_attribute (unsigned char *p, int tag) } 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; @@ -9089,10 +9104,10 @@ process_attributes (FILE * file, 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; @@ -9225,14 +9240,14 @@ process_attributes (FILE * file, } 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); @@ -9243,7 +9258,7 @@ process_power_specific (FILE *file) 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); @@ -9270,7 +9285,7 @@ print_mips_got_entry (unsigned char *data, bfd_vma pltgot, bfd_vma addr) 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); @@ -9288,9 +9303,9 @@ print_mips_pltgot_entry (unsigned char *data, bfd_vma pltgot, bfd_vma addr) } 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; @@ -9365,7 +9380,7 @@ process_mips_specific (FILE *file) 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, @@ -9383,7 +9398,7 @@ process_mips_specific (FILE *file) 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); @@ -9411,7 +9426,7 @@ process_mips_specific (FILE *file) { static const struct { - const char *name; + const char * name; int bit; } l_flags_vals[] = @@ -9445,10 +9460,10 @@ process_mips_specific (FILE *file) 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; @@ -9460,7 +9475,7 @@ process_mips_specific (FILE *file) _("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")); @@ -9472,7 +9487,7 @@ process_mips_specific (FILE *file) while (offset < sect->sh_size) { - Elf_External_Options *eoption; + Elf_External_Options * eoption; eoption = (Elf_External_Options *) ((char *) eopt + offset); @@ -9507,7 +9522,7 @@ process_mips_specific (FILE *file) 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); @@ -9528,7 +9543,7 @@ process_mips_specific (FILE *file) else { /* 64 bit form. */ - Elf64_External_RegInfo *ereg; + Elf64_External_RegInfo * ereg; Elf64_Internal_RegInfo reginfo; ereg = (Elf64_External_RegInfo *) (option + 1); @@ -9625,7 +9640,7 @@ process_mips_specific (FILE *file) break; } - len = sizeof (*eopt); + len = sizeof (* eopt); while (len < option->size) if (((char *) option)[len] >= ' ' && ((char *) option)[len] < 0x7f) @@ -9643,7 +9658,7 @@ process_mips_specific (FILE *file) if (conflicts_offset != 0 && conflictsno != 0) { - Elf32_Conflict *iconf; + Elf32_Conflict * iconf; size_t cnt; if (dynamic_symbols == NULL) @@ -9652,7 +9667,7 @@ process_mips_specific (FILE *file) return 0; } - iconf = cmalloc (conflictsno, sizeof (*iconf)); + iconf = cmalloc (conflictsno, sizeof (* iconf)); if (iconf == NULL) { error (_("Out of memory\n")); @@ -9661,10 +9676,10 @@ process_mips_specific (FILE *file) 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; @@ -9675,10 +9690,10 @@ process_mips_specific (FILE *file) } 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; @@ -9694,7 +9709,7 @@ process_mips_specific (FILE *file) 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); @@ -9713,7 +9728,7 @@ process_mips_specific (FILE *file) { bfd_vma entry, local_end, global_end; size_t i, offset; - unsigned char *data; + unsigned char * data; int addr_size; entry = pltgot; @@ -9769,7 +9784,7 @@ process_mips_specific (FILE *file) 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); @@ -9796,9 +9811,9 @@ process_mips_specific (FILE *file) 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) @@ -9836,7 +9851,7 @@ process_mips_specific (FILE *file) 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); @@ -9862,11 +9877,12 @@ process_mips_specific (FILE *file) } 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; @@ -9914,7 +9930,7 @@ process_gnu_liblist (FILE *file) 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); @@ -10091,10 +10107,10 @@ get_netbsd_elfcore_note_type (unsigned e_type) 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 @@ -10127,10 +10143,10 @@ process_note (Elf_Internal_Note *pnote) 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) @@ -10146,11 +10162,11 @@ process_corefile_note_segment (FILE *file, bfd_vma offset, bfd_vma length) (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); @@ -10159,7 +10175,7 @@ process_corefile_note_segment (FILE *file, bfd_vma offset, bfd_vma length) 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)) { @@ -10209,9 +10225,9 @@ process_corefile_note_segment (FILE *file, bfd_vma offset, bfd_vma 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; @@ -10232,9 +10248,9 @@ process_corefile_note_segments (FILE *file) } 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; @@ -10250,7 +10266,7 @@ process_note_sections (FILE *file) } 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) @@ -10268,7 +10284,7 @@ process_notes (FILE *file) } static int -process_arch_specific (FILE *file) +process_arch_specific (FILE * file) { if (! do_arch) return 1; @@ -10291,7 +10307,7 @@ process_arch_specific (FILE *file) } 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) @@ -10388,7 +10404,7 @@ get_file_header (FILE *file) 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; @@ -10514,7 +10530,8 @@ process_object (char *file_name, FILE *file) if (section_groups) { - struct group_list *g, *next; + struct group_list * g; + struct group_list * next; for (i = 0; i < group_count; i++) { @@ -10534,28 +10551,98 @@ process_object (char *file_name, FILE *file) 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; @@ -10565,13 +10652,15 @@ process_archive (char *file_name, FILE *file) } /* 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. @@ -10594,67 +10683,63 @@ process_archive (char *file_name, FILE *file) 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 @@ -10666,135 +10751,304 @@ process_archive (char *file_name, FILE *file) } } - 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; } } @@ -10802,7 +11056,10 @@ process_archive (char *file_name, FILE *file) && !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); @@ -10810,97 +11067,122 @@ process_archive (char *file_name, FILE *file) 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; @@ -10936,7 +11218,9 @@ process_file (char *file_name) } 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) @@ -10959,7 +11243,7 @@ process_file (char *file_name) symbols. */ void -print_address (unsigned int addr, FILE *outfile) +print_address (unsigned int addr, FILE * outfile) { fprintf (outfile,"0x%8.8x", addr); } @@ -10973,7 +11257,7 @@ db_task_printsym (unsigned int addr) #endif int -main (int argc, char **argv) +main (int argc, char ** argv) { int err; |