PATCH: Add archive support to ELF
H. J. Lu
hjl@lucon.org
Sat Aug 9 00:40:00 GMT 2003
This patch supports "readelf -s libfoo.a".
H.J.
-------------- next part --------------
bfd/
2003-08-08 H.J. Lu <hongjiu.lu@intel.com>
* bfd-in.h (file_ptr): Defined it as long.
(ufile_ptr): Defined as unsigned long.
(bfd_host_size_type): New.
(bfd_bread): Use bfd_host_size_type instead of bfd_size_type.
(bfd_bwrite): Likeweise.
* bfdio.c (bfd_bread): Likeweise.
(bfd_bwrite): Likeweise.
(bfd_seek): Likeweise.
* bfd-in2.h: Regenerated.
binutils/
2003-08-08 H.J. Lu <hongjiu.lu@intel.com>
* Makefile.am (readelf_LDADD): Add $(BFDLIB).
* Makefile.in: Regenerated.
* readelf.c: Replace FILE * with bfd *.
Replace fseek with bfd_seek.
Replace bread with bfd_bread.
Replace fscanf with bfd_bread.
(process_bfd): New.
(process_file): Support archive.
--- binutils/bfd/bfd-in.h.archive 2003-07-14 12:49:10.000000000 -0700
+++ binutils/bfd/bfd-in.h 2003-08-08 17:04:54.000000000 -0700
@@ -169,8 +169,10 @@ typedef unsigned long bfd_size_type;
in this header file, and to handle this in the BFD implementation
rather than in its interface. */
/* typedef off_t file_ptr; */
-typedef bfd_signed_vma file_ptr;
-typedef bfd_vma ufile_ptr;
+typedef long file_ptr;
+typedef unsigned long ufile_ptr;
+
+typedef unsigned long bfd_host_size_type;
extern void bfd_sprintf_vma (bfd *, char *, bfd_vma);
extern void bfd_fprintf_vma (bfd *, void *, bfd_vma);
@@ -454,8 +456,8 @@ extern void bfd_hash_traverse
/* Direct I/O routines, for programs which know more about the object
file than BFD does. Use higher level routines if possible. */
-extern bfd_size_type bfd_bread (void *, bfd_size_type, bfd *);
-extern bfd_size_type bfd_bwrite (const void *, bfd_size_type, bfd *);
+extern bfd_host_size_type bfd_bread (void *, bfd_host_size_type, bfd *);
+extern bfd_host_size_type bfd_bwrite (const void *, bfd_host_size_type, bfd *);
extern int bfd_seek (bfd *, file_ptr, int);
extern ufile_ptr bfd_tell (bfd *);
extern int bfd_flush (bfd *);
--- binutils/bfd/bfdio.c.archive 2003-06-30 08:05:19.000000000 -0700
+++ binutils/bfd/bfdio.c 2003-08-08 17:06:19.000000000 -0700
@@ -70,21 +70,21 @@ real_read (void *where, size_t a, size_t
/* Return value is amount read. */
-bfd_size_type
-bfd_bread (void *ptr, bfd_size_type size, bfd *abfd)
+bfd_host_size_type
+bfd_bread (void *ptr, bfd_host_size_type size, bfd *abfd)
{
size_t nread;
if ((abfd->flags & BFD_IN_MEMORY) != 0)
{
struct bfd_in_memory *bim;
- bfd_size_type get;
+ bfd_host_size_type get;
bim = abfd->iostream;
get = size;
if (abfd->where + get > bim->size)
{
- if (bim->size < (bfd_size_type) abfd->where)
+ if (bim->size < (bfd_host_size_type) abfd->where)
get = 0;
else
get = bim->size - abfd->where;
@@ -117,8 +117,8 @@ bfd_bread (void *ptr, bfd_size_type size
return nread;
}
-bfd_size_type
-bfd_bwrite (const void *ptr, bfd_size_type size, bfd *abfd)
+bfd_host_size_type
+bfd_bwrite (const void *ptr, bfd_host_size_type size, bfd *abfd)
{
size_t nwrote;
@@ -128,12 +128,12 @@ bfd_bwrite (const void *ptr, bfd_size_ty
size = (size_t) size;
if (abfd->where + size > bim->size)
{
- bfd_size_type newsize, oldsize;
+ bfd_host_size_type newsize, oldsize;
- oldsize = (bim->size + 127) & ~(bfd_size_type) 127;
+ oldsize = (bim->size + 127) & ~(bfd_host_size_type) 127;
bim->size = abfd->where + size;
/* Round up to cut down on memory fragmentation */
- newsize = (bim->size + 127) & ~(bfd_size_type) 127;
+ newsize = (bim->size + 127) & ~(bfd_host_size_type) 127;
if (newsize > oldsize)
{
bim->buffer = bfd_realloc (bim->buffer, newsize);
@@ -243,11 +243,11 @@ bfd_seek (bfd *abfd, file_ptr position,
if ((abfd->direction == write_direction) ||
(abfd->direction == both_direction))
{
- bfd_size_type newsize, oldsize;
- oldsize = (bim->size + 127) & ~(bfd_size_type) 127;
+ bfd_host_size_type newsize, oldsize;
+ oldsize = (bim->size + 127) & ~(bfd_host_size_type) 127;
bim->size = abfd->where;
/* Round up to cut down on memory fragmentation */
- newsize = (bim->size + 127) & ~(bfd_size_type) 127;
+ newsize = (bim->size + 127) & ~(bfd_host_size_type) 127;
if (newsize > oldsize)
{
bim->buffer = bfd_realloc (bim->buffer, newsize);
--- binutils/binutils/Makefile.am.archive 2003-03-24 09:53:01.000000000 -0800
+++ binutils/binutils/Makefile.am 2003-08-08 15:03:07.000000000 -0700
@@ -168,7 +168,7 @@ objcopy_SOURCES = objcopy.c not-strip.c
strings_SOURCES = strings.c $(BULIBS)
readelf_SOURCES = readelf.c version.c unwind-ia64.c
-readelf_LDADD = $(INTLLIBS) $(LIBIBERTY)
+readelf_LDADD = $(BFDLIB) $(INTLLIBS) $(LIBIBERTY)
strip_new_SOURCES = objcopy.c is-strip.c rename.c $(WRITE_DEBUG_SRCS) $(BULIBS)
--- binutils/binutils/readelf.c.archive 2003-08-06 08:17:02.000000000 -0700
+++ binutils/binutils/readelf.c 2003-08-08 17:28:19.000000000 -0700
@@ -209,9 +209,9 @@ typedef int Elf32_Word;
#define NUM_ELEM(array) (sizeof (array) / sizeof ((array)[0]))
-#define GET_ELF_SYMBOLS(file, section) \
- (is_32bit_elf ? get_32bit_elf_symbols (file, section) \
- : get_64bit_elf_symbols (file, section))
+#define GET_ELF_SYMBOLS(abfd, section) \
+ (is_32bit_elf ? get_32bit_elf_symbols (abfd, section) \
+ : get_64bit_elf_symbols (abfd, section))
static void
@@ -237,14 +237,15 @@ warn (const char *message, ...)
}
static void *
-get_data (void *var, FILE *file, long offset, size_t size, const char *reason)
+get_data (void *var, bfd *abfd, long offset, size_t size,
+ const char *reason)
{
void *mvar;
if (size == 0)
return NULL;
- if (fseek (file, offset, SEEK_SET))
+ if (bfd_seek (abfd, offset, SEEK_SET))
{
error (_("Unable to seek to 0x%x for %s\n"), offset, reason);
return NULL;
@@ -263,7 +264,7 @@ get_data (void *var, FILE *file, long of
}
}
- if (fread (mvar, size, 1, file) != 1)
+ if (bfd_bread (mvar, size, abfd) != size)
{
error (_("Unable to read in 0x%x bytes of %s\n"), size, reason);
if (mvar != var)
@@ -671,7 +672,7 @@ guess_is_rela (unsigned long e_machine)
}
static int
-slurp_rela_relocs (FILE *file,
+slurp_rela_relocs (bfd *abfd,
unsigned long rel_offset,
unsigned long rel_size,
Elf_Internal_Rela **relasp,
@@ -685,7 +686,7 @@ slurp_rela_relocs (FILE *file,
{
Elf32_External_Rela *erelas;
- erelas = get_data (NULL, file, rel_offset, rel_size, _("relocs"));
+ erelas = get_data (NULL, abfd, rel_offset, rel_size, _("relocs"));
if (!erelas)
return 0;
@@ -712,7 +713,7 @@ slurp_rela_relocs (FILE *file,
{
Elf64_External_Rela *erelas;
- erelas = get_data (NULL, file, rel_offset, rel_size, _("relocs"));
+ erelas = get_data (NULL, abfd, rel_offset, rel_size, _("relocs"));
if (!erelas)
return 0;
@@ -741,7 +742,7 @@ slurp_rela_relocs (FILE *file,
}
static int
-slurp_rel_relocs (FILE *file,
+slurp_rel_relocs (bfd *abfd,
unsigned long rel_offset,
unsigned long rel_size,
Elf_Internal_Rela **relsp,
@@ -755,7 +756,7 @@ slurp_rel_relocs (FILE *file,
{
Elf32_External_Rel *erels;
- erels = get_data (NULL, file, rel_offset, rel_size, _("relocs"));
+ erels = get_data (NULL, abfd, rel_offset, rel_size, _("relocs"));
if (!erels)
return 0;
@@ -782,7 +783,7 @@ slurp_rel_relocs (FILE *file,
{
Elf64_External_Rel *erels;
- erels = get_data (NULL, file, rel_offset, rel_size, _("relocs"));
+ erels = get_data (NULL, abfd, rel_offset, rel_size, _("relocs"));
if (!erels)
return 0;
@@ -814,7 +815,7 @@ slurp_rel_relocs (FILE *file,
offset. */
static int
-dump_relocations (FILE *file,
+dump_relocations (bfd *abfd,
unsigned long rel_offset,
unsigned long rel_size,
Elf_Internal_Sym *symtab,
@@ -831,12 +832,14 @@ dump_relocations (FILE *file,
if (is_rela)
{
- if (!slurp_rela_relocs (file, rel_offset, rel_size, &rels, &rel_size))
+ if (!slurp_rela_relocs (abfd, rel_offset, rel_size, &rels,
+ &rel_size))
return 0;
}
else
{
- if (!slurp_rel_relocs (file, rel_offset, rel_size, &rels, &rel_size))
+ if (!slurp_rel_relocs (abfd, rel_offset, rel_size, &rels,
+ &rel_size))
return 0;
}
@@ -2821,14 +2824,15 @@ process_file_header (void)
static int
-get_32bit_program_headers (FILE *file, Elf_Internal_Phdr *program_headers)
+get_32bit_program_headers (bfd *abfd,
+ Elf_Internal_Phdr *program_headers)
{
Elf32_External_Phdr *phdrs;
Elf32_External_Phdr *external;
Elf_Internal_Phdr *internal;
unsigned int i;
- phdrs = get_data (NULL, file, elf_header.e_phoff,
+ phdrs = get_data (NULL, abfd, elf_header.e_phoff,
elf_header.e_phentsize * elf_header.e_phnum,
_("program headers"));
if (!phdrs)
@@ -2854,14 +2858,15 @@ get_32bit_program_headers (FILE *file, E
}
static int
-get_64bit_program_headers (FILE *file, Elf_Internal_Phdr *program_headers)
+get_64bit_program_headers (bfd *abfd,
+ Elf_Internal_Phdr *program_headers)
{
Elf64_External_Phdr *phdrs;
Elf64_External_Phdr *external;
Elf_Internal_Phdr *internal;
unsigned int i;
- phdrs = get_data (NULL, file, elf_header.e_phoff,
+ phdrs = get_data (NULL, abfd, elf_header.e_phoff,
elf_header.e_phentsize * elf_header.e_phnum,
_("program headers"));
if (!phdrs)
@@ -2889,7 +2894,7 @@ get_64bit_program_headers (FILE *file, E
/* Returns 1 if the program headers were read into `program_headers'. */
static int
-get_program_headers (FILE *file)
+get_program_headers (bfd *abfd)
{
Elf_Internal_Phdr *phdrs;
@@ -2906,8 +2911,8 @@ get_program_headers (FILE *file)
}
if (is_32bit_elf
- ? get_32bit_program_headers (file, phdrs)
- : get_64bit_program_headers (file, phdrs))
+ ? get_32bit_program_headers (abfd, phdrs)
+ : get_64bit_program_headers (abfd, phdrs))
{
program_headers = phdrs;
return 1;
@@ -2920,7 +2925,7 @@ get_program_headers (FILE *file)
/* Returns 1 if the program headers were loaded. */
static int
-process_program_headers (FILE *file)
+process_program_headers (bfd *abfd)
{
Elf_Internal_Phdr *segment;
unsigned int i;
@@ -2943,7 +2948,7 @@ process_program_headers (FILE *file)
printf ("\n");
}
- if (! get_program_headers (file))
+ if (! get_program_headers (abfd))
return 0;
if (do_segments)
@@ -3064,12 +3069,13 @@ process_program_headers (FILE *file)
break;
case PT_INTERP:
- if (fseek (file, (long) segment->p_offset, SEEK_SET))
+ if (bfd_seek (abfd, segment->p_offset, SEEK_SET))
error (_("Unable to find program interpreter name\n"));
else
{
program_interpreter[0] = 0;
- fscanf (file, "%63s", program_interpreter);
+ bfd_bread (program_interpreter,
+ sizeof (program_interpreter), abfd);
if (do_segments)
printf (_("\n [Requesting program interpreter: %s]"),
@@ -3125,11 +3131,11 @@ 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 (bfd *abfd, bfd_vma vma, bfd_size_type size)
{
Elf_Internal_Phdr *seg;
- if (! get_program_headers (file))
+ if (! get_program_headers (abfd))
{
warn (_("Cannot interpret virtual addresses without program headers.\n"));
return (long) vma;
@@ -3154,13 +3160,13 @@ offset_from_vma (FILE *file, bfd_vma vma
static int
-get_32bit_section_headers (FILE *file, unsigned int num)
+get_32bit_section_headers (bfd *abfd, unsigned int num)
{
Elf32_External_Shdr *shdrs;
Elf_Internal_Shdr *internal;
unsigned int i;
- shdrs = get_data (NULL, file, elf_header.e_shoff,
+ shdrs = get_data (NULL, abfd, elf_header.e_shoff,
elf_header.e_shentsize * num, _("section headers"));
if (!shdrs)
return 0;
@@ -3195,13 +3201,13 @@ get_32bit_section_headers (FILE *file, u
}
static int
-get_64bit_section_headers (FILE *file, unsigned int num)
+get_64bit_section_headers (bfd *abfd, unsigned int num)
{
Elf64_External_Shdr *shdrs;
Elf_Internal_Shdr *internal;
unsigned int i;
- shdrs = get_data (NULL, file, elf_header.e_shoff,
+ shdrs = get_data (NULL, abfd, elf_header.e_shoff,
elf_header.e_shentsize * num, _("section headers"));
if (!shdrs)
return 0;
@@ -3236,7 +3242,7 @@ get_64bit_section_headers (FILE *file, u
}
static Elf_Internal_Sym *
-get_32bit_elf_symbols (FILE *file, Elf_Internal_Shdr *section)
+get_32bit_elf_symbols (bfd *abfd, Elf_Internal_Shdr *section)
{
unsigned long number;
Elf32_External_Sym *esyms;
@@ -3245,7 +3251,7 @@ get_32bit_elf_symbols (FILE *file, Elf_I
Elf_Internal_Sym *psym;
unsigned int j;
- esyms = get_data (NULL, file, section->sh_offset, section->sh_size,
+ esyms = get_data (NULL, abfd, section->sh_offset, section->sh_size,
_("symbols"));
if (!esyms)
return NULL;
@@ -3255,7 +3261,7 @@ get_32bit_elf_symbols (FILE *file, Elf_I
&& (symtab_shndx_hdr->sh_link
== (unsigned long) SECTION_HEADER_NUM (section - section_headers)))
{
- shndx = get_data (NULL, file, symtab_shndx_hdr->sh_offset,
+ shndx = get_data (NULL, abfd, symtab_shndx_hdr->sh_offset,
symtab_shndx_hdr->sh_size, _("symtab shndx"));
if (!shndx)
{
@@ -3299,7 +3305,7 @@ get_32bit_elf_symbols (FILE *file, Elf_I
}
static Elf_Internal_Sym *
-get_64bit_elf_symbols (FILE *file, Elf_Internal_Shdr *section)
+get_64bit_elf_symbols (bfd *abfd, Elf_Internal_Shdr *section)
{
unsigned long number;
Elf64_External_Sym *esyms;
@@ -3308,7 +3314,7 @@ get_64bit_elf_symbols (FILE *file, Elf_I
Elf_Internal_Sym *psym;
unsigned int j;
- esyms = get_data (NULL, file, section->sh_offset, section->sh_size,
+ esyms = get_data (NULL, abfd, section->sh_offset, section->sh_size,
_("symbols"));
if (!esyms)
return NULL;
@@ -3318,7 +3324,7 @@ get_64bit_elf_symbols (FILE *file, Elf_I
&& (symtab_shndx_hdr->sh_link
== (unsigned long) SECTION_HEADER_NUM (section - section_headers)))
{
- shndx = get_data (NULL, file, symtab_shndx_hdr->sh_offset,
+ shndx = get_data (NULL, abfd, symtab_shndx_hdr->sh_offset,
symtab_shndx_hdr->sh_size, _("symtab shndx"));
if (!shndx)
{
@@ -3409,7 +3415,7 @@ get_elf_section_flags (bfd_vma sh_flags)
}
static int
-process_section_headers (FILE *file)
+process_section_headers (bfd *abfd)
{
Elf_Internal_Shdr *section;
unsigned int i;
@@ -3430,10 +3436,10 @@ process_section_headers (FILE *file)
if (is_32bit_elf)
{
- if (! get_32bit_section_headers (file, elf_header.e_shnum))
+ if (! get_32bit_section_headers (abfd, elf_header.e_shnum))
return 0;
}
- else if (! get_64bit_section_headers (file, elf_header.e_shnum))
+ else if (! get_64bit_section_headers (abfd, elf_header.e_shnum))
return 0;
/* Read in the string table, so that we have names to display. */
@@ -3441,7 +3447,7 @@ process_section_headers (FILE *file)
if (section->sh_size != 0)
{
- string_table = get_data (NULL, file, section->sh_offset,
+ string_table = get_data (NULL, abfd, section->sh_offset,
section->sh_size, _("string table"));
if (string_table == NULL)
@@ -3472,7 +3478,7 @@ process_section_headers (FILE *file)
}
num_dynamic_syms = section->sh_size / section->sh_entsize;
- dynamic_symbols = GET_ELF_SYMBOLS (file, section);
+ dynamic_symbols = GET_ELF_SYMBOLS (abfd, section);
}
else if (section->sh_type == SHT_STRTAB
&& strcmp (name, ".dynstr") == 0)
@@ -3483,7 +3489,7 @@ process_section_headers (FILE *file)
continue;
}
- dynamic_strings = get_data (NULL, file, section->sh_offset,
+ dynamic_strings = get_data (NULL, abfd, section->sh_offset,
section->sh_size, _("dynamic strings"));
}
else if (section->sh_type == SHT_SYMTAB_SHNDX)
@@ -3659,7 +3665,7 @@ struct
/* Process the reloc section. */
static int
-process_relocs (FILE *file)
+process_relocs (bfd *abfd)
{
unsigned long rel_size;
unsigned long rel_offset;
@@ -3706,8 +3712,9 @@ process_relocs (FILE *file)
(_("\n'%s' relocation section at offset 0x%lx contains %ld bytes:\n"),
name, rel_offset, rel_size);
- dump_relocations (file,
- offset_from_vma (file, rel_offset, rel_size),
+ dump_relocations (abfd,
+ offset_from_vma (abfd, rel_offset,
+ rel_size),
rel_size,
dynamic_symbols, num_dynamic_syms,
dynamic_strings, is_rela);
@@ -3761,19 +3768,19 @@ process_relocs (FILE *file)
symsec = SECTION_HEADER (section->sh_link);
nsyms = symsec->sh_size / symsec->sh_entsize;
- symtab = GET_ELF_SYMBOLS (file, symsec);
+ symtab = GET_ELF_SYMBOLS (abfd, symsec);
if (symtab == NULL)
continue;
strsec = SECTION_HEADER (symsec->sh_link);
- strtab = get_data (NULL, file, strsec->sh_offset,
+ strtab = get_data (NULL, abfd, strsec->sh_offset,
strsec->sh_size, _("string table"));
}
is_rela = section->sh_type == SHT_RELA;
- dump_relocations (file, rel_offset, rel_size,
+ dump_relocations (abfd, rel_offset, rel_size,
symtab, nsyms, strtab, is_rela);
if (strtab)
@@ -3918,7 +3925,7 @@ dump_ia64_unwind (struct unw_aux_info *a
}
static int
-slurp_ia64_unwind_table (FILE *file,
+slurp_ia64_unwind_table (bfd *abfd,
struct unw_aux_info *aux,
Elf_Internal_Shdr *sec)
{
@@ -3938,7 +3945,7 @@ slurp_ia64_unwind_table (FILE *file,
if (elf_header.e_phnum)
{
- if (! get_program_headers (file))
+ if (! get_program_headers (abfd))
return 0;
for (seg = program_headers;
@@ -3959,7 +3966,8 @@ slurp_ia64_unwind_table (FILE *file,
/* Second, build the unwind table from the contents of the unwind section: */
size = sec->sh_size;
- table = get_data (NULL, file, sec->sh_offset, size, _("unwind table"));
+ table = get_data (NULL, abfd, sec->sh_offset, size,
+ _("unwind table"));
if (!table)
return 0;
@@ -3997,7 +4005,7 @@ slurp_ia64_unwind_table (FILE *file,
|| SECTION_HEADER (relsec->sh_info) != sec)
continue;
- if (!slurp_rela_relocs (file, relsec->sh_offset, relsec->sh_size,
+ if (!slurp_rela_relocs (abfd, relsec->sh_offset, relsec->sh_size,
& rela, & nrelas))
return 0;
@@ -4063,7 +4071,7 @@ slurp_ia64_unwind_table (FILE *file,
}
static int
-process_unwind (FILE *file)
+process_unwind (bfd *abfd)
{
Elf_Internal_Shdr *sec, *unwsec = NULL, *strsec;
unsigned long i, addr_size, unwcount = 0, unwstart = 0;
@@ -4087,11 +4095,11 @@ process_unwind (FILE *file)
if (sec->sh_type == SHT_SYMTAB)
{
aux.nsyms = sec->sh_size / sec->sh_entsize;
- aux.symtab = GET_ELF_SYMBOLS (file, sec);
+ aux.symtab = GET_ELF_SYMBOLS (abfd, sec);
strsec = SECTION_HEADER (sec->sh_link);
aux.strtab_size = strsec->sh_size;
- aux.strtab = get_data (NULL, file, strsec->sh_offset,
+ aux.strtab = get_data (NULL, abfd, strsec->sh_offset,
aux.strtab_size, _("string table"));
}
else if (sec->sh_type == SHT_IA_64_UNWIND)
@@ -4161,8 +4169,8 @@ process_unwind (FILE *file)
{
aux.info_size = sec->sh_size;
aux.info_addr = sec->sh_addr;
- aux.info = get_data (NULL, file, sec->sh_offset, aux.info_size,
- _("unwind info"));
+ aux.info = get_data (NULL, abfd, sec->sh_offset,
+ aux.info_size, _("unwind info"));
printf (_("\nUnwind section "));
@@ -4175,7 +4183,7 @@ process_unwind (FILE *file)
(unsigned long) unwsec->sh_offset,
(unsigned long) (unwsec->sh_size / (3 * addr_size)));
- (void) slurp_ia64_unwind_table (file, & aux, unwsec);
+ (void) slurp_ia64_unwind_table (abfd, & aux, unwsec);
if (aux.table_len > 0)
dump_ia64_unwind (& aux);
@@ -4347,13 +4355,13 @@ dynamic_segment_ia64_val (Elf_Internal_D
}
static int
-get_32bit_dynamic_segment (FILE *file)
+get_32bit_dynamic_segment (bfd *abfd)
{
Elf32_External_Dyn *edyn;
Elf_Internal_Dyn *entry;
bfd_size_type i;
- edyn = get_data (NULL, file, dynamic_addr, dynamic_size,
+ edyn = get_data (NULL, abfd, dynamic_addr, dynamic_size,
_("dynamic segment"));
if (!edyn)
return 0;
@@ -4388,13 +4396,13 @@ get_32bit_dynamic_segment (FILE *file)
}
static int
-get_64bit_dynamic_segment (FILE *file)
+get_64bit_dynamic_segment (bfd *abfd)
{
Elf64_External_Dyn *edyn;
Elf_Internal_Dyn *entry;
bfd_size_type i;
- edyn = get_data (NULL, file, dynamic_addr, dynamic_size,
+ edyn = get_data (NULL, abfd, dynamic_addr, dynamic_size,
_("dynamic segment"));
if (!edyn)
return 0;
@@ -4462,7 +4470,7 @@ get_dynamic_flags (bfd_vma flags)
/* Parse and display the contents of the dynamic segment. */
static int
-process_dynamic_segment (FILE *file)
+process_dynamic_segment (bfd *abfd)
{
Elf_Internal_Dyn *entry;
bfd_size_type i;
@@ -4477,10 +4485,10 @@ process_dynamic_segment (FILE *file)
if (is_32bit_elf)
{
- if (! get_32bit_dynamic_segment (file))
+ if (! get_32bit_dynamic_segment (abfd))
return 0;
}
- else if (! get_64bit_dynamic_segment (file))
+ else if (! get_64bit_dynamic_segment (abfd))
return 0;
/* Find the appropriate symbol table. */
@@ -4501,12 +4509,13 @@ process_dynamic_segment (FILE *file)
we default to reading in the entire file (!) and
processing that. This is overkill, I know, but it
should work. */
- section.sh_offset = offset_from_vma (file, entry->d_un.d_val, 0);
+ section.sh_offset = offset_from_vma (abfd,
+ entry->d_un.d_val, 0);
- if (fseek (file, 0, SEEK_END))
+ if (bfd_seek (abfd, 0, SEEK_END))
error (_("Unable to seek to end of file!"));
- section.sh_size = ftell (file) - section.sh_offset;
+ section.sh_size = bfd_tell (abfd) - section.sh_offset;
if (is_32bit_elf)
section.sh_entsize = sizeof (Elf32_External_Sym);
else
@@ -4519,7 +4528,7 @@ process_dynamic_segment (FILE *file)
continue;
}
- dynamic_symbols = GET_ELF_SYMBOLS (file, §ion);
+ dynamic_symbols = GET_ELF_SYMBOLS (abfd, §ion);
}
}
@@ -4543,10 +4552,10 @@ process_dynamic_segment (FILE *file)
processing that. This is overkill, I know, but it
should work. */
- offset = offset_from_vma (file, entry->d_un.d_val, 0);
- if (fseek (file, 0, SEEK_END))
+ offset = offset_from_vma (abfd, entry->d_un.d_val, 0);
+ if (bfd_seek (abfd, 0, SEEK_END))
error (_("Unable to seek to end of file\n"));
- str_tab_len = ftell (file) - offset;
+ str_tab_len = bfd_tell (abfd) - offset;
if (str_tab_len < 1)
{
@@ -4555,7 +4564,7 @@ process_dynamic_segment (FILE *file)
continue;
}
- dynamic_strings = get_data (NULL, file, offset, str_tab_len,
+ dynamic_strings = get_data (NULL, abfd, offset, str_tab_len,
_("dynamic string table"));
break;
}
@@ -4579,7 +4588,8 @@ process_dynamic_segment (FILE *file)
else if (entry->d_tag == DT_SYMINSZ)
syminsz = entry->d_un.d_val;
else if (entry->d_tag == DT_SYMINFO)
- dynamic_syminfo_offset = offset_from_vma (file, entry->d_un.d_val,
+ dynamic_syminfo_offset = offset_from_vma (abfd,
+ entry->d_un.d_val,
syminsz);
}
@@ -4589,8 +4599,8 @@ process_dynamic_segment (FILE *file)
Elf_Internal_Syminfo *syminfo;
/* There is a syminfo section. Read the data. */
- extsyminfo = get_data (NULL, file, dynamic_syminfo_offset, syminsz,
- _("symbol information"));
+ extsyminfo = get_data (NULL, abfd, dynamic_syminfo_offset,
+ syminsz, _("symbol information"));
if (!extsyminfo)
return 0;
@@ -5035,7 +5045,7 @@ get_ver_flags (unsigned int flags)
/* Display the contents of the version sections. */
static int
-process_version_sections (FILE *file)
+process_version_sections (bfd *abfd)
{
Elf_Internal_Shdr *section;
unsigned i;
@@ -5068,7 +5078,8 @@ process_version_sections (FILE *file)
(unsigned long) section->sh_offset, section->sh_link,
SECTION_NAME (SECTION_HEADER (section->sh_link)));
- edefs = get_data (NULL, file, section->sh_offset, section->sh_size,
+ edefs = get_data (NULL, abfd, section->sh_offset,
+ section->sh_size,
_("version definition section"));
if (!edefs)
break;
@@ -5157,7 +5168,8 @@ process_version_sections (FILE *file)
(unsigned long) section->sh_offset, section->sh_link,
SECTION_NAME (SECTION_HEADER (section->sh_link)));
- eneed = get_data (NULL, file, section->sh_offset, section->sh_size,
+ eneed = get_data (NULL, abfd, section->sh_offset,
+ section->sh_size,
_("version need section"));
if (!eneed)
break;
@@ -5242,11 +5254,11 @@ process_version_sections (FILE *file)
found = 1;
- symbols = GET_ELF_SYMBOLS (file, link_section);
+ symbols = GET_ELF_SYMBOLS (abfd, link_section);
string_sec = SECTION_HEADER (link_section->sh_link);
- strtab = get_data (NULL, file, string_sec->sh_offset,
+ strtab = get_data (NULL, abfd, string_sec->sh_offset,
string_sec->sh_size, _("version string table"));
if (!strtab)
break;
@@ -5260,10 +5272,10 @@ process_version_sections (FILE *file)
(unsigned long) section->sh_offset, section->sh_link,
SECTION_NAME (link_section));
- off = offset_from_vma (file,
+ off = offset_from_vma (abfd,
version_info[DT_VERSIONTAGIDX (DT_VERSYM)],
total * sizeof (short));
- edata = get_data (NULL, file, off, total * sizeof (short),
+ edata = get_data (NULL, abfd, off, total * sizeof (short),
_("version symbol data"));
if (!edata)
{
@@ -5320,7 +5332,7 @@ process_version_sections (FILE *file)
unsigned long offset;
offset = offset_from_vma
- (file, version_info[DT_VERSIONTAGIDX (DT_VERNEED)],
+ (abfd, version_info[DT_VERSIONTAGIDX (DT_VERNEED)],
sizeof (Elf_External_Verneed));
do
@@ -5330,7 +5342,8 @@ process_version_sections (FILE *file)
Elf_External_Vernaux evna;
unsigned long a_off;
- get_data (&evn, file, offset, sizeof (evn),
+ get_data (&evn, abfd, offset,
+ sizeof (evn),
_("version need"));
ivn.vn_aux = BYTE_GET (evn.vn_aux);
@@ -5340,7 +5353,8 @@ process_version_sections (FILE *file)
do
{
- get_data (&evna, file, a_off, sizeof (evna),
+ get_data (&evna, abfd, a_off,
+ sizeof (evna),
_("version need aux (2)"));
ivna.vna_next = BYTE_GET (evna.vna_next);
@@ -5377,12 +5391,13 @@ process_version_sections (FILE *file)
unsigned long offset;
offset = offset_from_vma
- (file, version_info[DT_VERSIONTAGIDX (DT_VERDEF)],
+ (abfd, version_info[DT_VERSIONTAGIDX (DT_VERDEF)],
sizeof evd);
do
{
- get_data (&evd, file, offset, sizeof (evd),
+ get_data (&evd, abfd, offset,
+ sizeof (evd),
_("version def"));
ivd.vd_next = BYTE_GET (evd.vd_next);
@@ -5400,9 +5415,10 @@ process_version_sections (FILE *file)
ivd.vd_aux = BYTE_GET (evd.vd_aux);
- get_data (&evda, file,
+ get_data (&evda, abfd,
offset - ivd.vd_next + ivd.vd_aux,
- sizeof (evda), _("version def aux"));
+ sizeof (evda),
+ _("version def aux"));
ivda.vda_name = BYTE_GET (evda.vda_name);
@@ -5544,7 +5560,7 @@ get_symbol_index_type (unsigned int type
}
static int *
-get_dynamic_data (FILE *file, unsigned int number)
+get_dynamic_data (bfd *abfd, unsigned int number)
{
unsigned char *e_data;
int *i_data;
@@ -5557,7 +5573,7 @@ get_dynamic_data (FILE *file, unsigned i
return NULL;
}
- if (fread (e_data, 4, number, file) != number)
+ if (bfd_bread (e_data, 4 * number, abfd) != 4 * number)
{
error (_("Unable to read in dynamic data\n"));
return NULL;
@@ -5582,7 +5598,7 @@ get_dynamic_data (FILE *file, unsigned i
/* Dump the symbol table. */
static int
-process_symbol_table (FILE *file)
+process_symbol_table (bfd *abfd)
{
Elf_Internal_Shdr *section;
unsigned char nb[4];
@@ -5598,21 +5614,22 @@ process_symbol_table (FILE *file)
if (dynamic_info[DT_HASH] && ((do_using_dynamic && dynamic_strings != NULL)
|| do_histogram))
{
- if (fseek (file, offset_from_vma (file, dynamic_info[DT_HASH],
- sizeof nb + sizeof nc),
- SEEK_SET))
+ if (bfd_seek (abfd,
+ offset_from_vma (abfd, dynamic_info[DT_HASH],
+ sizeof nb + sizeof nc),
+ SEEK_SET))
{
error (_("Unable to seek to start of dynamic information"));
return 0;
}
- if (fread (nb, sizeof (nb), 1, file) != 1)
+ if (bfd_bread (nb, sizeof (nb), abfd) != sizeof (nb))
{
error (_("Failed to read in number of buckets\n"));
return 0;
}
- if (fread (nc, sizeof (nc), 1, file) != 1)
+ if (bfd_bread (nc, sizeof (nc), abfd) != sizeof (nb))
{
error (_("Failed to read in number of chains\n"));
return 0;
@@ -5621,8 +5638,8 @@ process_symbol_table (FILE *file)
nbuckets = byte_get (nb, 4);
nchains = byte_get (nc, 4);
- buckets = get_dynamic_data (file, nbuckets);
- chains = get_dynamic_data (file, nchains);
+ buckets = get_dynamic_data (abfd, nbuckets);
+ chains = get_dynamic_data (abfd, nchains);
if (buckets == NULL || chains == NULL)
return 0;
@@ -5691,7 +5708,7 @@ process_symbol_table (FILE *file)
else
printf (_(" Num: Value Size Type Bind Vis Ndx Name\n"));
- symtab = GET_ELF_SYMBOLS (file, section);
+ symtab = GET_ELF_SYMBOLS (abfd, section);
if (symtab == NULL)
continue;
@@ -5703,8 +5720,9 @@ process_symbol_table (FILE *file)
string_sec = SECTION_HEADER (section->sh_link);
- strtab = get_data (NULL, file, string_sec->sh_offset,
- string_sec->sh_size, _("string table"));
+ strtab = get_data (NULL, abfd, string_sec->sh_offset,
+ string_sec->sh_size,
+ _("string table"));
}
for (si = 0, psym = symtab;
@@ -5731,10 +5749,10 @@ process_symbol_table (FILE *file)
int check_def;
offset = offset_from_vma
- (file, version_info[DT_VERSIONTAGIDX (DT_VERSYM)],
+ (abfd, version_info[DT_VERSIONTAGIDX (DT_VERSYM)],
sizeof data + si * sizeof (vers_data));
- get_data (&data, file, offset + si * sizeof (vers_data),
+ get_data (&data, abfd, offset + si * sizeof (vers_data),
sizeof (data), _("version data"));
vers_data = byte_get (data, 2);
@@ -5755,14 +5773,15 @@ process_symbol_table (FILE *file)
/* We must test both. */
offset = offset_from_vma
- (file, version_info[DT_VERSIONTAGIDX (DT_VERNEED)],
+ (abfd, version_info[DT_VERSIONTAGIDX (DT_VERNEED)],
sizeof evn);
do
{
unsigned long vna_off;
- get_data (&evn, file, offset, sizeof (evn),
+ get_data (&evn, abfd, offset,
+ sizeof (evn),
_("version need"));
ivn.vn_aux = BYTE_GET (evn.vn_aux);
@@ -5774,7 +5793,7 @@ process_symbol_table (FILE *file)
{
Elf_External_Vernaux evna;
- get_data (&evna, file, vna_off,
+ get_data (&evna, abfd, vna_off,
sizeof (evna),
_("version need aux (3)"));
@@ -5817,7 +5836,7 @@ process_symbol_table (FILE *file)
unsigned long offset;
offset = offset_from_vma
- (file,
+ (abfd,
version_info[DT_VERSIONTAGIDX (DT_VERDEF)],
sizeof (Elf_External_Verdef));
@@ -5825,7 +5844,7 @@ process_symbol_table (FILE *file)
{
Elf_External_Verdef evd;
- get_data (&evd, file, offset, sizeof (evd),
+ get_data (&evd, abfd, offset, sizeof (evd),
_("version def"));
ivd.vd_ndx = BYTE_GET (evd.vd_ndx);
@@ -5840,7 +5859,8 @@ process_symbol_table (FILE *file)
offset -= ivd.vd_next;
offset += ivd.vd_aux;
- get_data (&evda, file, offset, sizeof (evda),
+ get_data (&evda, abfd, offset,
+ sizeof (evda),
_("version def aux"));
ivda.vda_name = BYTE_GET (evda.vda_name);
@@ -5936,7 +5956,7 @@ process_symbol_table (FILE *file)
}
static int
-process_syminfo (FILE *file ATTRIBUTE_UNUSED)
+process_syminfo (bfd *abfd ATTRIBUTE_UNUSED)
{
unsigned int i;
@@ -6002,7 +6022,7 @@ process_syminfo (FILE *file ATTRIBUTE_UN
#ifdef SUPPORT_DISASSEMBLY
static void
-disassemble_section (Elf_Internal_Shdr *section, FILE *file)
+disassemble_section (Elf_Internal_Shdr *section, bfd *abfd)
{
printf (_("\nAssembly dump of section %s\n"),
SECTION_NAME (section));
@@ -6014,7 +6034,7 @@ disassemble_section (Elf_Internal_Shdr *
#endif
static int
-dump_section (Elf_Internal_Shdr *section, FILE *file)
+dump_section (Elf_Internal_Shdr *section, bfd *abfd)
{
bfd_size_type bytes;
bfd_vma addr;
@@ -6034,7 +6054,8 @@ dump_section (Elf_Internal_Shdr *section
addr = section->sh_addr;
- start = get_data (NULL, file, section->sh_offset, bytes, _("section data"));
+ start = get_data (NULL, abfd, section->sh_offset, bytes,
+ _("section data"));
if (!start)
return 0;
@@ -6229,7 +6250,7 @@ static int debug_line_pointer_size = 4;
static int
display_debug_lines (Elf_Internal_Shdr *section,
unsigned char * start,
- FILE *file ATTRIBUTE_UNUSED)
+ bfd *abfd ATTRIBUTE_UNUSED)
{
unsigned char *hdrptr;
DWARF2_Internal_LineInfo info;
@@ -6503,7 +6524,7 @@ display_debug_lines (Elf_Internal_Shdr *
static int
display_debug_pubnames (Elf_Internal_Shdr *section,
unsigned char *start,
- FILE *file ATTRIBUTE_UNUSED)
+ bfd *abfd ATTRIBUTE_UNUSED)
{
DWARF2_Internal_PubNames pubnames;
unsigned char *end;
@@ -6972,7 +6993,7 @@ process_abbrev_section (unsigned char *s
static int
display_debug_macinfo (Elf_Internal_Shdr *section,
unsigned char *start,
- FILE *file ATTRIBUTE_UNUSED)
+ bfd *abfd ATTRIBUTE_UNUSED)
{
unsigned char *end = start + section->sh_size;
unsigned char *curr = start;
@@ -7045,7 +7066,7 @@ display_debug_macinfo (Elf_Internal_Shdr
static int
display_debug_abbrev (Elf_Internal_Shdr *section,
unsigned char *start,
- FILE *file ATTRIBUTE_UNUSED)
+ bfd *abfd ATTRIBUTE_UNUSED)
{
abbrev_entry *entry;
unsigned char *end = start + section->sh_size;
@@ -7435,7 +7456,7 @@ static const char *debug_loc_contents;
static bfd_vma debug_loc_size;
static void
-load_debug_loc (FILE *file)
+load_debug_loc (bfd *abfd)
{
Elf_Internal_Shdr *sec;
unsigned int i;
@@ -7456,7 +7477,8 @@ load_debug_loc (FILE *file)
debug_loc_size = sec->sh_size;
- debug_loc_contents = get_data (NULL, file, sec->sh_offset, sec->sh_size,
+ debug_loc_contents = get_data (NULL, abfd, sec->sh_offset,
+ sec->sh_size,
_("debug_loc section data"));
}
@@ -7475,7 +7497,7 @@ free_debug_loc (void)
static int
display_debug_loc (Elf_Internal_Shdr *section,
unsigned char *start,
- FILE *file ATTRIBUTE_UNUSED)
+ bfd *abfd ATTRIBUTE_UNUSED)
{
unsigned char *section_end;
unsigned long bytes;
@@ -7545,7 +7567,7 @@ static const char *debug_str_contents;
static bfd_vma debug_str_size;
static void
-load_debug_str (FILE *file)
+load_debug_str (bfd *abfd)
{
Elf_Internal_Shdr *sec;
unsigned int i;
@@ -7566,7 +7588,8 @@ load_debug_str (FILE *file)
debug_str_size = sec->sh_size;
- debug_str_contents = get_data (NULL, file, sec->sh_offset, sec->sh_size,
+ debug_str_contents = get_data (NULL, abfd, sec->sh_offset,
+ sec->sh_size,
_("debug_str section data"));
}
@@ -7596,7 +7619,7 @@ fetch_indirect_string (unsigned long off
static int
display_debug_str (Elf_Internal_Shdr *section,
unsigned char *start,
- FILE *file ATTRIBUTE_UNUSED)
+ bfd *abfd ATTRIBUTE_UNUSED)
{
unsigned long bytes;
bfd_vma addr;
@@ -8006,15 +8029,15 @@ read_and_display_attr (unsigned long att
static int
display_debug_info (Elf_Internal_Shdr *section,
unsigned char *start,
- FILE *file)
+ bfd *abfd)
{
unsigned char *end = start + section->sh_size;
unsigned char *section_begin = start;
printf (_("The section %s contains:\n\n"), SECTION_NAME (section));
- load_debug_str (file);
- load_debug_loc (file);
+ load_debug_str (abfd);
+ load_debug_loc (abfd);
while (start < end)
{
@@ -8066,12 +8089,13 @@ display_debug_info (Elf_Internal_Shdr *s
|| relsec->sh_size == 0)
continue;
- if (!slurp_rela_relocs (file, relsec->sh_offset, relsec->sh_size,
+ if (!slurp_rela_relocs (abfd, relsec->sh_offset,
+ relsec->sh_size,
& rela, & nrelas))
return 0;
symsec = SECTION_HEADER (relsec->sh_link);
- symtab = GET_ELF_SYMBOLS (file, symsec);
+ symtab = GET_ELF_SYMBOLS (abfd, symsec);
for (rp = rela; rp < rela + nrelas; ++rp)
{
@@ -8159,7 +8183,7 @@ display_debug_info (Elf_Internal_Shdr *s
return 0;
}
- begin = get_data (NULL, file, sec->sh_offset, sec->sh_size,
+ begin = get_data (NULL, abfd, sec->sh_offset, sec->sh_size,
_("debug_abbrev section data"));
if (!begin)
return 0;
@@ -8232,7 +8256,7 @@ display_debug_info (Elf_Internal_Shdr *s
static int
display_debug_aranges (Elf_Internal_Shdr *section,
unsigned char *start,
- FILE *file ATTRIBUTE_UNUSED)
+ bfd *abfd ATTRIBUTE_UNUSED)
{
unsigned char *end = start + section->sh_size;
@@ -8465,7 +8489,7 @@ get_encoded_value (unsigned char *data,
static int
display_debug_frames (Elf_Internal_Shdr *section,
unsigned char *start,
- FILE *file ATTRIBUTE_UNUSED)
+ bfd *abfd ATTRIBUTE_UNUSED)
{
unsigned char *end = start + section->sh_size;
unsigned char *section_start = start;
@@ -9109,7 +9133,7 @@ display_debug_frames (Elf_Internal_Shdr
static int
display_debug_not_supported (Elf_Internal_Shdr *section,
unsigned char *start ATTRIBUTE_UNUSED,
- FILE *file ATTRIBUTE_UNUSED)
+ bfd *abfd ATTRIBUTE_UNUSED)
{
printf (_("Displaying the debug contents of section %s is not yet supported.\n"),
SECTION_NAME (section));
@@ -9123,7 +9147,7 @@ display_debug_not_supported (Elf_Interna
static int
prescan_debug_info (Elf_Internal_Shdr *section ATTRIBUTE_UNUSED,
unsigned char *start,
- FILE *file ATTRIBUTE_UNUSED)
+ bfd *abfd ATTRIBUTE_UNUSED)
{
unsigned long length;
@@ -9170,8 +9194,8 @@ prescan_debug_info (Elf_Internal_Shdr *s
struct
{
const char *const name;
- int (*display) (Elf_Internal_Shdr *, unsigned char *, FILE *);
- int (*prescan) (Elf_Internal_Shdr *, unsigned char *, FILE *);
+ int (*display) (Elf_Internal_Shdr *, unsigned char *, bfd *);
+ int (*prescan) (Elf_Internal_Shdr *, unsigned char *, bfd *);
}
debug_displays[] =
{
@@ -9194,7 +9218,7 @@ debug_displays[] =
};
static int
-display_debug_section (Elf_Internal_Shdr *section, FILE *file)
+display_debug_section (Elf_Internal_Shdr *section, bfd *abfd)
{
char *name = SECTION_NAME (section);
bfd_size_type length;
@@ -9208,7 +9232,7 @@ display_debug_section (Elf_Internal_Shdr
return 0;
}
- start = get_data (NULL, file, section->sh_offset, length,
+ start = get_data (NULL, abfd, section->sh_offset, length,
_("debug section data"));
if (!start)
return 0;
@@ -9220,7 +9244,7 @@ display_debug_section (Elf_Internal_Shdr
for (i = NUM_ELEM (debug_displays); i--;)
if (strcmp (debug_displays[i].name, name) == 0)
{
- debug_displays[i].display (section, start, file);
+ debug_displays[i].display (section, start, abfd);
break;
}
@@ -9237,7 +9261,7 @@ display_debug_section (Elf_Internal_Shdr
}
static int
-process_section_contents (FILE *file)
+process_section_contents (bfd *abfd)
{
Elf_Internal_Shdr *section;
unsigned int i;
@@ -9268,12 +9292,13 @@ process_section_contents (FILE *file)
unsigned char *start;
length = section->sh_size;
- start = get_data (NULL, file, section->sh_offset, length,
+ start = get_data (NULL, abfd, section->sh_offset,
+ length,
_("debug section data"));
if (!start)
return 0;
- debug_displays[j].prescan (section, start, file);
+ debug_displays[j].prescan (section, start, abfd);
free (start);
}
@@ -9287,13 +9312,13 @@ process_section_contents (FILE *file)
{
#ifdef SUPPORT_DISASSEMBLY
if (dump_sects[i] & DISASS_DUMP)
- disassemble_section (section, file);
+ disassemble_section (section, abfd);
#endif
if (dump_sects[i] & HEX_DUMP)
- dump_section (section, file);
+ dump_section (section, abfd);
if (dump_sects[i] & DEBUG_DUMP)
- display_debug_section (section, file);
+ display_debug_section (section, abfd);
}
if (i < num_dump_sects)
@@ -9324,7 +9349,7 @@ process_mips_fpe_exception (int mask)
}
static int
-process_mips_specific (FILE *file)
+process_mips_specific (bfd *abfd)
{
Elf_Internal_Dyn *entry;
size_t liblist_offset = 0;
@@ -9343,18 +9368,18 @@ process_mips_specific (FILE *file)
{
case DT_MIPS_LIBLIST:
liblist_offset
- = offset_from_vma (file, entry->d_un.d_val,
+ = offset_from_vma (abfd, entry->d_un.d_val,
liblistno * sizeof (Elf32_External_Lib));
break;
case DT_MIPS_LIBLISTNO:
liblistno = entry->d_un.d_val;
break;
case DT_MIPS_OPTIONS:
- options_offset = offset_from_vma (file, entry->d_un.d_val, 0);
+ options_offset = offset_from_vma (abfd, entry->d_un.d_val, 0);
break;
case DT_MIPS_CONFLICT:
conflicts_offset
- = offset_from_vma (file, entry->d_un.d_val,
+ = offset_from_vma (abfd, entry->d_un.d_val,
conflictsno * sizeof (Elf32_External_Conflict));
break;
case DT_MIPS_CONFLICTNO:
@@ -9369,7 +9394,7 @@ process_mips_specific (FILE *file)
Elf32_External_Lib *elib;
size_t cnt;
- elib = get_data (NULL, file, liblist_offset,
+ elib = get_data (NULL, abfd, liblist_offset,
liblistno * sizeof (Elf32_External_Lib),
_("liblist"));
if (elib)
@@ -9455,7 +9480,7 @@ process_mips_specific (FILE *file)
while (sect->sh_type != SHT_MIPS_OPTIONS)
++sect;
- eopt = get_data (NULL, file, options_offset, sect->sh_size,
+ eopt = get_data (NULL, abfd, options_offset, sect->sh_size,
_("options"));
if (eopt)
{
@@ -9662,7 +9687,7 @@ process_mips_specific (FILE *file)
{
Elf32_External_Conflict *econf32;
- econf32 = get_data (NULL, file, conflicts_offset,
+ econf32 = get_data (NULL, abfd, conflicts_offset,
conflictsno * sizeof (*econf32), _("conflict"));
if (!econf32)
return 0;
@@ -9676,7 +9701,7 @@ process_mips_specific (FILE *file)
{
Elf64_External_Conflict *econf64;
- econf64 = get_data (NULL, file, conflicts_offset,
+ econf64 = get_data (NULL, abfd, conflicts_offset,
conflictsno * sizeof (*econf64), _("conflict"));
if (!econf64)
return 0;
@@ -9709,7 +9734,7 @@ process_mips_specific (FILE *file)
}
static int
-process_gnu_liblist (FILE *file)
+process_gnu_liblist (bfd *abfd)
{
Elf_Internal_Shdr *section, *string_sec;
Elf32_External_Lib *elib;
@@ -9727,15 +9752,17 @@ process_gnu_liblist (FILE *file)
switch (section->sh_type)
{
case SHT_GNU_LIBLIST:
- elib = get_data (NULL, file, section->sh_offset, section->sh_size,
+ elib = get_data (NULL, abfd, section->sh_offset,
+ section->sh_size,
_("liblist"));
if (elib == NULL)
break;
string_sec = SECTION_HEADER (section->sh_link);
- strtab = get_data (NULL, file, string_sec->sh_offset,
- string_sec->sh_size, _("liblist string table"));
+ strtab = get_data (NULL, abfd, string_sec->sh_offset,
+ string_sec->sh_size,
+ _("liblist string table"));
if (strtab == NULL
|| section->sh_entsize != sizeof (Elf32_External_Lib))
@@ -9906,7 +9933,8 @@ process_note (Elf_Internal_Note *pnote)
static int
-process_corefile_note_segment (FILE *file, bfd_vma offset, bfd_vma length)
+process_corefile_note_segment (bfd *abfd, bfd_vma offset,
+ bfd_vma length)
{
Elf_External_Note *pnotes;
Elf_External_Note *external;
@@ -9915,7 +9943,7 @@ process_corefile_note_segment (FILE *fil
if (length <= 0)
return 0;
- pnotes = get_data (NULL, file, offset, length, _("notes"));
+ pnotes = get_data (NULL, abfd, offset, length, _("notes"));
if (!pnotes)
return 0;
@@ -9988,13 +10016,13 @@ process_corefile_note_segment (FILE *fil
}
static int
-process_corefile_note_segments (FILE *file)
+process_corefile_note_segments (bfd *abfd)
{
Elf_Internal_Phdr *segment;
unsigned int i;
int res = 1;
- if (! get_program_headers (file))
+ if (! get_program_headers (abfd))
return 0;
for (i = 0, segment = program_headers;
@@ -10002,7 +10030,7 @@ process_corefile_note_segments (FILE *fi
i++, segment++)
{
if (segment->p_type == PT_NOTE)
- res &= process_corefile_note_segment (file,
+ res &= process_corefile_note_segment (abfd,
(bfd_vma) segment->p_offset,
(bfd_vma) segment->p_filesz);
}
@@ -10011,7 +10039,7 @@ process_corefile_note_segments (FILE *fi
}
static int
-process_corefile_contents (FILE *file)
+process_corefile_contents (bfd *abfd)
{
/* If we have not been asked to display the notes then do nothing. */
if (! do_notes)
@@ -10028,11 +10056,11 @@ process_corefile_contents (FILE *file)
return 1;
}
- return process_corefile_note_segments (file);
+ return process_corefile_note_segments (abfd);
}
static int
-process_arch_specific (FILE *file)
+process_arch_specific (bfd *abfd)
{
if (! do_arch)
return 1;
@@ -10041,7 +10069,7 @@ process_arch_specific (FILE *file)
{
case EM_MIPS:
case EM_MIPS_RS3_LE:
- return process_mips_specific (file);
+ return process_mips_specific (abfd);
break;
default:
break;
@@ -10050,10 +10078,10 @@ process_arch_specific (FILE *file)
}
static int
-get_file_header (FILE *file)
+get_file_header (bfd *abfd)
{
/* Read in the identity array. */
- if (fread (elf_header.e_ident, EI_NIDENT, 1, file) != 1)
+ if (bfd_bread (elf_header.e_ident, EI_NIDENT, abfd) != EI_NIDENT)
return 0;
/* Determine how to read the rest of the header. */
@@ -10079,7 +10107,8 @@ get_file_header (FILE *file)
{
Elf32_External_Ehdr ehdr32;
- if (fread (ehdr32.e_type, sizeof (ehdr32) - EI_NIDENT, 1, file) != 1)
+ if (bfd_bread (ehdr32.e_type, sizeof (ehdr32) - EI_NIDENT,
+ abfd) != sizeof (ehdr32) - EI_NIDENT)
return 0;
elf_header.e_type = BYTE_GET (ehdr32.e_type);
@@ -10111,7 +10140,8 @@ get_file_header (FILE *file)
return 0;
}
- if (fread (ehdr64.e_type, sizeof (ehdr64) - EI_NIDENT, 1, file) != 1)
+ if (bfd_bread (ehdr64.e_type, sizeof (ehdr64) - EI_NIDENT,
+ abfd) != sizeof (ehdr64) - EI_NIDENT)
return 0;
elf_header.e_type = BYTE_GET (ehdr64.e_type);
@@ -10134,38 +10164,30 @@ get_file_header (FILE *file)
/* There may be some extensions in the first section header. Don't
bomb if we can't read it. */
if (is_32bit_elf)
- get_32bit_section_headers (file, 1);
+ get_32bit_section_headers (abfd, 1);
else
- get_64bit_section_headers (file, 1);
+ get_64bit_section_headers (abfd, 1);
}
return 1;
}
static int
-process_file (char *file_name)
+process_bfd (bfd *abfd)
{
- FILE *file;
- struct stat statbuf;
unsigned int i;
+ const char *file_name = bfd_get_filename (abfd);
- if (stat (file_name, & statbuf) < 0)
+ if (bfd_seek (abfd, 0, SEEK_SET))
{
- error (_("Cannot stat input file %s.\n"), file_name);
+ error (_("%s: Unable to seek to beginning of file: %s.\n"),
+ file_name, bfd_errmsg (bfd_get_error ()));
return 1;
}
- file = fopen (file_name, "rb");
- if (file == NULL)
- {
- error (_("Input file %s not found.\n"), file_name);
- return 1;
- }
-
- if (! get_file_header (file))
+ if (! get_file_header (abfd))
{
error (_("%s: Failed to read file header\n"), file_name);
- fclose (file);
return 1;
}
@@ -10182,11 +10204,10 @@ process_file (char *file_name)
if (! process_file_header ())
{
- fclose (file);
return 1;
}
- if (! process_section_headers (file))
+ if (! process_section_headers (abfd))
{
/* Without loaded section headers we
cannot process lots of things. */
@@ -10196,28 +10217,26 @@ process_file (char *file_name)
do_syms = do_reloc = 0;
}
- if (process_program_headers (file))
- process_dynamic_segment (file);
+ if (process_program_headers (abfd))
+ process_dynamic_segment (abfd);
- process_relocs (file);
+ process_relocs (abfd);
- process_unwind (file);
+ process_unwind (abfd);
- process_symbol_table (file);
+ process_symbol_table (abfd);
- process_syminfo (file);
+ process_syminfo (abfd);
- process_version_sections (file);
+ process_version_sections (abfd);
- process_section_contents (file);
+ process_section_contents (abfd);
- process_corefile_contents (file);
+ process_corefile_contents (abfd);
- process_gnu_liblist (file);
+ process_gnu_liblist (abfd);
- process_arch_specific (file);
-
- fclose (file);
+ process_arch_specific (abfd);
if (program_headers)
{
@@ -10260,6 +10279,67 @@ process_file (char *file_name)
return 0;
}
+static int
+process_file (char *file_name)
+{
+ bfd *abfd, *arbfd = NULL;
+ struct stat statbuf;
+
+ if (stat (file_name, & statbuf) < 0)
+ {
+ error (_("Cannot stat input file %s.\n"), file_name);
+ return 1;
+ }
+
+ abfd = bfd_openr (file_name, NULL);
+ if (abfd == NULL)
+ {
+ error (_("Input file %s not found: %s.\n"), file_name,
+ bfd_errmsg (bfd_get_error ()));
+ return 1;
+ }
+
+ if (bfd_check_format (abfd, bfd_archive))
+ {
+ bfd *last_arbfd = NULL;
+
+ show_name = 1;
+ printf (_("In archive %s:\n"), bfd_get_filename (abfd));
+ for (;;)
+ {
+ bfd_set_error (bfd_error_no_error);
+
+ arbfd = bfd_openr_next_archived_file (abfd, arbfd);
+ if (arbfd == NULL)
+ {
+ if (bfd_get_error () != bfd_error_no_more_archived_files)
+ error (_("Fail to extract member from archive %s: %s.\n"),
+ bfd_get_filename (abfd),
+ bfd_errmsg (bfd_get_error ()));
+ break;
+ }
+
+ if (process_bfd (arbfd))
+ {
+ bfd_close (arbfd);
+ break;
+ }
+
+ if (last_arbfd != NULL)
+ bfd_close (last_arbfd);
+ last_arbfd = arbfd;
+ }
+
+ if (last_arbfd != NULL)
+ bfd_close (last_arbfd);
+ }
+ else
+ process_bfd (abfd);
+
+ bfd_close (abfd);
+ return 0;
+}
+
#ifdef SUPPORT_DISASSEMBLY
/* Needed by the i386 disassembler. For extra credit, someone could
fix this so that we insert symbolic addresses here, esp for GOT/PLT
@@ -10295,6 +10375,14 @@ main (int argc, char **argv)
bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE);
+ bfd_init ();
+ if (! bfd_set_default_target (TARGET))
+ {
+ error (_("can't set BFD default target to `%s': %s"),
+ TARGET, bfd_errmsg (bfd_get_error ()));
+ return 1;
+ }
+
parse_args (argc, argv);
if (optind < (argc - 1))
More information about the Binutils
mailing list