| /* readelf.c -- display contents of an ELF format file |
| Copyright 1998, 1999, 2000, 2001 Free Software Foundation, Inc. |
| |
| Originally developed by Eric Youngdale <eric@andante.jic.com> |
| Modifications by Nick Clifton <nickc@redhat.com> |
| |
| This file is part of GNU Binutils. |
| |
| This program is free software; you can redistribute it and/or modify |
| it under the terms of the GNU General Public License as published by |
| the Free Software Foundation; either version 2 of the License, or |
| (at your option) any later version. |
| |
| This program is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| GNU General Public License for more details. |
| |
| You should have received a copy of the GNU General Public License |
| along with this program; if not, write to the Free Software |
| Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA |
| 02111-1307, USA. */ |
| |
| |
| #include <assert.h> |
| #include <sys/types.h> |
| #include <sys/stat.h> |
| #include <stdio.h> |
| #include <time.h> |
| |
| #if __GNUC__ >= 2 |
| /* Define BFD64 here, even if our default architecture is 32 bit ELF |
| as this will allow us to read in and parse 64bit and 32bit ELF files. |
| Only do this if we belive that the compiler can support a 64 bit |
| data type. For now we only rely on GCC being able to do this. */ |
| #define BFD64 |
| #endif |
| |
| #include "bfd.h" |
| |
| #include "elf/common.h" |
| #include "elf/external.h" |
| #include "elf/internal.h" |
| #include "elf/dwarf2.h" |
| |
| /* The following headers use the elf/reloc-macros.h file to |
| automatically generate relocation recognition functions |
| such as elf_mips_reloc_type() */ |
| |
| #define RELOC_MACROS_GEN_FUNC |
| |
| #include "elf/i386.h" |
| #include "elf/v850.h" |
| #include "elf/ppc.h" |
| #include "elf/mips.h" |
| #include "elf/alpha.h" |
| #include "elf/arm.h" |
| #include "elf/m68k.h" |
| #include "elf/sparc.h" |
| #include "elf/m32r.h" |
| #include "elf/d10v.h" |
| #include "elf/d30v.h" |
| #include "elf/sh.h" |
| #include "elf/mn10200.h" |
| #include "elf/mn10300.h" |
| #include "elf/hppa.h" |
| #include "elf/arc.h" |
| #include "elf/fr30.h" |
| #include "elf/mcore.h" |
| #include "elf/i960.h" |
| #include "elf/pj.h" |
| #include "elf/avr.h" |
| #include "elf/ia64.h" |
| #include "elf/cris.h" |
| #include "elf/i860.h" |
| #include "elf/x86-64.h" |
| |
| #include "bucomm.h" |
| #include "getopt.h" |
| |
| char * program_name = "readelf"; |
| unsigned int dynamic_addr; |
| bfd_size_type dynamic_size; |
| unsigned int rela_addr; |
| unsigned int rela_size; |
| char * dynamic_strings; |
| char * string_table; |
| unsigned long string_table_length; |
| unsigned long num_dynamic_syms; |
| Elf_Internal_Sym * dynamic_symbols; |
| Elf_Internal_Syminfo * dynamic_syminfo; |
| unsigned long dynamic_syminfo_offset; |
| unsigned int dynamic_syminfo_nent; |
| char program_interpreter [64]; |
| int dynamic_info[DT_JMPREL + 1]; |
| int version_info[16]; |
| int loadaddr = 0; |
| Elf_Internal_Ehdr elf_header; |
| Elf_Internal_Shdr * section_headers; |
| Elf_Internal_Dyn * dynamic_segment; |
| int show_name; |
| int do_dynamic; |
| int do_syms; |
| int do_reloc; |
| int do_sections; |
| int do_segments; |
| int do_unwind; |
| int do_using_dynamic; |
| int do_header; |
| int do_dump; |
| int do_version; |
| int do_histogram; |
| int do_debugging; |
| int do_debug_info; |
| int do_debug_abbrevs; |
| int do_debug_lines; |
| int do_debug_pubnames; |
| int do_debug_aranges; |
| int do_debug_frames; |
| int do_debug_frames_interp; |
| int do_arch; |
| int do_notes; |
| int is_32bit_elf; |
| |
| /* A dynamic array of flags indicating which sections require dumping. */ |
| char * dump_sects = NULL; |
| unsigned int num_dump_sects = 0; |
| |
| #define HEX_DUMP (1 << 0) |
| #define DISASS_DUMP (1 << 1) |
| #define DEBUG_DUMP (1 << 2) |
| |
| /* How to rpint a vma value. */ |
| typedef enum print_mode |
| { |
| HEX, |
| DEC, |
| DEC_5, |
| UNSIGNED, |
| PREFIX_HEX, |
| FULL_HEX, |
| LONG_HEX |
| } |
| print_mode; |
| |
| /* Forward declarations for dumb compilers. */ |
| static void print_vma PARAMS ((bfd_vma, print_mode)); |
| static bfd_vma (* byte_get) PARAMS ((unsigned char *, int)); |
| static bfd_vma byte_get_little_endian PARAMS ((unsigned char *, int)); |
| static bfd_vma byte_get_big_endian PARAMS ((unsigned char *, int)); |
| static const char * get_mips_dynamic_type PARAMS ((unsigned long)); |
| static const char * get_sparc64_dynamic_type PARAMS ((unsigned long)); |
| static const char * get_parisc_dynamic_type PARAMS ((unsigned long)); |
| static const char * get_dynamic_type PARAMS ((unsigned long)); |
| static int slurp_rela_relocs PARAMS ((FILE *, unsigned long, unsigned long, Elf_Internal_Rela **, unsigned long *)); |
| static int slurp_rel_relocs PARAMS ((FILE *, unsigned long, unsigned long, Elf_Internal_Rel **, unsigned long *)); |
| static int dump_relocations PARAMS ((FILE *, unsigned long, unsigned long, Elf_Internal_Sym *, unsigned long, char *, int)); |
| static char * get_file_type PARAMS ((unsigned)); |
| static char * get_machine_name PARAMS ((unsigned)); |
| static void decode_ARM_machine_flags PARAMS ((unsigned, char [])); |
| static char * get_machine_flags PARAMS ((unsigned, unsigned)); |
| static const char * get_mips_segment_type PARAMS ((unsigned long)); |
| static const char * get_parisc_segment_type PARAMS ((unsigned long)); |
| static const char * get_ia64_segment_type PARAMS ((unsigned long)); |
| static const char * get_segment_type PARAMS ((unsigned long)); |
| static const char * get_mips_section_type_name PARAMS ((unsigned int)); |
| static const char * get_parisc_section_type_name PARAMS ((unsigned int)); |
| static const char * get_ia64_section_type_name PARAMS ((unsigned int)); |
| static const char * get_section_type_name PARAMS ((unsigned int)); |
| static const char * get_symbol_binding PARAMS ((unsigned int)); |
| static const char * get_symbol_type PARAMS ((unsigned int)); |
| static const char * get_symbol_visibility PARAMS ((unsigned int)); |
| static const char * get_symbol_index_type PARAMS ((unsigned int)); |
| static const char * get_dynamic_flags PARAMS ((bfd_vma)); |
| static void usage PARAMS ((void)); |
| static void parse_args PARAMS ((int, char **)); |
| static int process_file_header PARAMS ((void)); |
| static int process_program_headers PARAMS ((FILE *)); |
| static int process_section_headers PARAMS ((FILE *)); |
| static int process_unwind PARAMS ((FILE *)); |
| static void dynamic_segment_mips_val PARAMS ((Elf_Internal_Dyn *)); |
| static void dynamic_segment_parisc_val PARAMS ((Elf_Internal_Dyn *)); |
| static int process_dynamic_segment PARAMS ((FILE *)); |
| static int process_symbol_table PARAMS ((FILE *)); |
| static int process_section_contents PARAMS ((FILE *)); |
| static void process_file PARAMS ((char *)); |
| static int process_relocs PARAMS ((FILE *)); |
| static int process_version_sections PARAMS ((FILE *)); |
| static char * get_ver_flags PARAMS ((unsigned int)); |
| static int get_32bit_section_headers PARAMS ((FILE *)); |
| static int get_64bit_section_headers PARAMS ((FILE *)); |
| static int get_32bit_program_headers PARAMS ((FILE *, Elf_Internal_Phdr *)); |
| static int get_64bit_program_headers PARAMS ((FILE *, Elf_Internal_Phdr *)); |
| static int get_file_header PARAMS ((FILE *)); |
| static Elf_Internal_Sym * get_32bit_elf_symbols PARAMS ((FILE *, unsigned long, unsigned long)); |
| static Elf_Internal_Sym * get_64bit_elf_symbols PARAMS ((FILE *, unsigned long, unsigned long)); |
| static const char * get_elf_section_flags PARAMS ((bfd_vma)); |
| static int * get_dynamic_data PARAMS ((FILE *, unsigned int)); |
| static int get_32bit_dynamic_segment PARAMS ((FILE *)); |
| static int get_64bit_dynamic_segment PARAMS ((FILE *)); |
| #ifdef SUPPORT_DISASSEMBLY |
| static int disassemble_section PARAMS ((Elf32_Internal_Shdr *, FILE *)); |
| #endif |
| static int dump_section PARAMS ((Elf32_Internal_Shdr *, FILE *)); |
| static int display_debug_section PARAMS ((Elf32_Internal_Shdr *, FILE *)); |
| static int display_debug_info PARAMS ((Elf32_Internal_Shdr *, unsigned char *, FILE *)); |
| static int display_debug_not_supported PARAMS ((Elf32_Internal_Shdr *, unsigned char *, FILE *)); |
| static int display_debug_lines PARAMS ((Elf32_Internal_Shdr *, unsigned char *, FILE *)); |
| static int display_debug_abbrev PARAMS ((Elf32_Internal_Shdr *, unsigned char *, FILE *)); |
| static int display_debug_aranges PARAMS ((Elf32_Internal_Shdr *, unsigned char *, FILE *)); |
| static int display_debug_frames PARAMS ((Elf32_Internal_Shdr *, unsigned char *, FILE *)); |
| static unsigned char * process_abbrev_section PARAMS ((unsigned char *, unsigned char *)); |
| static unsigned long read_leb128 PARAMS ((unsigned char *, int *, int)); |
| static int process_extended_line_op PARAMS ((unsigned char *, int, int)); |
| static void reset_state_machine PARAMS ((int)); |
| static char * get_TAG_name PARAMS ((unsigned long)); |
| static char * get_AT_name PARAMS ((unsigned long)); |
| static char * get_FORM_name PARAMS ((unsigned long)); |
| static void free_abbrevs PARAMS ((void)); |
| static void add_abbrev PARAMS ((unsigned long, unsigned long, int)); |
| static void add_abbrev_attr PARAMS ((unsigned long, unsigned long)); |
| static unsigned char * read_and_display_attr PARAMS ((unsigned long, unsigned long, unsigned char *, unsigned long, unsigned long)); |
| static unsigned char * display_block PARAMS ((unsigned char *, unsigned long)); |
| static void decode_location_expression PARAMS ((unsigned char *, unsigned int, unsigned long)); |
| static void request_dump PARAMS ((unsigned int, char)); |
| static const char * get_elf_class PARAMS ((unsigned char)); |
| static const char * get_data_encoding PARAMS ((unsigned char)); |
| static const char * get_osabi_name PARAMS ((unsigned char)); |
| static int guess_is_rela PARAMS ((unsigned long)); |
| static char * get_note_type PARAMS ((unsigned int)); |
| static int process_note PARAMS ((Elf32_Internal_Note *)); |
| static int process_corefile_note_segment PARAMS ((FILE *, bfd_vma, bfd_vma)); |
| static int process_corefile_note_segments PARAMS ((FILE *)); |
| static int process_corefile_contents PARAMS ((FILE *)); |
| |
| typedef int Elf32_Word; |
| |
| #ifndef TRUE |
| #define TRUE 1 |
| #define FALSE 0 |
| #endif |
| #define UNKNOWN -1 |
| |
| #define SECTION_NAME(X) ((X) == NULL ? "<none>" : \ |
| ((X)->sh_name >= string_table_length \ |
| ? "<corrupt>" : string_table + (X)->sh_name)) |
| |
| #define DT_VERSIONTAGIDX(tag) (DT_VERNEEDNUM - (tag)) /* Reverse order! */ |
| |
| #define BYTE_GET(field) byte_get (field, sizeof (field)) |
| |
| /* If we can support a 64 bit data type then BFD64 should be defined |
| and sizeof (bfd_vma) == 8. In this case when translating from an |
| external 8 byte field to an internal field, we can assume that the |
| internal field is also 8 bytes wide and so we can extract all the data. |
| If, however, BFD64 is not defined, then we must assume that the |
| internal data structure only has 4 byte wide fields that are the |
| equivalent of the 8 byte wide external counterparts, and so we must |
| truncate the data. */ |
| #ifdef BFD64 |
| #define BYTE_GET8(field) byte_get (field, -8) |
| #else |
| #define BYTE_GET8(field) byte_get (field, 8) |
| #endif |
| |
| #define NUM_ELEM(array) (sizeof (array) / sizeof ((array)[0])) |
| |
| #define GET_DATA_ALLOC(offset, size, var, type, reason) \ |
| if (fseek (file, offset, SEEK_SET)) \ |
| { \ |
| error (_("Unable to seek to start of %s at %x\n"), reason, offset); \ |
| return 0; \ |
| } \ |
| \ |
| var = (type) malloc (size); \ |
| \ |
| if (var == NULL) \ |
| { \ |
| error (_("Out of memory allocating %d bytes for %s\n"), size, reason); \ |
| return 0; \ |
| } \ |
| \ |
| if (fread (var, size, 1, file) != 1) \ |
| { \ |
| error (_("Unable to read in %d bytes of %s\n"), size, reason); \ |
| free (var); \ |
| var = NULL; \ |
| return 0; \ |
| } |
| |
| |
| #define GET_DATA(offset, var, reason) \ |
| if (fseek (file, offset, SEEK_SET)) \ |
| { \ |
| error (_("Unable to seek to %x for %s\n"), offset, reason); \ |
| return 0; \ |
| } \ |
| else if (fread (& var, sizeof (var), 1, file) != 1) \ |
| { \ |
| error (_("Unable to read data at %x for %s\n"), offset, reason); \ |
| return 0; \ |
| } |
| |
| #define GET_ELF_SYMBOLS(file, offset, size) \ |
| (is_32bit_elf ? get_32bit_elf_symbols (file, offset, size) \ |
| : get_64bit_elf_symbols (file, offset, size)) |
| |
| |
| #ifdef ANSI_PROTOTYPES |
| static void |
| error (const char * message, ...) |
| { |
| va_list args; |
| |
| fprintf (stderr, _("%s: Error: "), program_name); |
| va_start (args, message); |
| vfprintf (stderr, message, args); |
| va_end (args); |
| return; |
| } |
| |
| static void |
| warn (const char * message, ...) |
| { |
| va_list args; |
| |
| fprintf (stderr, _("%s: Warning: "), program_name); |
| va_start (args, message); |
| vfprintf (stderr, message, args); |
| va_end (args); |
| return; |
| } |
| #else |
| static void |
| error (va_alist) |
| va_dcl |
| { |
| char * message; |
| va_list args; |
| |
| fprintf (stderr, _("%s: Error: "), program_name); |
| va_start (args); |
| message = va_arg (args, char *); |
| vfprintf (stderr, message, args); |
| va_end (args); |
| return; |
| } |
| |
| static void |
| warn (va_alist) |
| va_dcl |
| { |
| char * message; |
| va_list args; |
| |
| fprintf (stderr, _("%s: Warning: "), program_name); |
| va_start (args); |
| message = va_arg (args, char *); |
| vfprintf (stderr, message, args); |
| va_end (args); |
| return; |
| } |
| #endif |
| |
| static bfd_vma |
| byte_get_little_endian (field, size) |
| unsigned char * field; |
| int size; |
| { |
| switch (size) |
| { |
| case 1: |
| return * field; |
| |
| case 2: |
| return ((unsigned int) (field [0])) |
| | (((unsigned int) (field [1])) << 8); |
| |
| #ifndef BFD64 |
| case 8: |
| /* We want to extract data from an 8 byte wide field and |
| place it into a 4 byte wide field. Since this is a little |
| endian source we can juts use the 4 byte extraction code. */ |
| /* Fall through. */ |
| #endif |
| case 4: |
| return ((unsigned long) (field [0])) |
| | (((unsigned long) (field [1])) << 8) |
| | (((unsigned long) (field [2])) << 16) |
| | (((unsigned long) (field [3])) << 24); |
| |
| #ifdef BFD64 |
| case 8: |
| case -8: |
| /* This is a special case, generated by the BYTE_GET8 macro. |
| It means that we are loading an 8 byte value from a field |
| in an external structure into an 8 byte value in a field |
| in an internal strcuture. */ |
| return ((bfd_vma) (field [0])) |
| | (((bfd_vma) (field [1])) << 8) |
| | (((bfd_vma) (field [2])) << 16) |
| | (((bfd_vma) (field [3])) << 24) |
| | (((bfd_vma) (field [4])) << 32) |
| | (((bfd_vma) (field [5])) << 40) |
| | (((bfd_vma) (field [6])) << 48) |
| | (((bfd_vma) (field [7])) << 56); |
| #endif |
| default: |
| error (_("Unhandled data length: %d\n"), size); |
| abort (); |
| } |
| } |
| |
| /* Print a VMA value. */ |
| static void |
| print_vma (vma, mode) |
| bfd_vma vma; |
| print_mode mode; |
| { |
| #ifdef BFD64 |
| if (is_32bit_elf) |
| #endif |
| { |
| switch (mode) |
| { |
| case FULL_HEX: printf ("0x"); /* drop through */ |
| case LONG_HEX: printf ("%8.8lx", (unsigned long) vma); break; |
| case PREFIX_HEX: printf ("0x"); /* drop through */ |
| case HEX: printf ("%lx", (unsigned long) vma); break; |
| case DEC: printf ("%ld", (unsigned long) vma); break; |
| case DEC_5: printf ("%5ld", (long) vma); break; |
| case UNSIGNED: printf ("%lu", (unsigned long) vma); break; |
| } |
| } |
| #ifdef BFD64 |
| else |
| { |
| switch (mode) |
| { |
| case FULL_HEX: |
| printf ("0x"); |
| /* drop through */ |
| |
| case LONG_HEX: |
| printf_vma (vma); |
| break; |
| |
| case PREFIX_HEX: |
| printf ("0x"); |
| /* drop through */ |
| |
| case HEX: |
| #if BFD_HOST_64BIT_LONG |
| printf ("%lx", vma); |
| #else |
| if (_bfd_int64_high (vma)) |
| printf ("%lx%lx", _bfd_int64_high (vma), _bfd_int64_low (vma)); |
| else |
| printf ("%lx", _bfd_int64_low (vma)); |
| #endif |
| break; |
| |
| case DEC: |
| #if BFD_HOST_64BIT_LONG |
| printf ("%ld", vma); |
| #else |
| if (_bfd_int64_high (vma)) |
| /* ugg */ |
| printf ("++%ld", _bfd_int64_low (vma)); |
| else |
| printf ("%ld", _bfd_int64_low (vma)); |
| #endif |
| break; |
| |
| case DEC_5: |
| #if BFD_HOST_64BIT_LONG |
| printf ("%5ld", vma); |
| #else |
| if (_bfd_int64_high (vma)) |
| /* ugg */ |
| printf ("++%ld", _bfd_int64_low (vma)); |
| else |
| printf ("%5ld", _bfd_int64_low (vma)); |
| #endif |
| break; |
| |
| case UNSIGNED: |
| #if BFD_HOST_64BIT_LONG |
| printf ("%lu", vma); |
| #else |
| if (_bfd_int64_high (vma)) |
| /* ugg */ |
| printf ("++%lu", _bfd_int64_low (vma)); |
| else |
| printf ("%lu", _bfd_int64_low (vma)); |
| #endif |
| break; |
| } |
| } |
| #endif |
| } |
| |
| static bfd_vma |
| byte_get_big_endian (field, size) |
| unsigned char * field; |
| int size; |
| { |
| switch (size) |
| { |
| case 1: |
| return * field; |
| |
| case 2: |
| return ((unsigned int) (field [1])) | (((int) (field [0])) << 8); |
| |
| case 4: |
| return ((unsigned long) (field [3])) |
| | (((unsigned long) (field [2])) << 8) |
| | (((unsigned long) (field [1])) << 16) |
| | (((unsigned long) (field [0])) << 24); |
| |
| #ifndef BFD64 |
| case 8: |
| /* Although we are extracing data from an 8 byte wide field, we |
| are returning only 4 bytes of data. */ |
| return ((unsigned long) (field [7])) |
| | (((unsigned long) (field [6])) << 8) |
| | (((unsigned long) (field [5])) << 16) |
| | (((unsigned long) (field [4])) << 24); |
| #else |
| case 8: |
| case -8: |
| /* This is a special case, generated by the BYTE_GET8 macro. |
| It means that we are loading an 8 byte value from a field |
| in an external structure into an 8 byte value in a field |
| in an internal strcuture. */ |
| return ((bfd_vma) (field [7])) |
| | (((bfd_vma) (field [6])) << 8) |
| | (((bfd_vma) (field [5])) << 16) |
| | (((bfd_vma) (field [4])) << 24) |
| | (((bfd_vma) (field [3])) << 32) |
| | (((bfd_vma) (field [2])) << 40) |
| | (((bfd_vma) (field [1])) << 48) |
| | (((bfd_vma) (field [0])) << 56); |
| #endif |
| |
| default: |
| error (_("Unhandled data length: %d\n"), size); |
| abort (); |
| } |
| } |
| |
| /* Guess the relocation size commonly used by the specific machines. */ |
| |
| static int |
| guess_is_rela (e_machine) |
| unsigned long e_machine; |
| { |
| switch (e_machine) |
| { |
| /* Targets that use REL relocations. */ |
| case EM_ARM: |
| case EM_386: |
| case EM_486: |
| case EM_960: |
| case EM_CYGNUS_M32R: |
| case EM_CYGNUS_D10V: |
| case EM_MIPS: |
| case EM_MIPS_RS3_LE: |
| return FALSE; |
| |
| /* Targets that use RELA relocations. */ |
| case EM_68K: |
| case EM_SPARC32PLUS: |
| case EM_SPARCV9: |
| case EM_SPARC: |
| case EM_PPC: |
| case EM_CYGNUS_V850: |
| case EM_CYGNUS_D30V: |
| case EM_CYGNUS_MN10200: |
| case EM_CYGNUS_MN10300: |
| case EM_CYGNUS_FR30: |
| case EM_SH: |
| case EM_ALPHA: |
| case EM_MCORE: |
| case EM_IA_64: |
| case EM_AVR: |
| case EM_CRIS: |
| case EM_860: |
| case EM_X86_64: |
| return TRUE; |
| |
| case EM_MMA: |
| case EM_PCP: |
| case EM_NCPU: |
| case EM_NDR1: |
| case EM_STARCORE: |
| case EM_ME16: |
| case EM_ST100: |
| case EM_TINYJ: |
| case EM_FX66: |
| case EM_ST9PLUS: |
| case EM_ST7: |
| case EM_68HC16: |
| case EM_68HC11: |
| case EM_68HC08: |
| case EM_68HC05: |
| case EM_SVX: |
| case EM_ST19: |
| case EM_VAX: |
| default: |
| warn (_("Don't know about relocations on this machine architecture\n")); |
| return FALSE; |
| } |
| } |
| |
| static int |
| slurp_rela_relocs (file, rel_offset, rel_size, relasp, nrelasp) |
| FILE *file; |
| unsigned long rel_offset; |
| unsigned long rel_size; |
| Elf_Internal_Rela **relasp; |
| unsigned long *nrelasp; |
| { |
| Elf_Internal_Rela *relas; |
| unsigned long nrelas; |
| unsigned int i; |
| |
| if (is_32bit_elf) |
| { |
| Elf32_External_Rela * erelas; |
| |
| GET_DATA_ALLOC (rel_offset, rel_size, erelas, |
| Elf32_External_Rela *, "relocs"); |
| |
| nrelas = rel_size / sizeof (Elf32_External_Rela); |
| |
| relas = (Elf_Internal_Rela *) |
| malloc (nrelas * sizeof (Elf_Internal_Rela)); |
| |
| if (relas == NULL) |
| { |
| error(_("out of memory parsing relocs")); |
| return 0; |
| } |
| |
| for (i = 0; i < nrelas; i++) |
| { |
| relas[i].r_offset = BYTE_GET (erelas[i].r_offset); |
| relas[i].r_info = BYTE_GET (erelas[i].r_info); |
| relas[i].r_addend = BYTE_GET (erelas[i].r_addend); |
| } |
| |
| free (erelas); |
| } |
| else |
| { |
| Elf64_External_Rela * erelas; |
| |
| GET_DATA_ALLOC (rel_offset, rel_size, erelas, |
| Elf64_External_Rela *, "relocs"); |
| |
| nrelas = rel_size / sizeof (Elf64_External_Rela); |
| |
| relas = (Elf_Internal_Rela *) |
| malloc (nrelas * sizeof (Elf_Internal_Rela)); |
| |
| if (relas == NULL) |
| { |
| error(_("out of memory parsing relocs")); |
| return 0; |
| } |
| |
| for (i = 0; i < nrelas; i++) |
| { |
| relas[i].r_offset = BYTE_GET8 (erelas[i].r_offset); |
| relas[i].r_info = BYTE_GET8 (erelas[i].r_info); |
| relas[i].r_addend = BYTE_GET8 (erelas[i].r_addend); |
| } |
| |
| free (erelas); |
| } |
| *relasp = relas; |
| *nrelasp = nrelas; |
| return 1; |
| } |
| |
| static int |
| slurp_rel_relocs (file, rel_offset, rel_size, relsp, nrelsp) |
| FILE *file; |
| unsigned long rel_offset; |
| unsigned long rel_size; |
| Elf_Internal_Rel **relsp; |
| unsigned long *nrelsp; |
| { |
| Elf_Internal_Rel *rels; |
| unsigned long nrels; |
| unsigned int i; |
| |
| if (is_32bit_elf) |
| { |
| Elf32_External_Rel * erels; |
| |
| GET_DATA_ALLOC (rel_offset, rel_size, erels, |
| Elf32_External_Rel *, "relocs"); |
| |
| nrels = rel_size / sizeof (Elf32_External_Rel); |
| |
| rels = (Elf_Internal_Rel *) malloc (nrels * sizeof (Elf_Internal_Rel)); |
| |
| if (rels == NULL) |
| { |
| error(_("out of memory parsing relocs")); |
| return 0; |
| } |
| |
| for (i = 0; i < nrels; i++) |
| { |
| rels[i].r_offset = BYTE_GET (erels[i].r_offset); |
| rels[i].r_info = BYTE_GET (erels[i].r_info); |
| } |
| |
| free (erels); |
| } |
| else |
| { |
| Elf64_External_Rel * erels; |
| |
| GET_DATA_ALLOC (rel_offset, rel_size, erels, |
| Elf64_External_Rel *, "relocs"); |
| |
| nrels = rel_size / sizeof (Elf64_External_Rel); |
| |
| rels = (Elf_Internal_Rel *) malloc (nrels * sizeof (Elf_Internal_Rel)); |
| |
| if (rels == NULL) |
| { |
| error(_("out of memory parsing relocs")); |
| return 0; |
| } |
| |
| for (i = 0; i < nrels; i++) |
| { |
| rels[i].r_offset = BYTE_GET8 (erels[i].r_offset); |
| rels[i].r_info = BYTE_GET8 (erels[i].r_info); |
| } |
| |
| free (erels); |
| } |
| *relsp = rels; |
| *nrelsp = nrels; |
| return 1; |
| } |
| |
| /* Display the contents of the relocation data found at the specified offset. */ |
| static int |
| dump_relocations (file, rel_offset, rel_size, symtab, nsyms, strtab, is_rela) |
| FILE * file; |
| unsigned long rel_offset; |
| unsigned long rel_size; |
| Elf_Internal_Sym * symtab; |
| unsigned long nsyms; |
| char * strtab; |
| int is_rela; |
| { |
| unsigned int i; |
| Elf_Internal_Rel * rels; |
| Elf_Internal_Rela * relas; |
| |
| |
| if (is_rela == UNKNOWN) |
| is_rela = guess_is_rela (elf_header.e_machine); |
| |
| if (is_rela) |
| { |
| if (!slurp_rela_relocs (file, rel_offset, rel_size, &relas, &rel_size)) |
| return 0; |
| } |
| else |
| { |
| if (!slurp_rel_relocs (file, rel_offset, rel_size, &rels, &rel_size)) |
| return 0; |
| } |
| |
| if (is_rela) |
| printf |
| (_(" Offset Info Type Symbol's Value Symbol's Name Addend\n")); |
| else |
| printf |
| (_(" Offset Info Type Symbol's Value Symbol's Name\n")); |
| |
| for (i = 0; i < rel_size; i++) |
| { |
| const char * rtype; |
| bfd_vma offset; |
| bfd_vma info; |
| bfd_vma symtab_index; |
| bfd_vma type; |
| |
| if (is_rela) |
| { |
| offset = relas [i].r_offset; |
| info = relas [i].r_info; |
| } |
| else |
| { |
| offset = rels [i].r_offset; |
| info = rels [i].r_info; |
| } |
| |
| if (is_32bit_elf) |
| { |
| type = ELF32_R_TYPE (info); |
| symtab_index = ELF32_R_SYM (info); |
| } |
| else |
| { |
| if (elf_header.e_machine == EM_SPARCV9) |
| type = ELF64_R_TYPE_ID (info); |
| else |
| type = ELF64_R_TYPE (info); |
| /* The #ifdef BFD64 below is to prevent a compile time warning. |
| We know that if we do not have a 64 bit data type that we |
| will never execute this code anyway. */ |
| #ifdef BFD64 |
| symtab_index = ELF64_R_SYM (info); |
| #endif |
| } |
| |
| #ifdef _bfd_int64_low |
| printf (" %8.8lx %5.5lx ", _bfd_int64_low (offset), _bfd_int64_low (info)); |
| #else |
| printf (" %8.8lx %5.5lx ", offset, info); |
| #endif |
| |
| switch (elf_header.e_machine) |
| { |
| default: |
| rtype = NULL; |
| break; |
| |
| case EM_CYGNUS_M32R: |
| rtype = elf_m32r_reloc_type (type); |
| break; |
| |
| case EM_386: |
| case EM_486: |
| rtype = elf_i386_reloc_type (type); |
| break; |
| |
| case EM_68K: |
| rtype = elf_m68k_reloc_type (type); |
| break; |
| |
| case EM_960: |
| rtype = elf_i960_reloc_type (type); |
| break; |
| |
| case EM_AVR: |
| rtype = elf_avr_reloc_type (type); |
| break; |
| |
| case EM_OLD_SPARCV9: |
| case EM_SPARC32PLUS: |
| case EM_SPARCV9: |
| case EM_SPARC: |
| rtype = elf_sparc_reloc_type (type); |
| break; |
| |
| case EM_CYGNUS_V850: |
| rtype = v850_reloc_type (type); |
| break; |
| |
| case EM_CYGNUS_D10V: |
| rtype = elf_d10v_reloc_type (type); |
| break; |
| |
| case EM_CYGNUS_D30V: |
| rtype = elf_d30v_reloc_type (type); |
| break; |
| |
| case EM_SH: |
| rtype = elf_sh_reloc_type (type); |
| break; |
| |
| case EM_CYGNUS_MN10300: |
| rtype = elf_mn10300_reloc_type (type); |
| break; |
| |
| case EM_CYGNUS_MN10200: |
| rtype = elf_mn10200_reloc_type (type); |
| break; |
| |
| case EM_CYGNUS_FR30: |
| rtype = elf_fr30_reloc_type (type); |
| break; |
| |
| case EM_MCORE: |
| rtype = elf_mcore_reloc_type (type); |
| break; |
| |
| case EM_PPC: |
| rtype = elf_ppc_reloc_type (type); |
| break; |
| |
| case EM_MIPS: |
| case EM_MIPS_RS3_LE: |
| rtype = elf_mips_reloc_type (type); |
| break; |
| |
| case EM_ALPHA: |
| rtype = elf_alpha_reloc_type (type); |
| break; |
| |
| case EM_ARM: |
| rtype = elf_arm_reloc_type (type); |
| break; |
| |
| case EM_CYGNUS_ARC: |
| case EM_ARC: |
| rtype = elf_arc_reloc_type (type); |
| break; |
| |
| case EM_PARISC: |
| rtype = elf_hppa_reloc_type (type); |
| break; |
| |
| case EM_PJ: |
| rtype = elf_pj_reloc_type (type); |
| break; |
| case EM_IA_64: |
| rtype = elf_ia64_reloc_type (type); |
| break; |
| |
| case EM_CRIS: |
| rtype = elf_cris_reloc_type (type); |
| break; |
| |
| case EM_860: |
| rtype = elf_i860_reloc_type (type); |
| break; |
| |
| case EM_X86_64: |
| rtype = elf_x86_64_reloc_type (type); |
| break; |
| } |
| |
| if (rtype == NULL) |
| #ifdef _bfd_int64_low |
| printf (_("unrecognised: %-7lx"), _bfd_int64_low (type)); |
| #else |
| printf (_("unrecognised: %-7lx"), type); |
| #endif |
| else |
| printf ("%-21.21s", rtype); |
| |
| if (symtab_index) |
| { |
| if (symtab != NULL) |
| { |
| if (symtab_index >= nsyms) |
| printf (" bad symbol index: %08lx", (unsigned long) symtab_index); |
| else |
| { |
| Elf_Internal_Sym * psym; |
| |
| psym = symtab + symtab_index; |
| |
| printf (" "); |
| print_vma (psym->st_value, LONG_HEX); |
| printf (" "); |
| |
| if (psym->st_name == 0) |
| printf ("%-25.25s", |
| SECTION_NAME (section_headers + psym->st_shndx)); |
| else if (strtab == NULL) |
| printf (_("<string table index %3ld>"), psym->st_name); |
| else |
| printf ("%-25.25s", strtab + psym->st_name); |
| |
| if (is_rela) |
| printf (" + %lx", (unsigned long) relas [i].r_addend); |
| } |
| } |
| } |
| else if (is_rela) |
| { |
| printf ("%*c", is_32bit_elf ? 34 : 26, ' '); |
| print_vma (relas[i].r_addend, LONG_HEX); |
| } |
| |
| if (elf_header.e_machine == EM_SPARCV9 |
| && !strcmp (rtype, "R_SPARC_OLO10")) |
| printf (" + %lx", (unsigned long) ELF64_R_TYPE_DATA (info)); |
| |
| putchar ('\n'); |
| } |
| |
| if (is_rela) |
| free (relas); |
| else |
| free (rels); |
| |
| return 1; |
| } |
| |
| static const char * |
| get_mips_dynamic_type (type) |
| unsigned long type; |
| { |
| switch (type) |
| { |
| case DT_MIPS_RLD_VERSION: return "MIPS_RLD_VERSION"; |
| case DT_MIPS_TIME_STAMP: return "MIPS_TIME_STAMP"; |
| case DT_MIPS_ICHECKSUM: return "MIPS_ICHECKSUM"; |
| case DT_MIPS_IVERSION: return "MIPS_IVERSION"; |
| case DT_MIPS_FLAGS: return "MIPS_FLAGS"; |
| case DT_MIPS_BASE_ADDRESS: return "MIPS_BASE_ADDRESS"; |
| case DT_MIPS_MSYM: return "MIPS_MSYM"; |
| case DT_MIPS_CONFLICT: return "MIPS_CONFLICT"; |
| case DT_MIPS_LIBLIST: return "MIPS_LIBLIST"; |
| case DT_MIPS_LOCAL_GOTNO: return "MIPS_LOCAL_GOTNO"; |
| case DT_MIPS_CONFLICTNO: return "MIPS_CONFLICTNO"; |
| case DT_MIPS_LIBLISTNO: return "MIPS_LIBLISTNO"; |
| case DT_MIPS_SYMTABNO: return "MIPS_SYMTABNO"; |
| case DT_MIPS_UNREFEXTNO: return "MIPS_UNREFEXTNO"; |
| case DT_MIPS_GOTSYM: return "MIPS_GOTSYM"; |
| case DT_MIPS_HIPAGENO: return "MIPS_HIPAGENO"; |
| case DT_MIPS_RLD_MAP: return "MIPS_RLD_MAP"; |
| case DT_MIPS_DELTA_CLASS: return "MIPS_DELTA_CLASS"; |
| case DT_MIPS_DELTA_CLASS_NO: return "MIPS_DELTA_CLASS_NO"; |
| case DT_MIPS_DELTA_INSTANCE: return "MIPS_DELTA_INSTANCE"; |
| case DT_MIPS_DELTA_INSTANCE_NO: return "MIPS_DELTA_INSTANCE_NO"; |
| case DT_MIPS_DELTA_RELOC: return "MIPS_DELTA_RELOC"; |
| case DT_MIPS_DELTA_RELOC_NO: return "MIPS_DELTA_RELOC_NO"; |
| case DT_MIPS_DELTA_SYM: return "MIPS_DELTA_SYM"; |
| case DT_MIPS_DELTA_SYM_NO: return "MIPS_DELTA_SYM_NO"; |
| case DT_MIPS_DELTA_CLASSSYM: return "MIPS_DELTA_CLASSSYM"; |
| case DT_MIPS_DELTA_CLASSSYM_NO: return "MIPS_DELTA_CLASSSYM_NO"; |
| case DT_MIPS_CXX_FLAGS: return "MIPS_CXX_FLAGS"; |
| case DT_MIPS_PIXIE_INIT: return "MIPS_PIXIE_INIT"; |
| case DT_MIPS_SYMBOL_LIB: return "MIPS_SYMBOL_LIB"; |
| case DT_MIPS_LOCALPAGE_GOTIDX: return "MIPS_LOCALPAGE_GOTIDX"; |
| case DT_MIPS_LOCAL_GOTIDX: return "MIPS_LOCAL_GOTIDX"; |
| case DT_MIPS_HIDDEN_GOTIDX: return "MIPS_HIDDEN_GOTIDX"; |
| case DT_MIPS_PROTECTED_GOTIDX: return "MIPS_PROTECTED_GOTIDX"; |
| case DT_MIPS_OPTIONS: return "MIPS_OPTIONS"; |
| case DT_MIPS_INTERFACE: return "MIPS_INTERFACE"; |
| case DT_MIPS_DYNSTR_ALIGN: return "MIPS_DYNSTR_ALIGN"; |
| case DT_MIPS_INTERFACE_SIZE: return "MIPS_INTERFACE_SIZE"; |
| case DT_MIPS_RLD_TEXT_RESOLVE_ADDR: return "MIPS_RLD_TEXT_RESOLVE_ADDR"; |
| case DT_MIPS_PERF_SUFFIX: return "MIPS_PERF_SUFFIX"; |
| case DT_MIPS_COMPACT_SIZE: return "MIPS_COMPACT_SIZE"; |
| case DT_MIPS_GP_VALUE: return "MIPS_GP_VALUE"; |
| case DT_MIPS_AUX_DYNAMIC: return "MIPS_AUX_DYNAMIC"; |
| default: |
| return NULL; |
| } |
| } |
| |
| static const char * |
| get_sparc64_dynamic_type (type) |
| unsigned long type; |
| { |
| switch (type) |
| { |
| case DT_SPARC_REGISTER: return "SPARC_REGISTER"; |
| default: |
| return NULL; |
| } |
| } |
| |
| static const char * |
| get_parisc_dynamic_type (type) |
| unsigned long type; |
| { |
| switch (type) |
| { |
| case DT_HP_LOAD_MAP: return "HP_LOAD_MAP"; |
| case DT_HP_DLD_FLAGS: return "HP_DLD_FLAGS"; |
| case DT_HP_DLD_HOOK: return "HP_DLD_HOOK"; |
| case DT_HP_UX10_INIT: return "HP_UX10_INIT"; |
| case DT_HP_UX10_INITSZ: return "HP_UX10_INITSZ"; |
| case DT_HP_PREINIT: return "HP_PREINIT"; |
| case DT_HP_PREINITSZ: return "HP_PREINITSZ"; |
| case DT_HP_NEEDED: return "HP_NEEDED"; |
| case DT_HP_TIME_STAMP: return "HP_TIME_STAMP"; |
| case DT_HP_CHECKSUM: return "HP_CHECKSUM"; |
| case DT_HP_GST_SIZE: return "HP_GST_SIZE"; |
| case DT_HP_GST_VERSION: return "HP_GST_VERSION"; |
| case DT_HP_GST_HASHVAL: return "HP_GST_HASHVAL"; |
| default: |
| return NULL; |
| } |
| } |
| |
| static const char * |
| get_dynamic_type (type) |
| unsigned long type; |
| { |
| static char buff [32]; |
| |
| switch (type) |
| { |
| case DT_NULL: return "NULL"; |
| case DT_NEEDED: return "NEEDED"; |
| case DT_PLTRELSZ: return "PLTRELSZ"; |
| case DT_PLTGOT: return "PLTGOT"; |
| case DT_HASH: return "HASH"; |
| case DT_STRTAB: return "STRTAB"; |
| case DT_SYMTAB: return "SYMTAB"; |
| case DT_RELA: return "RELA"; |
| case DT_RELASZ: return "RELASZ"; |
| case DT_RELAENT: return "RELAENT"; |
| case DT_STRSZ: return "STRSZ"; |
| case DT_SYMENT: return "SYMENT"; |
| case DT_INIT: return "INIT"; |
| case DT_FINI: return "FINI"; |
| case DT_SONAME: return "SONAME"; |
| case DT_RPATH: return "RPATH"; |
| case DT_SYMBOLIC: return "SYMBOLIC"; |
| case DT_REL: return "REL"; |
| case DT_RELSZ: return "RELSZ"; |
| case DT_RELENT: return "RELENT"; |
| case DT_PLTREL: return "PLTREL"; |
| case DT_DEBUG: return "DEBUG"; |
| case DT_TEXTREL: return "TEXTREL"; |
| case DT_JMPREL: return "JMPREL"; |
| case DT_BIND_NOW: return "BIND_NOW"; |
| case DT_INIT_ARRAY: return "INIT_ARRAY"; |
| case DT_FINI_ARRAY: return "FINI_ARRAY"; |
| case DT_INIT_ARRAYSZ: return "INIT_ARRAYSZ"; |
| case DT_FINI_ARRAYSZ: return "FINI_ARRAYSZ"; |
| case DT_RUNPATH: return "RUNPATH"; |
| case DT_FLAGS: return "FLAGS"; |
| |
| case DT_PREINIT_ARRAY: return "PREINIT_ARRAY"; |
| case DT_PREINIT_ARRAYSZ: return "PREINIT_ARRAYSZ"; |
| |
| case DT_CHECKSUM: return "CHECKSUM"; |
| case DT_PLTPADSZ: return "PLTPADSZ"; |
| case DT_MOVEENT: return "MOVEENT"; |
| case DT_MOVESZ: return "MOVESZ"; |
| case DT_FEATURE: return "FEATURE"; |
| case DT_POSFLAG_1: return "POSFLAG_1"; |
| case DT_SYMINSZ: return "SYMINSZ"; |
| case DT_SYMINENT: return "SYMINENT"; /* aka VALRNGHI */ |
| |
| case DT_ADDRRNGLO: return "ADDRRNGLO"; |
| case DT_CONFIG: return "CONFIG"; |
| case DT_DEPAUDIT: return "DEPAUDIT"; |
| case DT_AUDIT: return "AUDIT"; |
| case DT_PLTPAD: return "PLTPAD"; |
| case DT_MOVETAB: return "MOVETAB"; |
| case DT_SYMINFO: return "SYMINFO"; /* aka ADDRRNGHI */ |
| |
| case DT_VERSYM: return "VERSYM"; |
| |
| case DT_RELACOUNT: return "RELACOUNT"; |
| case DT_RELCOUNT: return "RELCOUNT"; |
| case DT_FLAGS_1: return "FLAGS_1"; |
| case DT_VERDEF: return "VERDEF"; |
| case DT_VERDEFNUM: return "VERDEFNUM"; |
| case DT_VERNEED: return "VERNEED"; |
| case DT_VERNEEDNUM: return "VERNEEDNUM"; |
| |
| case DT_AUXILIARY: return "AUXILIARY"; |
| case DT_USED: return "USED"; |
| case DT_FILTER: return "FILTER"; |
| |
| default: |
| if ((type >= DT_LOPROC) && (type <= DT_HIPROC)) |
| { |
| const char * result; |
| |
| switch (elf_header.e_machine) |
| { |
| case EM_MIPS: |
| case EM_MIPS_RS3_LE: |
| result = get_mips_dynamic_type (type); |
| break; |
| case EM_SPARCV9: |
| result = get_sparc64_dynamic_type (type); |
| break; |
| default: |
| result = NULL; |
| break; |
| } |
| |
| if (result != NULL) |
| return result; |
| |
| sprintf (buff, _("Processor Specific: %lx"), type); |
| } |
| else if ((type >= DT_LOOS) && (type <= DT_HIOS)) |
| { |
| const char * result; |
| |
| switch (elf_header.e_machine) |
| { |
| case EM_PARISC: |
| result = get_parisc_dynamic_type (type); |
| break; |
| default: |
| result = NULL; |
| break; |
| } |
| |
| if (result != NULL) |
| return result; |
| |
| sprintf (buff, _("Operating System specific: %lx"), type); |
| } |
| else |
| sprintf (buff, _("<unknown>: %lx"), type); |
| |
| return buff; |
| } |
| } |
| |
| static char * |
| get_file_type (e_type) |
| unsigned e_type; |
| { |
| static char buff [32]; |
| |
| switch (e_type) |
| { |
| case ET_NONE: return _("NONE (None)"); |
| case ET_REL: return _("REL (Relocatable file)"); |
| case ET_EXEC: return _("EXEC (Executable file)"); |
| case ET_DYN: return _("DYN (Shared object file)"); |
| case ET_CORE: return _("CORE (Core file)"); |
| |
| default: |
| if ((e_type >= ET_LOPROC) && (e_type <= ET_HIPROC)) |
| sprintf (buff, _("Processor Specific: (%x)"), e_type); |
| else if ((e_type >= ET_LOOS) && (e_type <= ET_HIOS)) |
| sprintf (buff, _("OS Specific: (%x)"), e_type); |
| else |
| sprintf (buff, _("<unknown>: %x"), e_type); |
| return buff; |
| } |
| } |
| |
| static char * |
| get_machine_name (e_machine) |
| unsigned e_machine; |
| { |
| static char buff [64]; /* XXX */ |
| |
| switch (e_machine) |
| { |
| case EM_NONE: return _("None"); |
| case EM_M32: return "WE32100"; |
| case EM_SPARC: return "Sparc"; |
| case EM_386: return "Intel 80386"; |
| case EM_68K: return "MC68000"; |
| case EM_88K: return "MC88000"; |
| case EM_486: return "Intel 80486"; |
| case EM_860: return "Intel 80860"; |
| case EM_MIPS: return "MIPS R3000"; |
| case EM_S370: return "IBM System/370"; |
| case EM_MIPS_RS3_LE: return "MIPS R4000 big-endian"; |
| case EM_OLD_SPARCV9: return "Sparc v9 (old)"; |
| case EM_PARISC: return "HPPA"; |
| case EM_PPC_OLD: return "Power PC (old)"; |
| case EM_SPARC32PLUS: return "Sparc v8+" ; |
| case EM_960: return "Intel 90860"; |
| case EM_PPC: return "PowerPC"; |
| case EM_V800: return "NEC V800"; |
| case EM_FR20: return "Fujitsu FR20"; |
| case EM_RH32: return "TRW RH32"; |
| case EM_MCORE: return "MCORE"; |
| case EM_ARM: return "ARM"; |
| case EM_OLD_ALPHA: return "Digital Alpha (old)"; |
| case EM_SH: return "Hitachi SH"; |
| case EM_SPARCV9: return "Sparc v9"; |
| case EM_TRICORE: return "Siemens Tricore"; |
| case EM_ARC: return "ARC"; |
| case EM_H8_300: return "Hitachi H8/300"; |
| case EM_H8_300H: return "Hitachi H8/300H"; |
| case EM_H8S: return "Hitachi H8S"; |
| case EM_H8_500: return "Hitachi H8/500"; |
| case EM_IA_64: return "Intel IA-64"; |
| case EM_MIPS_X: return "Stanford MIPS-X"; |
| case EM_COLDFIRE: return "Motorola Coldfire"; |
| case EM_68HC12: return "Motorola M68HC12"; |
| case EM_ALPHA: return "Alpha"; |
| case EM_CYGNUS_D10V: return "d10v"; |
| case EM_CYGNUS_D30V: return "d30v"; |
| case EM_CYGNUS_ARC: return "ARC"; |
| case EM_CYGNUS_M32R: return "Mitsubishi M32r"; |
| case EM_CYGNUS_V850: return "NEC v850"; |
| case EM_CYGNUS_MN10300: return "mn10300"; |
| case EM_CYGNUS_MN10200: return "mn10200"; |
| case EM_CYGNUS_FR30: return "Fujitsu FR30"; |
| case EM_PJ: return "picoJava"; |
| case EM_MMA: return "Fujitsu Multimedia Accelerator"; |
| case EM_PCP: return "Siemens PCP"; |
| case EM_NCPU: return "Sony nCPU embedded RISC processor"; |
| case EM_NDR1: return "Denso NDR1 microprocesspr"; |
| case EM_STARCORE: return "Motorola Star*Core processor"; |
| case EM_ME16: return "Toyota ME16 processor"; |
| case EM_ST100: return "STMicroelectronics ST100 processor"; |
| case EM_TINYJ: return "Advanced Logic Corp. TinyJ embedded processor"; |
| case EM_FX66: return "Siemens FX66 microcontroller"; |
| case EM_ST9PLUS: return "STMicroelectronics ST9+ 8/16 bit microcontroller"; |
| case EM_ST7: return "STMicroelectronics ST7 8-bit microcontroller"; |
| case EM_68HC16: return "Motorola MC68HC16 Microcontroller"; |
| case EM_68HC11: return "Motorola MC68HC11 Microcontroller"; |
| case EM_68HC08: return "Motorola MC68HC08 Microcontroller"; |
| case EM_68HC05: return "Motorola MC68HC05 Microcontroller"; |
| case EM_SVX: return "Silicon Graphics SVx"; |
| case EM_ST19: return "STMicroelectronics ST19 8-bit microcontroller"; |
| case EM_VAX: return "Digital VAX"; |
| case EM_AVR: return "Atmel AVR 8-bit microcontroller"; |
| case EM_CRIS: return "Axis Communications 32-bit embedded processor"; |
| case EM_JAVELIN: return "Infineon Technologies 32-bit embedded cpu"; |
| case EM_FIREPATH: return "Element 14 64-bit DSP processor"; |
| case EM_ZSP: return "LSI Logic's 16-bit DSP processor"; |
| case EM_MMIX: return "Donald Knuth's educational 64-bit processor"; |
| case EM_HUANY: return "Harvard Universitys's machine-independent object format"; |
| case EM_PRISM: return "SiTera Prism"; |
| case EM_X86_64: return "Advanced Micro Devices X86-64"; |
| default: |
| sprintf (buff, _("<unknown>: %x"), e_machine); |
| return buff; |
| } |
| } |
| |
| static void |
| decode_ARM_machine_flags (e_flags, buf) |
| unsigned e_flags; |
| char buf[]; |
| { |
| unsigned eabi; |
| int unknown = 0; |
| |
| eabi = EF_ARM_EABI_VERSION (e_flags); |
| e_flags &= ~ EF_ARM_EABIMASK; |
| |
| /* Handle "generic" ARM flags. */ |
| if (e_flags & EF_ARM_RELEXEC) |
| { |
| strcat (buf, ", relocatable executable"); |
| e_flags &= ~ EF_ARM_RELEXEC; |
| } |
| |
| if (e_flags & EF_ARM_HASENTRY) |
| { |
| strcat (buf, ", has entry point"); |
| e_flags &= ~ EF_ARM_HASENTRY; |
| } |
| |
| /* Now handle EABI specific flags. */ |
| switch (eabi) |
| { |
| default: |
| strcat (buf, ", <unknown EABI>"); |
| if (e_flags) |
| unknown = 1; |
| break; |
| |
| case EF_ARM_EABI_VER1: |
| while (e_flags) |
| { |
| unsigned flag; |
| |
| /* Process flags one bit at a time. */ |
| flag = e_flags & - e_flags; |
| e_flags &= ~ flag; |
| |
| switch (flag) |
| { |
| case EF_ARM_SYMSARESORTED: /* Conflicts with EF_INTERWORK. */ |
| strcat (buf, ", sorted symbol tables"); |
| break; |
| |
| default: |
| unknown = 1; |
| break; |
| } |
| } |
| break; |
| |
| case EF_ARM_EABI_UNKNOWN: |
| while (e_flags) |
| { |
| unsigned flag; |
| |
| /* Process flags one bit at a time. */ |
| flag = e_flags & - e_flags; |
| e_flags &= ~ flag; |
| |
| switch (flag) |
| { |
| case EF_INTERWORK: |
| strcat (buf, ", interworking enabled"); |
| break; |
| |
| case EF_APCS_26: |
| strcat (buf, ", uses APCS/26"); |
| break; |
| |
| case EF_APCS_FLOAT: |
| strcat (buf, ", uses APCS/float"); |
| break; |
| |
| case EF_PIC: |
| strcat (buf, ", position independent"); |
| break; |
| |
| case EF_ALIGN8: |
| strcat (buf, ", 8 bit structure alignment"); |
| break; |
| |
| case EF_NEW_ABI: |
| strcat (buf, ", uses new ABI"); |
| break; |
| |
| case EF_OLD_ABI: |
| strcat (buf, ", uses old ABI"); |
| break; |
| |
| case EF_SOFT_FLOAT: |
| strcat (buf, ", software FP"); |
| break; |
| |
| default: |
| unknown = 1; |
| break; |
| } |
| } |
| } |
| |
| if (unknown) |
| strcat (buf,", <unknown>"); |
| } |
| |
| static char * |
| get_machine_flags (e_flags, e_machine) |
| unsigned e_flags; |
| unsigned e_machine; |
| { |
| static char buf [1024]; |
| |
| buf[0] = '\0'; |
| |
| if (e_flags) |
| { |
| switch (e_machine) |
| { |
| default: |
| break; |
| |
| case EM_ARM: |
| decode_ARM_machine_flags (e_flags, buf); |
| break; |
| |
| case EM_68K: |
| if (e_flags & EF_CPU32) |
| strcat (buf, ", cpu32"); |
| break; |
| |
| case EM_PPC: |
| if (e_flags & EF_PPC_EMB) |
| strcat (buf, ", emb"); |
| |
| if (e_flags & EF_PPC_RELOCATABLE) |
| strcat (buf, ", relocatable"); |
| |
| if (e_flags & EF_PPC_RELOCATABLE_LIB) |
| strcat (buf, ", relocatable-lib"); |
| break; |
| |
| case EM_CYGNUS_V850: |
| switch (e_flags & EF_V850_ARCH) |
| { |
| case E_V850E_ARCH: |
| strcat (buf, ", v850e"); |
| break; |
| case E_V850EA_ARCH: |
| strcat (buf, ", v850ea"); |
| break; |
| case E_V850_ARCH: |
| strcat (buf, ", v850"); |
| break; |
| default: |
| strcat (buf, ", unknown v850 architecture variant"); |
| break; |
| } |
| break; |
| |
| case EM_CYGNUS_M32R: |
| if ((e_flags & EF_M32R_ARCH) == E_M32R_ARCH) |
| strcat (buf, ", m32r"); |
| |
| break; |
| |
| case EM_MIPS: |
| case EM_MIPS_RS3_LE: |
| if (e_flags & EF_MIPS_NOREORDER) |
| strcat (buf, ", noreorder"); |
| |
| if (e_flags & EF_MIPS_PIC) |
| strcat (buf, ", pic"); |
| |
| if (e_flags & EF_MIPS_CPIC) |
| strcat (buf, ", cpic"); |
| |
| if (e_flags & EF_MIPS_ABI2) |
| strcat (buf, ", abi2"); |
| |
| if ((e_flags & EF_MIPS_ARCH) == E_MIPS_ARCH_1) |
| strcat (buf, ", mips1"); |
| |
| if ((e_flags & EF_MIPS_ARCH) == E_MIPS_ARCH_2) |
| strcat (buf, ", mips2"); |
| |
| if ((e_flags & EF_MIPS_ARCH) == E_MIPS_ARCH_3) |
| strcat (buf, ", mips3"); |
| |
| if ((e_flags & EF_MIPS_ARCH) == E_MIPS_ARCH_4) |
| strcat (buf, ", mips4"); |
| |
| if ((e_flags & EF_MIPS_ARCH) == E_MIPS_ARCH_5) |
| strcat (buf, ", mips5"); |
| |
| if ((e_flags & EF_MIPS_ARCH) == E_MIPS_ARCH_32) |
| strcat (buf, ", mips32"); |
| |
| if ((e_flags & EF_MIPS_ARCH) == E_MIPS_ARCH_64) |
| strcat (buf, ", mips64"); |
| |
| switch ((e_flags & EF_MIPS_MACH)) |
| { |
| case E_MIPS_MACH_3900: strcat (buf, ", 3900"); break; |
| case E_MIPS_MACH_4010: strcat (buf, ", 4010"); break; |
| case E_MIPS_MACH_4100: strcat (buf, ", 4100"); break; |
| case E_MIPS_MACH_4650: strcat (buf, ", 4650"); break; |
| case E_MIPS_MACH_4111: strcat (buf, ", 4111"); break; |
| case E_MIPS_MACH_MIPS32_4K: strcat (buf, ", mips32-4k"); break; |
| case E_MIPS_MACH_SB1: strcat (buf, ", sb1"); break; |
| default: strcat (buf, " UNKNOWN"); break; |
| } |
| break; |
| |
| case EM_SPARCV9: |
| if (e_flags & EF_SPARC_32PLUS) |
| strcat (buf, ", v8+"); |
| |
| if (e_flags & EF_SPARC_SUN_US1) |
| strcat (buf, ", ultrasparcI"); |
| |
| if (e_flags & EF_SPARC_SUN_US3) |
| strcat (buf, ", ultrasparcIII"); |
| |
| if (e_flags & EF_SPARC_HAL_R1) |
| strcat (buf, ", halr1"); |
| |
| if (e_flags & EF_SPARC_LEDATA) |
| strcat (buf, ", ledata"); |
| |
| if ((e_flags & EF_SPARCV9_MM) == EF_SPARCV9_TSO) |
| strcat (buf, ", tso"); |
| |
| if ((e_flags & EF_SPARCV9_MM) == EF_SPARCV9_PSO) |
| strcat (buf, ", pso"); |
| |
| if ((e_flags & EF_SPARCV9_MM) == EF_SPARCV9_RMO) |
| strcat (buf, ", rmo"); |
| break; |
| |
| case EM_PARISC: |
| switch (e_flags & EF_PARISC_ARCH) |
| { |
| case EFA_PARISC_1_0: |
| strcpy (buf, ", PA-RISC 1.0"); |
| break; |
| case EFA_PARISC_1_1: |
| strcpy (buf, ", PA-RISC 1.1"); |
| break; |
| case EFA_PARISC_2_0: |
| strcpy (buf, ", PA-RISC 2.0"); |
| break; |
| default: |
| break; |
| } |
| if (e_flags & EF_PARISC_TRAPNIL) |
| strcat (buf, ", trapnil"); |
| if (e_flags & EF_PARISC_EXT) |
| strcat (buf, ", ext"); |
| if (e_flags & EF_PARISC_LSB) |
| strcat (buf, ", lsb"); |
| if (e_flags & EF_PARISC_WIDE) |
| strcat (buf, ", wide"); |
| if (e_flags & EF_PARISC_NO_KABP) |
| strcat (buf, ", no kabp"); |
| if (e_flags & EF_PARISC_LAZYSWAP) |
| strcat (buf, ", lazyswap"); |
| break; |
| |
| case EM_PJ: |
| if ((e_flags & EF_PICOJAVA_NEWCALLS) == EF_PICOJAVA_NEWCALLS) |
| strcat (buf, ", new calling convention"); |
| |
| if ((e_flags & EF_PICOJAVA_GNUCALLS) == EF_PICOJAVA_GNUCALLS) |
| strcat (buf, ", gnu calling convention"); |
| break; |
| |
| case EM_IA_64: |
| if ((e_flags & EF_IA_64_ABI64)) |
| strcat (buf, ", 64-bit"); |
| else |
| strcat (buf, ", 32-bit"); |
| if ((e_flags & EF_IA_64_REDUCEDFP)) |
| strcat (buf, ", reduced fp model"); |
| if ((e_flags & EF_IA_64_NOFUNCDESC_CONS_GP)) |
| strcat (buf, ", no function descriptors, constant gp"); |
| else if ((e_flags & EF_IA_64_CONS_GP)) |
| strcat (buf, ", constant gp"); |
| if ((e_flags & EF_IA_64_ABSOLUTE)) |
| strcat (buf, ", absolute"); |
| break; |
| } |
| } |
| |
| return buf; |
| } |
| |
| static const char * |
| get_mips_segment_type (type) |
| unsigned long type; |
| { |
| switch (type) |
| { |
| case PT_MIPS_REGINFO: |
| return "REGINFO"; |
| case PT_MIPS_RTPROC: |
| return "RTPROC"; |
| case PT_MIPS_OPTIONS: |
| return "OPTIONS"; |
| default: |
| break; |
| } |
| |
| return NULL; |
| } |
| |
| static const char * |
| get_parisc_segment_type (type) |
| unsigned long type; |
| { |
| switch (type) |
| { |
| case PT_HP_TLS: return "HP_TLS"; |
| case PT_HP_CORE_NONE: return "HP_CORE_NONE"; |
| case PT_HP_CORE_VERSION: return "HP_CORE_VERSION"; |
| case PT_HP_CORE_KERNEL: return "HP_CORE_KERNEL"; |
| case PT_HP_CORE_COMM: return "HP_CORE_COMM"; |
| case PT_HP_CORE_PROC: return "HP_CORE_PROC"; |
| case PT_HP_CORE_LOADABLE: return "HP_CORE_LOADABLE"; |
| case PT_HP_CORE_STACK: return "HP_CORE_STACK"; |
| case PT_HP_CORE_SHM: return "HP_CORE_SHM"; |
| case PT_HP_CORE_MMF: return "HP_CORE_MMF"; |
| case PT_HP_PARALLEL: return "HP_PARALLEL"; |
| case PT_HP_FASTBIND: return "HP_FASTBIND"; |
| case PT_PARISC_ARCHEXT: return "PARISC_ARCHEXT"; |
| case PT_PARISC_UNWIND: return "PARISC_UNWIND"; |
| default: |
| break; |
| } |
| |
| return NULL; |
| } |
| |
| static const char * |
| get_ia64_segment_type (type) |
| unsigned long type; |
| { |
| switch (type) |
| { |
| case PT_IA_64_ARCHEXT: return "IA_64_ARCHEXT"; |
| case PT_IA_64_UNWIND: return "IA_64_UNWIND"; |
| default: |
| break; |
| } |
| |
| return NULL; |
| } |
| |
| static const char * |
| get_segment_type (p_type) |
| unsigned long p_type; |
| { |
| static char buff [32]; |
| |
| switch (p_type) |
| { |
| case PT_NULL: return "NULL"; |
| case PT_LOAD: return "LOAD"; |
| case PT_DYNAMIC: return "DYNAMIC"; |
| case PT_INTERP: return "INTERP"; |
| case PT_NOTE: return "NOTE"; |
| case PT_SHLIB: return "SHLIB"; |
| case PT_PHDR: return "PHDR"; |
| |
| default: |
| if ((p_type >= PT_LOPROC) && (p_type <= PT_HIPROC)) |
| { |
| const char * result; |
| |
| switch (elf_header.e_machine) |
| { |
| case EM_MIPS: |
| case EM_MIPS_RS3_LE: |
| result = get_mips_segment_type (p_type); |
| break; |
| case EM_PARISC: |
| result = get_parisc_segment_type (p_type); |
| break; |
| case EM_IA_64: |
| result = get_ia64_segment_type (p_type); |
| break; |
| default: |
| result = NULL; |
| break; |
| } |
| |
| if (result != NULL) |
| return result; |
| |
| sprintf (buff, "LOPROC+%lx", p_type - PT_LOPROC); |
| } |
| else if ((p_type >= PT_LOOS) && (p_type <= PT_HIOS)) |
| { |
| const char * result; |
| |
| switch (elf_header.e_machine) |
| { |
| case EM_PARISC: |
| result = get_parisc_segment_type (p_type); |
| break; |
| default: |
| result = NULL; |
| break; |
| } |
| |
| if (result != NULL) |
| return result; |
| |
| sprintf (buff, "LOOS+%lx", p_type - PT_LOOS); |
| } |
| else |
| sprintf (buff, _("<unknown>: %lx"), p_type); |
| |
| return buff; |
| } |
| } |
| |
| static const char * |
| get_mips_section_type_name (sh_type) |
| unsigned int sh_type; |
| { |
| switch (sh_type) |
| { |
| case SHT_MIPS_LIBLIST: return "MIPS_LIBLIST"; |
| case SHT_MIPS_MSYM: return "MIPS_MSYM"; |
| case SHT_MIPS_CONFLICT: return "MIPS_CONFLICT"; |
| case SHT_MIPS_GPTAB: return "MIPS_GPTAB"; |
| case SHT_MIPS_UCODE: return "MIPS_UCODE"; |
| case SHT_MIPS_DEBUG: return "MIPS_DEBUG"; |
| case SHT_MIPS_REGINFO: return "MIPS_REGINFO"; |
| case SHT_MIPS_PACKAGE: return "MIPS_PACKAGE"; |
| case SHT_MIPS_PACKSYM: return "MIPS_PACKSYM"; |
| case SHT_MIPS_RELD: return "MIPS_RELD"; |
| case SHT_MIPS_IFACE: return "MIPS_IFACE"; |
| case SHT_MIPS_CONTENT: return "MIPS_CONTENT"; |
| case SHT_MIPS_OPTIONS: return "MIPS_OPTIONS"; |
| case SHT_MIPS_SHDR: return "MIPS_SHDR"; |
| case SHT_MIPS_FDESC: return "MIPS_FDESC"; |
| case SHT_MIPS_EXTSYM: return "MIPS_EXTSYM"; |
| case SHT_MIPS_DENSE: return "MIPS_DENSE"; |
| case SHT_MIPS_PDESC: return "MIPS_PDESC"; |
| case SHT_MIPS_LOCSYM: return "MIPS_LOCSYM"; |
| case SHT_MIPS_AUXSYM: return "MIPS_AUXSYM"; |
| case SHT_MIPS_OPTSYM: return "MIPS_OPTSYM"; |
| case SHT_MIPS_LOCSTR: return "MIPS_LOCSTR"; |
| case SHT_MIPS_LINE: return "MIPS_LINE"; |
| case SHT_MIPS_RFDESC: return "MIPS_RFDESC"; |
| case SHT_MIPS_DELTASYM: return "MIPS_DELTASYM"; |
| case SHT_MIPS_DELTAINST: return "MIPS_DELTAINST"; |
| case SHT_MIPS_DELTACLASS: return "MIPS_DELTACLASS"; |
| case SHT_MIPS_DWARF: return "MIPS_DWARF"; |
| case SHT_MIPS_DELTADECL: return "MIPS_DELTADECL"; |
| case SHT_MIPS_SYMBOL_LIB: return "MIPS_SYMBOL_LIB"; |
| case SHT_MIPS_EVENTS: return "MIPS_EVENTS"; |
| case SHT_MIPS_TRANSLATE: return "MIPS_TRANSLATE"; |
| case SHT_MIPS_PIXIE: return "MIPS_PIXIE"; |
| case SHT_MIPS_XLATE: return "MIPS_XLATE"; |
| case SHT_MIPS_XLATE_DEBUG: return "MIPS_XLATE_DEBUG"; |
| case SHT_MIPS_WHIRL: return "MIPS_WHIRL"; |
| case SHT_MIPS_EH_REGION: return "MIPS_EH_REGION"; |
| case SHT_MIPS_XLATE_OLD: return "MIPS_XLATE_OLD"; |
| case SHT_MIPS_PDR_EXCEPTION: return "MIPS_PDR_EXCEPTION"; |
| default: |
| break; |
| } |
| return NULL; |
| } |
| |
| static const char * |
| get_parisc_section_type_name (sh_type) |
| unsigned int sh_type; |
| { |
| switch (sh_type) |
| { |
| case SHT_PARISC_EXT: return "PARISC_EXT"; |
| case SHT_PARISC_UNWIND: return "PARISC_UNWIND"; |
| case SHT_PARISC_DOC: return "PARISC_DOC"; |
| default: |
| break; |
| } |
| return NULL; |
| } |
| |
| static const char * |
| get_ia64_section_type_name (sh_type) |
| unsigned int sh_type; |
| { |
| switch (sh_type) |
| { |
| case SHT_IA_64_EXT: return "IA_64_EXT"; |
| case SHT_IA_64_UNWIND: return "IA_64_UNWIND"; |
| default: |
| break; |
| } |
| return NULL; |
| } |
| |
| static const char * |
| get_section_type_name (sh_type) |
| unsigned int sh_type; |
| { |
| static char buff [32]; |
| |
| switch (sh_type) |
| { |
| case SHT_NULL: return "NULL"; |
| case SHT_PROGBITS: return "PROGBITS"; |
| case SHT_SYMTAB: return "SYMTAB"; |
| case SHT_STRTAB: return "STRTAB"; |
| case SHT_RELA: return "RELA"; |
| case SHT_HASH: return "HASH"; |
| case SHT_DYNAMIC: return "DYNAMIC"; |
| case SHT_NOTE: return "NOTE"; |
| case SHT_NOBITS: return "NOBITS"; |
| case SHT_REL: return "REL"; |
| case SHT_SHLIB: return "SHLIB"; |
| case SHT_DYNSYM: return "DYNSYM"; |
| case SHT_INIT_ARRAY: return "INIT_ARRAY"; |
| case SHT_FINI_ARRAY: return "FINI_ARRAY"; |
| case SHT_PREINIT_ARRAY: return "PREINIT_ARRAY"; |
| case SHT_GROUP: return "GROUP"; |
| case SHT_SYMTAB_SHNDX: return "SYMTAB SECTION INDICIES"; |
| case SHT_GNU_verdef: return "VERDEF"; |
| case SHT_GNU_verneed: return "VERNEED"; |
| case SHT_GNU_versym: return "VERSYM"; |
| case 0x6ffffff0: return "VERSYM"; |
| case 0x6ffffffc: return "VERDEF"; |
| case 0x7ffffffd: return "AUXILIARY"; |
| case 0x7fffffff: return "FILTER"; |
| |
| default: |
| if ((sh_type >= SHT_LOPROC) && (sh_type <= SHT_HIPROC)) |
| { |
| const char * result; |
| |
| switch (elf_header.e_machine) |
| { |
| case EM_MIPS: |
| case EM_MIPS_RS3_LE: |
| result = get_mips_section_type_name (sh_type); |
| break; |
| case EM_PARISC: |
| result = get_parisc_section_type_name (sh_type); |
| break; |
| case EM_IA_64: |
| result = get_ia64_section_type_name (sh_type); |
| break; |
| default: |
| result = NULL; |
| break; |
| } |
| |
| if (result != NULL) |
| return result; |
| |
| sprintf (buff, "SHT_LOPROC+%x", sh_type - SHT_LOPROC); |
| } |
| else if ((sh_type >= SHT_LOOS) && (sh_type <= SHT_HIOS)) |
| sprintf (buff, "SHT_LOOS+%x", sh_type - SHT_LOOS); |
| else if ((sh_type >= SHT_LOUSER) && (sh_type <= SHT_HIUSER)) |
| sprintf (buff, "SHT_LOUSER+%x", sh_type - SHT_LOUSER); |
| else |
| sprintf (buff, _("<unknown>: %x"), sh_type); |
| |
| return buff; |
| } |
| } |
| |
| struct option options [] = |
| { |
| {"all", no_argument, 0, 'a'}, |
| {"file-header", no_argument, 0, 'h'}, |
| {"program-headers", no_argument, 0, 'l'}, |
| {"headers", no_argument, 0, 'e'}, |
| {"histogram", no_argument, 0, 'I'}, |
| {"segments", no_argument, 0, 'l'}, |
| {"sections", no_argument, 0, 'S'}, |
| {"section-headers", no_argument, 0, 'S'}, |
| {"symbols", no_argument, 0, 's'}, |
| {"syms", no_argument, 0, 's'}, |
| {"relocs", no_argument, 0, 'r'}, |
| {"notes", no_argument, 0, 'n'}, |
| {"dynamic", no_argument, 0, 'd'}, |
| {"arch-specific", no_argument, 0, 'A'}, |
| {"version-info", no_argument, 0, 'V'}, |
| {"use-dynamic", no_argument, 0, 'D'}, |
| {"hex-dump", required_argument, 0, 'x'}, |
| {"debug-dump", optional_argument, 0, 'w'}, |
| {"unwind", no_argument, 0, 'u'}, |
| #ifdef SUPPORT_DISASSEMBLY |
| {"instruction-dump", required_argument, 0, 'i'}, |
| #endif |
| |
| {"version", no_argument, 0, 'v'}, |
| {"help", no_argument, 0, 'H'}, |
| {0, no_argument, 0, 0} |
| }; |
| |
| static void |
| usage () |
| { |
| fprintf (stdout, _("Usage: readelf {options} elf-file(s)\n")); |
| fprintf (stdout, _(" Options are:\n")); |
| fprintf (stdout, _(" -a or --all Equivalent to: -h -l -S -s -r -d -V -A -I\n")); |
| fprintf (stdout, _(" -h or --file-header Display the ELF file header\n")); |
| fprintf (stdout, _(" -l or --program-headers or --segments\n")); |
| fprintf (stdout, _(" Display the program headers\n")); |
| fprintf (stdout, _(" -S or --section-headers or --sections\n")); |
| fprintf (stdout, _(" Display the sections' header\n")); |
| fprintf (stdout, _(" -e or --headers Equivalent to: -h -l -S\n")); |
| fprintf (stdout, _(" -s or --syms or --symbols Display the symbol table\n")); |
| fprintf (stdout, _(" -n or --notes Display the core notes (if present)\n")); |
| fprintf (stdout, _(" -r or --relocs Display the relocations (if present)\n")); |
| fprintf (stdout, _(" -u or --unwind Display the unwind info (if present)\n")); |
| fprintf (stdout, _(" -d or --dynamic Display the dynamic segment (if present)\n")); |
| fprintf (stdout, _(" -V or --version-info Display the version sections (if present)\n")); |
| fprintf (stdout, _(" -A or --arch-specific Display architecture specific information (if any).\n")); |
| fprintf (stdout, _(" -D or --use-dynamic Use the dynamic section info when displaying symbols\n")); |
| fprintf (stdout, _(" -x <number> or --hex-dump=<number>\n")); |
| fprintf (stdout, _(" Dump the contents of section <number>\n")); |
| fprintf (stdout, _(" -w[liaprf] or --debug-dump[=line,=info,=abbrev,=pubnames,=ranges,=frames]\n")); |
| fprintf (stdout, _(" Display the contents of DWARF2 debug sections\n")); |
| #ifdef SUPPORT_DISASSEMBLY |
| fprintf (stdout, _(" -i <number> or --instruction-dump=<number>\n")); |
| fprintf (stdout, _(" Disassemble the contents of section <number>\n")); |
| #endif |
| fprintf (stdout, _(" -I or --histogram Display histogram of bucket list lengths\n")); |
| fprintf (stdout, _(" -v or --version Display the version number of readelf\n")); |
| fprintf (stdout, _(" -H or --help Display this information\n")); |
| fprintf (stdout, _("Report bugs to %s\n"), REPORT_BUGS_TO); |
| |
| exit (0); |
| } |
| |
| static void |
| request_dump (section, type) |
| unsigned int section; |
| char type; |
| { |
| if (section >= num_dump_sects) |
| { |
| char * new_dump_sects; |
| |
| new_dump_sects = (char *) calloc (section + 1, 1); |
| |
| if (new_dump_sects == NULL) |
| error (_("Out of memory allocating dump request table.")); |
| else |
| { |
| /* Copy current flag settings. */ |
| memcpy (new_dump_sects, dump_sects, num_dump_sects); |
| |
| free (dump_sects); |
| |
| dump_sects = new_dump_sects; |
| num_dump_sects = section + 1; |
| } |
| } |
| |
| if (dump_sects) |
| dump_sects [section] |= type; |
| |
| return; |
| } |
| |
| static void |
| parse_args (argc, argv) |
| int argc; |
| char ** argv; |
| { |
| int c; |
| |
| if (argc < 2) |
| usage (); |
| |
| while ((c = getopt_long |
| (argc, argv, "ersuahnldSDAIw::x:i:vV", options, NULL)) != EOF) |
| { |
| char * cp; |
| int section; |
| |
| switch (c) |
| { |
| case 0: |
| /* Long options. */ |
| break; |
| case 'H': |
| usage (); |
| break; |
| |
| case 'a': |
| do_syms ++; |
| do_reloc ++; |
| do_unwind ++; |
| do_dynamic ++; |
| do_header ++; |
| do_sections ++; |
| do_segments ++; |
| do_version ++; |
| do_histogram ++; |
| do_arch ++; |
| do_notes ++; |
| break; |
| case 'e': |
| do_header ++; |
| do_sections ++; |
| do_segments ++; |
| break; |
| case 'A': |
| do_arch ++; |
| break; |
| case 'D': |
| do_using_dynamic ++; |
| break; |
| case 'r': |
| do_reloc ++; |
| break; |
| case 'u': |
| do_unwind ++; |
| break; |
| case 'h': |
| do_header ++; |
| break; |
| case 'l': |
| do_segments ++; |
| break; |
| case 's': |
| do_syms ++; |
| break; |
| case 'S': |
| do_sections ++; |
| break; |
| case 'd': |
| do_dynamic ++; |
| break; |
| case 'I': |
| do_histogram ++; |
| break; |
| case 'n': |
| do_notes ++; |
| break; |
| case 'x': |
| do_dump ++; |
| section = strtoul (optarg, & cp, 0); |
| if (! * cp && section >= 0) |
| { |
| request_dump (section, HEX_DUMP); |
| break; |
| } |
| goto oops; |
| case 'w': |
| do_dump ++; |
| if (optarg == 0) |
| do_debugging = 1; |
| else |
| { |
| do_debugging = 0; |
| switch (optarg[0]) |
| { |
| case 'i': |
| case 'I': |
| do_debug_info = 1; |
| break; |
| |
| case 'a': |
| case 'A': |
| do_debug_abbrevs = 1; |
| break; |
| |
| case 'l': |
| case 'L': |
| do_debug_lines = 1; |
| break; |
| |
| case 'p': |
| case 'P': |
| do_debug_pubnames = 1; |
| break; |
| |
| case 'r': |
| case 'R': |
| do_debug_aranges = 1; |
| break; |
| |
| case 'F': |
| do_debug_frames_interp = 1; |
| case 'f': |
| do_debug_frames = 1; |
| break; |
| |
| default: |
| warn (_("Unrecognised debug option '%s'\n"), optarg); |
| break; |
| } |
| } |
| break; |
| #ifdef SUPPORT_DISASSEMBLY |
| case 'i': |
| do_dump ++; |
| section = strtoul (optarg, & cp, 0); |
| if (! * cp && section >= 0) |
| { |
| request_dump (section, DISASS_DUMP); |
| break; |
| } |
| goto oops; |
| #endif |
| case 'v': |
| print_version (program_name); |
| break; |
| case 'V': |
| do_version ++; |
| break; |
| default: |
| oops: |
| /* xgettext:c-format */ |
| error (_("Invalid option '-%c'\n"), c); |
| /* Drop through. */ |
| case '?': |
| usage (); |
| } |
| } |
| |
| if (!do_dynamic && !do_syms && !do_reloc && !do_unwind && !do_sections |
| && !do_segments && !do_header && !do_dump && !do_version |
| && !do_histogram && !do_debugging && !do_arch && !do_notes) |
| usage (); |
| else if (argc < 3) |
| { |
| warn (_("Nothing to do.\n")); |
| usage(); |
| } |
| } |
| |
| static const char * |
| get_elf_class (elf_class) |
| unsigned char elf_class; |
| { |
| static char buff [32]; |
| |
| switch (elf_class) |
| { |
| case ELFCLASSNONE: return _("none"); |
| case ELFCLASS32: return _("ELF32"); |
| case ELFCLASS64: return _("ELF64"); |
| default: |
| sprintf (buff, _("<unknown: %x>"), elf_class); |
| return buff; |
| } |
| } |
| |
| static const char * |
| get_data_encoding (encoding) |
| unsigned char encoding; |
| { |
| static char buff [32]; |
| |
| switch (encoding) |
| { |
| case ELFDATANONE: return _("none"); |
| case ELFDATA2LSB: return _("2's complement, little endian"); |
| case ELFDATA2MSB: return _("2's complement, big endian"); |
| default: |
| sprintf (buff, _("<unknown: %x>"), encoding); |
| return buff; |
| } |
| } |
| |
| static const char * |
| get_osabi_name (osabi) |
| unsigned char osabi; |
| { |
| static char buff [32]; |
| |
| switch (osabi) |
| { |
| case ELFOSABI_NONE: return _("UNIX - System V"); |
| case ELFOSABI_HPUX: return _("UNIX - HP-UX"); |
| case ELFOSABI_NETBSD: return _("UNIX - NetBSD"); |
| case ELFOSABI_LINUX: return _("UNIX - Linux"); |
| case ELFOSABI_HURD: return _("GNU/Hurd"); |
| case ELFOSABI_SOLARIS: return _("UNIX - Solaris"); |
| case ELFOSABI_AIX: return _("UNIX - AIX"); |
| case ELFOSABI_IRIX: return _("UNIX - IRIX"); |
| case ELFOSABI_FREEBSD: return _("UNIX - FreeBSD"); |
| case ELFOSABI_TRU64: return _("UNIX - TRU64"); |
| case ELFOSABI_MODESTO: return _("Novell - Modesto"); |
| case ELFOSABI_OPENBSD: return _("UNIX - OpenBSD"); |
| case ELFOSABI_STANDALONE: return _("Standalone App"); |
| case ELFOSABI_ARM: return _("ARM"); |
| default: |
| sprintf (buff, _("<unknown: %x>"), osabi); |
| return buff; |
| } |
| } |
| |
| /* Decode the data held in 'elf_header'. */ |
| static int |
| process_file_header () |
| { |
| if ( elf_header.e_ident [EI_MAG0] != ELFMAG0 |
| || elf_header.e_ident [EI_MAG1] != ELFMAG1 |
| || elf_header.e_ident [EI_MAG2] != ELFMAG2 |
| || elf_header.e_ident [EI_MAG3] != ELFMAG3) |
| { |
| error |
| (_("Not an ELF file - it has the wrong magic bytes at the start\n")); |
| return 0; |
| } |
| |
| if (do_header) |
| { |
| int i; |
| |
| printf (_("ELF Header:\n")); |
| printf (_(" Magic: ")); |
| for (i = 0; i < EI_NIDENT; i ++) |
| printf ("%2.2x ", elf_header.e_ident [i]); |
| printf ("\n"); |
| printf (_(" Class: %s\n"), |
| get_elf_class (elf_header.e_ident [EI_CLASS])); |
| printf (_(" Data: %s\n"), |
| get_data_encoding (elf_header.e_ident [EI_DATA])); |
| printf (_(" Version: %d %s\n"), |
| elf_header.e_ident [EI_VERSION], |
| (elf_header.e_ident [EI_VERSION] == EV_CURRENT |
| ? "(current)" |
| : (elf_header.e_ident [EI_VERSION] != EV_NONE |
| ? "<unknown: %lx>" |
| : ""))); |
| printf (_(" OS/ABI: %s\n"), |
| get_osabi_name (elf_header.e_ident [EI_OSABI])); |
| printf (_(" ABI Version: %d\n"), |
| elf_header.e_ident [EI_ABIVERSION]); |
| printf (_(" Type: %s\n"), |
| get_file_type (elf_header.e_type)); |
| printf (_(" Machine: %s\n"), |
| get_machine_name (elf_header.e_machine)); |
| printf (_(" Version: 0x%lx\n"), |
| (unsigned long) elf_header.e_version); |
| |
| printf (_(" Entry point address: ")); |
| print_vma ((bfd_vma) elf_header.e_entry, PREFIX_HEX); |
| printf (_("\n Start of program headers: ")); |
| print_vma ((bfd_vma) elf_header.e_phoff, DEC); |
| printf (_(" (bytes into file)\n Start of section headers: ")); |
| print_vma ((bfd_vma) elf_header.e_shoff, DEC); |
| printf (_(" (bytes into file)\n")); |
| |
| printf (_(" Flags: 0x%lx%s\n"), |
| (unsigned long) elf_header.e_flags, |
| get_machine_flags (elf_header.e_flags, elf_header.e_machine)); |
| printf (_(" Size of this header: %ld (bytes)\n"), |
| (long) elf_header.e_ehsize); |
| printf (_(" Size of program headers: %ld (bytes)\n"), |
| (long) elf_header.e_phentsize); |
| printf (_(" Number of program headers: %ld\n"), |
| (long) elf_header.e_phnum); |
| printf (_(" Size of section headers: %ld (bytes)\n"), |
| (long) elf_header.e_shentsize); |
| printf (_(" Number of section headers: %ld\n"), |
| (long) elf_header.e_shnum); |
| printf (_(" Section header string table index: %ld\n"), |
| (long) elf_header.e_shstrndx); |
| } |
| |
| return 1; |
| } |
| |
| |
| static int |
| get_32bit_program_headers (file, program_headers) |
| FILE * file; |
| Elf_Internal_Phdr * program_headers; |
| { |
| Elf32_External_Phdr * phdrs; |
| Elf32_External_Phdr * external; |
| Elf32_Internal_Phdr * internal; |
| unsigned int i; |
| |
| GET_DATA_ALLOC (elf_header.e_phoff, |
| elf_header.e_phentsize * elf_header.e_phnum, |
| phdrs, Elf32_External_Phdr *, "program headers"); |
| |
| for (i = 0, internal = program_headers, external = phdrs; |
| i < elf_header.e_phnum; |
| i ++, internal ++, external ++) |
| { |
| internal->p_type = BYTE_GET (external->p_type); |
| internal->p_offset = BYTE_GET (external->p_offset); |
| internal->p_vaddr = BYTE_GET (external->p_vaddr); |
| internal->p_paddr = BYTE_GET (external->p_paddr); |
| internal->p_filesz = BYTE_GET (external->p_filesz); |
| internal->p_memsz = BYTE_GET (external->p_memsz); |
| internal->p_flags = BYTE_GET (external->p_flags); |
| internal->p_align = BYTE_GET (external->p_align); |
| } |
| |
| free (phdrs); |
| |
| return 1; |
| } |
| |
| static int |
| get_64bit_program_headers (file, program_headers) |
| FILE * file; |
| Elf_Internal_Phdr * program_headers; |
| { |
| Elf64_External_Phdr * phdrs; |
| Elf64_External_Phdr * external; |
| Elf64_Internal_Phdr * internal; |
| unsigned int i; |
| |
| GET_DATA_ALLOC (elf_header.e_phoff, |
| elf_header.e_phentsize * elf_header.e_phnum, |
| phdrs, Elf64_External_Phdr *, "program headers"); |
| |
| for (i = 0, internal = program_headers, external = phdrs; |
| i < elf_header.e_phnum; |
| i ++, internal ++, external ++) |
| { |
| internal->p_type = BYTE_GET (external->p_type); |
| internal->p_flags = BYTE_GET (external->p_flags); |
| internal->p_offset = BYTE_GET8 (external->p_offset); |
| internal->p_vaddr = BYTE_GET8 (external->p_vaddr); |
| internal->p_paddr = BYTE_GET8 (external->p_paddr); |
| internal->p_filesz = BYTE_GET8 (external->p_filesz); |
| internal->p_memsz = BYTE_GET8 (external->p_memsz); |
| internal->p_align = BYTE_GET8 (external->p_align); |
| } |
| |
| free (phdrs); |
| |
| return 1; |
| } |
| |
| static int |
| process_program_headers (file) |
| FILE * file; |
| { |
| Elf_Internal_Phdr * program_headers; |
| Elf_Internal_Phdr * segment; |
| unsigned int i; |
| |
| if (elf_header.e_phnum == 0) |
| { |
| if (do_segments) |
| printf (_("\nThere are no program headers in this file.\n")); |
| return 1; |
| } |
| |
| if (do_segments && !do_header) |
| { |
| printf (_("\nElf file type is %s\n"), get_file_type (elf_header.e_type)); |
| printf (_("Entry point ")); |
| print_vma ((bfd_vma) elf_header.e_entry, PREFIX_HEX); |
| printf (_("\nThere are %d program headers, starting at offset "), |
| elf_header.e_phnum); |
| print_vma ((bfd_vma) elf_header.e_phoff, DEC); |
| printf ("\n"); |
| } |
| |
| program_headers = (Elf_Internal_Phdr *) malloc |
| (elf_header.e_phnum * sizeof (Elf_Internal_Phdr)); |
| |
| if (program_headers == NULL) |
| { |
| error (_("Out of memory\n")); |
| return 0; |
| } |
| |
| if (is_32bit_elf) |
| i = get_32bit_program_headers (file, program_headers); |
| else |
| i = get_64bit_program_headers (file, program_headers); |
| |
| if (i == 0) |
| { |
| free (program_headers); |
| return 0; |
| } |
| |
| if (do_segments) |
| { |
| printf |
| (_("\nProgram Header%s:\n"), elf_header.e_phnum > 1 ? "s" : ""); |
| |
| if (is_32bit_elf) |
| printf |
| (_(" Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align\n")); |
| else |
| { |
| printf |
| (_(" Type Offset VirtAddr PhysAddr\n")); |
| printf |
| (_(" FileSiz MemSiz Flags Align\n")); |
| } |
| } |
| |
| loadaddr = -1; |
| dynamic_addr = 0; |
| dynamic_size = 0; |
| |
| for (i = 0, segment = program_headers; |
| i < elf_header.e_phnum; |
| i ++, segment ++) |
| { |
| if (do_segments) |
| { |
| printf (" %-14.14s ", get_segment_type (segment->p_type)); |
| |
| if (is_32bit_elf) |
| { |
| printf ("0x%6.6lx ", (unsigned long) segment->p_offset); |
| printf ("0x%8.8lx ", (unsigned long) segment->p_vaddr); |
| printf ("0x%8.8lx ", (unsigned long) segment->p_paddr); |
| printf ("0x%5.5lx ", (unsigned long) segment->p_filesz); |
| printf ("0x%5.5lx ", (unsigned long) segment->p_memsz); |
| printf ("%c%c%c ", |
| (segment->p_flags & PF_R ? 'R' : ' '), |
| (segment->p_flags & PF_W ? 'W' : ' '), |
| (segment->p_flags & PF_X ? 'E' : ' ')); |
| printf ("%#lx", (unsigned long) segment->p_align); |
| } |
| else |
| { |
| print_vma (segment->p_offset, FULL_HEX); |
| putchar (' '); |
| print_vma (segment->p_vaddr, FULL_HEX); |
| putchar (' '); |
| print_vma (segment->p_paddr, FULL_HEX); |
| printf ("\n "); |
| print_vma (segment->p_filesz, FULL_HEX); |
| putchar (' '); |
| print_vma (segment->p_memsz, FULL_HEX); |
| printf (" %c%c%c ", |
| (segment->p_flags & PF_R ? 'R' : ' '), |
| (segment->p_flags & PF_W ? 'W' : ' '), |
| (segment->p_flags & PF_X ? 'E' : ' ')); |
| print_vma (segment->p_align, HEX); |
| } |
| } |
| |
| switch (segment->p_type) |
| { |
| case PT_LOAD: |
| if (loadaddr == -1) |
| loadaddr = (segment->p_vaddr & 0xfffff000) |
| - (segment->p_offset & 0xfffff000); |
| break; |
| |
| case PT_DYNAMIC: |
| if (dynamic_addr) |
| error (_("more than one dynamic segment\n")); |
| |
| dynamic_addr = segment->p_offset; |
| dynamic_size = segment->p_filesz; |
| break; |
| |
| case PT_INTERP: |
| if (fseek (file, (long) segment->p_offset, SEEK_SET)) |
| error (_("Unable to find program interpreter name\n")); |
| else |
| { |
| program_interpreter[0] = 0; |
| fscanf (file, "%63s", program_interpreter); |
| |
| if (do_segments) |
| printf (_("\n [Requesting program interpreter: %s]"), |
| program_interpreter); |
| } |
| break; |
| } |
| |
| if (do_segments) |
| putc ('\n', stdout); |
| } |
| |
| if (loadaddr == -1) |
| { |
| /* Very strange. */ |
| loadaddr = 0; |
| } |
| |
| if (do_segments && section_headers != NULL) |
| { |
| printf (_("\n Section to Segment mapping:\n")); |
| printf (_(" Segment Sections...\n")); |
| |
| assert (string_table != NULL); |
| |
| for (i = 0; i < elf_header.e_phnum; i++) |
| { |
| int j; |
| Elf_Internal_Shdr * section; |
| |
| segment = program_headers + i; |
| section = section_headers; |
| |
| printf (" %2.2d ", i); |
| |
| for (j = 0; j < elf_header.e_shnum; j++, section ++) |
| { |
| if (section->sh_size > 0 |
| /* Compare allocated sections by VMA, unallocated |
| sections by file offset. */ |
| && (section->sh_flags & SHF_ALLOC |
| ? (section->sh_addr >= segment->p_vaddr |
| && section->sh_addr + section->sh_size |
| <= segment->p_vaddr + segment->p_memsz) |
| : ((bfd_vma) section->sh_offset >= segment->p_offset |
| && (section->sh_offset + section->sh_size |
| <= segment->p_offset + segment->p_filesz)))) |
| printf ("%s ", SECTION_NAME (section)); |
| } |
| |
| putc ('\n',stdout); |
| } |
| } |
| |
| free (program_headers); |
| |
| return 1; |
| } |
| |
| |
| static int |
| get_32bit_section_headers (file) |
| FILE * file; |
| { |
| Elf32_External_Shdr * shdrs; |
| Elf32_Internal_Shdr * internal; |
| unsigned int i; |
| |
| GET_DATA_ALLOC (elf_header.e_shoff, |
| elf_header.e_shentsize * elf_header.e_shnum, |
| shdrs, Elf32_External_Shdr *, "section headers"); |
| |
| section_headers = (Elf_Internal_Shdr *) malloc |
| (elf_header.e_shnum * sizeof (Elf_Internal_Shdr)); |
| |
| if (section_headers == NULL) |
| { |
| error (_("Out of memory\n")); |
| return 0; |
| } |
| |
| for (i = 0, internal = section_headers; |
| i < elf_header.e_shnum; |
| i ++, internal ++) |
| { |
| internal->sh_name = BYTE_GET (shdrs[i].sh_name); |
| internal->sh_type = BYTE_GET (shdrs[i].sh_type); |
| internal->sh_flags = BYTE_GET (shdrs[i].sh_flags); |
| internal->sh_addr = BYTE_GET (shdrs[i].sh_addr); |
| internal->sh_offset = BYTE_GET (shdrs[i].sh_offset); |
| internal->sh_size = BYTE_GET (shdrs[i].sh_size); |
| internal->sh_link = BYTE_GET (shdrs[i].sh_link); |
| internal->sh_info = BYTE_GET (shdrs[i].sh_info); |
| internal->sh_addralign = BYTE_GET (shdrs[i].sh_addralign); |
| internal->sh_entsize = BYTE_GET (shdrs[i].sh_entsize); |
| } |
| |
| free (shdrs); |
| |
| return 1; |
| } |
| |
| static int |
| get_64bit_section_headers (file) |
| FILE * file; |
| { |
| Elf64_External_Shdr * shdrs; |
| Elf64_Internal_Shdr * internal; |
| unsigned int i; |
| |
| GET_DATA_ALLOC (elf_header.e_shoff, |
| elf_header.e_shentsize * elf_header.e_shnum, |
| shdrs, Elf64_External_Shdr *, "section headers"); |
| |
| section_headers = (Elf_Internal_Shdr *) malloc |
| (elf_header.e_shnum * sizeof (Elf_Internal_Shdr)); |
| |
| if (section_headers == NULL) |
| { |
| error (_("Out of memory\n")); |
| return 0; |
| } |
| |
| for (i = 0, internal = section_headers; |
| i < elf_header.e_shnum; |
| i ++, internal ++) |
| { |
| internal->sh_name = BYTE_GET (shdrs[i].sh_name); |
| internal->sh_type = BYTE_GET (shdrs[i].sh_type); |
| internal->sh_flags = BYTE_GET8 (shdrs[i].sh_flags); |
| internal->sh_addr = BYTE_GET8 (shdrs[i].sh_addr); |
| internal->sh_size = BYTE_GET8 (shdrs[i].sh_size); |
| internal->sh_entsize = BYTE_GET8 (shdrs[i].sh_entsize); |
| internal->sh_link = BYTE_GET (shdrs[i].sh_link); |
| internal->sh_info = BYTE_GET (shdrs[i].sh_info); |
| internal->sh_offset = BYTE_GET (shdrs[i].sh_offset); |
| internal->sh_addralign = BYTE_GET (shdrs[i].sh_addralign); |
| } |
| |
| free (shdrs); |
| |
| return 1; |
| } |
| |
| static Elf_Internal_Sym * |
| get_32bit_elf_symbols (file, offset, number) |
| FILE * file; |
| unsigned long offset; |
| unsigned long number; |
| { |
| Elf32_External_Sym * esyms; |
| Elf_Internal_Sym * isyms; |
| Elf_Internal_Sym * psym; |
|
|