/* readelf.c -- display contents of an ELF format file
- Copyright 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
+ Copyright 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
Originally developed by Eric Youngdale <eric@andante.jic.com>
Modifications by Nick Clifton <nickc@redhat.com>
/* Forward declarations for dumb compilers. */
static void print_vma PARAMS ((bfd_vma, print_mode));
+static void print_symbol PARAMS ((int, char *));
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_ppc64_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 const char * get_data_encoding PARAMS ((unsigned int));
static const char * get_osabi_name PARAMS ((unsigned int));
static int guess_is_rela PARAMS ((unsigned long));
-static char * get_note_type PARAMS ((unsigned int));
+static const char * get_note_type PARAMS ((unsigned int));
+static const char * get_netbsd_elfcore_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 *));
#endif
}
+/* Display a symbol on stdout. If do_wide is not true then
+ format the symbol to be at most WIDTH characters,
+ truhncating as necessary. If WIDTH is negative then
+ format the string to be exactly - WIDTH characters,
+ truncating or padding as necessary. */
+
+static void
+print_symbol (width, symbol)
+ int width;
+ char * symbol;
+{
+ if (do_wide)
+ printf (symbol);
+ else if (width < 0)
+ printf ("%-*.*s", width, width, symbol);
+ else
+ printf ("%-.*s", width, symbol);
+}
+
static bfd_vma
byte_get_big_endian (field, size)
unsigned char * field;
case EM_SPARCV9:
case EM_SPARC:
case EM_PPC:
+ case EM_PPC64:
case EM_V850:
case EM_CYGNUS_V850:
case EM_D30V:
printf (" ");
if (psym->st_name == 0)
- printf ("%-25.25s",
- SECTION_NAME (SECTION_HEADER (psym->st_shndx)));
+ print_symbol (-25, 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);
+ print_symbol (-25, strtab + psym->st_name);
if (is_rela)
printf (" + %lx", (unsigned long) relas [i].r_addend);
}
}
+static const char *
+get_ppc64_dynamic_type (type)
+ unsigned long type;
+{
+ switch (type)
+ {
+ case DT_PPC64_GLINK: return "PPC64_GLINK";
+ default:
+ return NULL;
+ }
+}
+
static const char *
get_parisc_dynamic_type (type)
unsigned long type;
case EM_SPARCV9:
result = get_sparc64_dynamic_type (type);
break;
+ case EM_PPC64:
+ result = get_ppc64_dynamic_type (type);
+ break;
default:
result = NULL;
break;
case EM_SPARC32PLUS: return "Sparc v8+" ;
case EM_960: return "Intel 90860";
case EM_PPC: return "PowerPC";
+ case EM_PPC64: return "PowerPC64";
case EM_V800: return "NEC V800";
case EM_FR20: return "Fujitsu FR20";
case EM_RH32: return "TRW RH32";
{
case PT_IA_64_ARCHEXT: return "IA_64_ARCHEXT";
case PT_IA_64_UNWIND: return "IA_64_UNWIND";
+ case PT_HP_TLS: return "HP_TLS";
+ case PT_IA_64_HP_OPT_ANOT: return "HP_OPT_ANNOT";
+ case PT_IA_64_HP_HSL_ANOT: return "HP_HSL_ANNOT";
+ case PT_IA_64_HP_STACK: return "HP_STACK";
default:
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;
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[liaprmfs] or --debug-dump[=line,=info,=abbrev,=pubnames,=ranges,=macro,=frames,=str]\n"));
- fprintf (stdout, _(" Display the contents of DWARF2 debug sections\n"));
+ fprintf (stdout, _("Usage: readelf <option(s)> elf-file(s)\n"));
+ fprintf (stdout, _(" Display information about the contents of ELF format files\n"));
+ fprintf (stdout, _(" Options are:\n\
+ -a --all Equivalent to: -h -l -S -s -r -d -V -A -I\n\
+ -h --file-header Display the ELF file header\n\
+ -l --program-headers Display the program headers\n\
+ --segments An alias for --program-headers\n\
+ -S --section-headers Display the sections' header\n\
+ --sections An alias for --section-headers\n\
+ -e --headers Equivalent to: -h -l -S\n\
+ -s --syms Display the symbol table\n\
+ --symbols An alias for --syms\n\
+ -n --notes Display the core notes (if present)\n\
+ -r --relocs Display the relocations (if present)\n\
+ -u --unwind Display the unwind info (if present)\n\
+ -d --dynamic Display the dynamic segment (if present)\n\
+ -V --version-info Display the version sections (if present)\n\
+ -A --arch-specific Display architecture specific information (if any).\n\
+ -D --use-dynamic Use the dynamic section info when displaying symbols\n\
+ -x --hex-dump=<number> Dump the contents of section <number>\n\
+ -w --debug-dump[=line,=info,=abbrev,=pubnames,=ranges,=macro,=frames,=str]\n\
+ 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"));
+ fprintf (stdout, _("\
+ -i --instruction-dump=<number>\n\
+ 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, _(" -W or --wide Don't split lines to fit into 80 columns\n"));
- fprintf (stdout, _(" -H or --help Display this information\n"));
+ fprintf (stdout, _("\
+ -I --histogram Display histogram of bucket list lengths\n\
+ -W --wide Allow output width to exceed 80 characters\n\
+ -H --help Display this information\n\
+ -v --version Display the version number of readelf\n"));
fprintf (stdout, _("Report bugs to %s\n"), REPORT_BUGS_TO);
exit (0);
printf (" %6s", get_symbol_type (ELF_ST_TYPE (psym->st_info)));
printf (" %6s", get_symbol_binding (ELF_ST_BIND (psym->st_info)));
printf (" %3s", get_symbol_visibility (ELF_ST_VISIBILITY (psym->st_other)));
- printf (" %3.3s", get_symbol_index_type (psym->st_shndx));
- printf (" %s\n", dynamic_strings + psym->st_name);
+ printf (" %3.3s ", get_symbol_index_type (psym->st_shndx));
+ print_symbol (25, dynamic_strings + psym->st_name);
+ putchar ('\n');
}
}
}
printf (" %-7s", get_symbol_type (ELF_ST_TYPE (psym->st_info)));
printf (" %-6s", get_symbol_binding (ELF_ST_BIND (psym->st_info)));
printf (" %-3s", get_symbol_visibility (ELF_ST_VISIBILITY (psym->st_other)));
- printf (" %4s", get_symbol_index_type (psym->st_shndx));
- printf (" %s", strtab + psym->st_name);
+ printf (" %4s ", get_symbol_index_type (psym->st_shndx));
+ print_symbol (25, strtab + psym->st_name);
if (section->sh_type == SHT_DYNSYM &&
version_info [DT_VERSIONTAGIDX (DT_VERSYM)] != 0)
{
unsigned short int flags = dynamic_syminfo[i].si_flags;
- printf ("%4d: %-30s ", i,
- dynamic_strings + dynamic_symbols[i].st_name);
+ printf ("%4d: ", i);
+ print_symbol (30, dynamic_strings + dynamic_symbols[i].st_name);
+ putchar (' ');
switch (dynamic_syminfo[i].si_boundto)
{
default:
if (dynamic_syminfo[i].si_boundto > 0
&& dynamic_syminfo[i].si_boundto < dynamic_size)
- printf ("%-10s ",
- dynamic_strings
- + dynamic_segment[dynamic_syminfo[i].si_boundto].d_un.d_val);
+ {
+ print_symbol (10, dynamic_strings
+ + dynamic_segment
+ [dynamic_syminfo[i].si_boundto].d_un.d_val);
+ putchar (' ' );
+ }
else
printf ("%-10d ", dynamic_syminfo[i].si_boundto);
break;
tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
- printf ("%3lu: %-20s %s %#10lx %-7ld", (unsigned long) cnt,
- dynamic_strings + liblist.l_name, timebuf,
- liblist.l_checksum, liblist.l_version);
+ printf ("%3lu: ", (unsigned long) cnt);
+ print_symbol (20, dynamic_strings + liblist.l_name);
+ printf (" %s %#10lx %-7ld", timebuf, liblist.l_checksum,
+ liblist.l_version);
if (liblist.l_flags == 0)
puts (" NONE");
for (cnt = 0; cnt < conflictsno; ++cnt)
{
- Elf_Internal_Sym * psym = &dynamic_symbols[iconf[cnt]];
+ Elf_Internal_Sym * psym = & dynamic_symbols [iconf [cnt]];
- printf ("%5lu: %8lu ", (unsigned long) cnt, iconf[cnt]);
+ printf ("%5lu: %8lu ", (unsigned long) cnt, iconf [cnt]);
print_vma (psym->st_value, FULL_HEX);
- printf (" %s\n", dynamic_strings + psym->st_name);
+ putchar (' ');
+ print_symbol (25, dynamic_strings + psym->st_name);
+ putchar ('\n');
}
free (iconf);
return 1;
}
-static char *
+static const char *
get_note_type (e_type)
unsigned e_type;
{
}
}
+static const char *
+get_netbsd_elfcore_note_type (e_type)
+ unsigned e_type;
+{
+ static char buff[64];
+
+ if (e_type == NT_NETBSDCORE_PROCINFO)
+ {
+ /* NetBSD core "procinfo" structure. */
+ return _("NetBSD procinfo structure");
+ }
+
+ /* As of Jan 2002 there are no other machine-independent notes
+ defined for NetBSD core files. If the note type is less
+ than the start of the machine-dependent note types, we don't
+ understand it. */
+
+ if (e_type < NT_NETBSDCORE_FIRSTMACH)
+ {
+ sprintf (buff, _("Unknown note type: (0x%08x)"), e_type);
+ return buff;
+ }
+
+ switch (elf_header.e_machine)
+ {
+ /* On the Alpha, SPARC (32-bit and 64-bit), PT_GETREGS == mach+0
+ and PT_GETFPREGS == mach+2. */
+
+ case EM_OLD_ALPHA:
+ case EM_ALPHA:
+ case EM_SPARC:
+ case EM_SPARC32PLUS:
+ case EM_SPARCV9:
+ switch (e_type)
+ {
+ case NT_NETBSDCORE_FIRSTMACH+0:
+ return _("PT_GETREGS (reg structure)");
+ case NT_NETBSDCORE_FIRSTMACH+2:
+ return _("PT_GETFPREGS (fpreg structure)");
+ default:
+ break;
+ }
+ break;
+
+ /* On all other arch's, PT_GETREGS == mach+1 and
+ PT_GETFPREGS == mach+3. */
+ default:
+ switch (e_type)
+ {
+ case NT_NETBSDCORE_FIRSTMACH+1:
+ return _("PT_GETREGS (reg structure)");
+ case NT_NETBSDCORE_FIRSTMACH+3:
+ return _("PT_GETFPREGS (fpreg structure)");
+ default:
+ break;
+ }
+ }
+
+ sprintf (buff, _("PT_FIRSTMACH+%d"), e_type - NT_NETBSDCORE_FIRSTMACH);
+ return buff;
+}
+
/* Note that by the ELF standard, the name field is already null byte
terminated, and namesz includes the terminating null byte.
I.E. the value of namesz for the name "FSF" is 4.
process_note (pnote)
Elf32_Internal_Note * pnote;
{
+ const char *nt;
+
+ if (pnote->namesz == 0)
+ {
+ /* If there is no note name, then use the default set of
+ note type strings. */
+ nt = get_note_type (pnote->type);
+ }
+ else if (strncmp (pnote->namedata, "NetBSD-CORE", 11) == 0)
+ {
+ /* NetBSD-specific core file notes. */
+ nt = get_netbsd_elfcore_note_type (pnote->type);
+ }
+ else
+ {
+ /* Don't recognize this note name; just use the default set of
+ note type strings. */
+ nt = get_note_type (pnote->type);
+ }
+
printf (" %s\t\t0x%08lx\t%s\n",
pnote->namesz ? pnote->namedata : "(NONE)",
- pnote->descsz, get_note_type (pnote->type));
+ pnote->descsz, nt);
return 1;
}