/* readelf.c -- display contents of an ELF format file
- Copyright 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
- 2008, 2009, 2010, 2011, 2012
- Free Software Foundation, Inc.
+ Copyright 1998-2013 Free Software Foundation, Inc.
Originally developed by Eric Youngdale <eric@andante.jic.com>
Modifications by Nick Clifton <nickc@redhat.com>
#include "elf/m68hc11.h"
#include "elf/mcore.h"
#include "elf/mep.h"
+#include "elf/metag.h"
#include "elf/microblaze.h"
#include "elf/mips.h"
#include "elf/mmix.h"
#include "elf/xstormy16.h"
#include "elf/xtensa.h"
+#include "elf/nios2.h"
+
#include "getopt.h"
#include "libiberty.h"
#include "safe-ctype.h"
#include "filenames.h"
+#ifndef offsetof
+#define offsetof(TYPE, MEMBER) ((size_t) &(((TYPE *) 0)->MEMBER))
+#endif
+
char * program_name = "readelf";
static long archive_file_offset;
static unsigned long archive_file_size;
case EM_M32R:
case EM_MCORE:
case EM_CYGNUS_MEP:
+ case EM_METAG:
case EM_MMIX:
case EM_MN10200:
case EM_CYGNUS_MN10200:
case EM_TI_C6000:
case EM_TILEGX:
case EM_TILEPRO:
+ case EM_V800:
case EM_V850:
case EM_CYGNUS_V850:
case EM_VAX:
rtype = elf_spu_reloc_type (type);
break;
+ case EM_V800:
+ rtype = v800_reloc_type (type);
+ break;
case EM_V850:
case EM_CYGNUS_V850:
rtype = v850_reloc_type (type);
rtype = elf_rx_reloc_type (type);
break;
+ case EM_METAG:
+ rtype = elf_metag_reloc_type (type);
+ break;
+
case EM_XC16X:
case EM_C166:
rtype = elf_xc16x_reloc_type (type);
case EM_XGATE:
rtype = elf_xgate_reloc_type (type);
break;
+
+ case EM_ALTERA_NIOS2:
+ rtype = elf_nios2_reloc_type (type);
+ break;
}
if (rtype == NULL)
}
}
+static const char *
+get_nios2_dynamic_type (unsigned long type)
+{
+ switch (type)
+ {
+ case DT_NIOS2_GP: return "NIOS2_GP";
+ default:
+ return NULL;
+ }
+}
+
static const char *
get_dynamic_type (unsigned long type)
{
case EM_TI_C6000:
result = get_tic6x_dynamic_type (type);
break;
+ case EM_ALTERA_NIOS2:
+ result = get_nios2_dynamic_type (type);
+ break;
default:
result = NULL;
break;
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 EM_MCORE: return "MCORE";
case EM_CYGNUS_M32R:
case EM_M32R: return "Renesas M32R (formerly Mitsubishi M32r)";
case EM_CYGNUS_V850:
+ case EM_V800: return "Renesas V850 (using RH850 ABI)";
case EM_V850: return "Renesas V850";
case EM_CYGNUS_MN10300:
case EM_MN10300: return "mn10300";
case EM_MICROBLAZE_OLD: return "Xilinx MicroBlaze";
case EM_RL78: return "Renesas RL78";
case EM_RX: return "Renesas RX";
- case EM_METAG: return "Imagination Technologies META processor architecture";
+ case EM_METAG: return "Imagination Technologies Meta processor architecture";
case EM_MCST_ELBRUS: return "MCST Elbrus general purpose hardware architecture";
case EM_ECOG16: return "Cyan Technology eCOG16 family";
case EM_ETPU: return "Freescale Extended Time Processing Unit";
strcat (buf, _(", relocatable-lib"));
break;
+ case EM_V800:
+ if ((e_flags & EF_RH850_ABI) == EF_RH850_ABI)
+ strcat (buf, ", RH850 ABI");
+
+ if (e_flags & EF_V800_850E3)
+ strcat (buf, ", V3 architecture");
+
+ if ((e_flags & (EF_RH850_FPU_DOUBLE | EF_RH850_FPU_SINGLE)) == 0)
+ strcat (buf, ", FPU not used");
+
+ if ((e_flags & (EF_RH850_REGMODE22 | EF_RH850_REGMODE32)) == 0)
+ strcat (buf, ", regmode: COMMON");
+
+ if ((e_flags & (EF_RH850_GP_FIX | EF_RH850_GP_NOFIX)) == 0)
+ strcat (buf, ", r4 not used");
+
+ if ((e_flags & (EF_RH850_EP_FIX | EF_RH850_EP_NOFIX)) == 0)
+ strcat (buf, ", r30 not used");
+
+ if ((e_flags & (EF_RH850_TP_FIX | EF_RH850_TP_NOFIX)) == 0)
+ strcat (buf, ", r5 not used");
+
+ if ((e_flags & (EF_RH850_REG2_RESERVE | EF_RH850_REG2_NORESERVE)) == 0)
+ strcat (buf, ", r2 not used");
+
+ for (e_flags &= 0xFFFF; e_flags; e_flags &= ~ (e_flags & - e_flags))
+ {
+ switch (e_flags & - e_flags)
+ {
+ case EF_RH850_FPU_DOUBLE: strcat (buf, ", double precision FPU"); break;
+ case EF_RH850_FPU_SINGLE: strcat (buf, ", single precision FPU"); break;
+ case EF_RH850_SIMD: strcat (buf, ", SIMD"); break;
+ case EF_RH850_CACHE: strcat (buf, ", CACHE"); break;
+ case EF_RH850_MMU: strcat (buf, ", MMU"); break;
+ case EF_RH850_REGMODE22: strcat (buf, ", regmode:22"); break;
+ case EF_RH850_REGMODE32: strcat (buf, ", regmode:23"); break;
+ case EF_RH850_DATA_ALIGN8: strcat (buf, ", 8-byte alignment"); break;
+ case EF_RH850_GP_FIX: strcat (buf, ", r4 fixed"); break;
+ case EF_RH850_GP_NOFIX: strcat (buf, ", r4 free"); break;
+ case EF_RH850_EP_FIX: strcat (buf, ", r30 fixed"); break;
+ case EF_RH850_EP_NOFIX: strcat (buf, ", r30 free"); break;
+ case EF_RH850_TP_FIX: strcat (buf, ", r5 fixed"); break;
+ case EF_RH850_TP_NOFIX: strcat (buf, ", r5 free"); break;
+ case EF_RH850_REG2_RESERVE: strcat (buf, ", r2 fixed"); break;
+ case EF_RH850_REG2_NORESERVE: strcat (buf, ", r2 free"); break;
+ default: break;
+ }
+ }
+ break;
+
case EM_V850:
case EM_CYGNUS_V850:
switch (e_flags & EF_V850_ARCH)
{
+ case E_V850E3V5_ARCH:
+ strcat (buf, ", v850e3v5");
+ break;
case E_V850E2V3_ARCH:
strcat (buf, ", v850e2v3");
break;
case E_MIPS_ARCH_64R2: strcat (buf, ", mips64r2"); break;
default: strcat (buf, _(", unknown ISA")); break;
}
-
- if (e_flags & EF_SH_PIC)
- strcat (buf, ", pic");
-
- if (e_flags & EF_SH_FDPIC)
- strcat (buf, ", fdpic");
break;
case EM_SH:
default: strcat (buf, _(", unknown ISA")); break;
}
+ if (e_flags & EF_SH_PIC)
+ strcat (buf, ", pic");
+
+ if (e_flags & EF_SH_FDPIC)
+ strcat (buf, ", fdpic");
break;
case EM_SPARCV9:
strcat (buf, ", dsp");
if (e_flags & E_FLAG_RX_PID)
strcat (buf, ", pid");
+ if (e_flags & E_FLAG_RX_ABI)
+ strcat (buf, ", RX ABI");
break;
case EM_S390:
#define CHECK_ENTSIZE_VALUES(section, i, size32, size64) \
do \
{ \
- size_t expected_entsize \
- = is_32bit_elf ? size32 : size64; \
+ bfd_size_type expected_entsize = is_32bit_elf ? size32 : size64; \
if (section->sh_entsize != expected_entsize) \
- error (_("Section %d has invalid sh_entsize %lx (expected %lx)\n"), \
- i, (unsigned long int) section->sh_entsize, \
- (unsigned long int) expected_entsize); \
- section->sh_entsize = expected_entsize; \
+ { \
+ error (_("Section %d has invalid sh_entsize of %" BFD_VMA_FMT "x\n"), \
+ i, section->sh_entsize); \
+ error (_("(Using the expected size of %d for the rest of this dump)\n"), \
+ (int) expected_entsize); \
+ section->sh_entsize = expected_entsize; \
+ } \
} \
while (0)
-#define CHECK_ENTSIZE(section, i, type) \
+
+#define CHECK_ENTSIZE(section, i, type) \
CHECK_ENTSIZE_VALUES (section, i, sizeof (Elf32_External_##type), \
sizeof (Elf64_External_##type))
printf (" NODUMP");
val ^= DF_1_NODUMP;
}
- if (val & DF_1_CONLFAT)
+ if (val & DF_1_CONFALT)
+ {
+ printf (" CONFALT");
+ val ^= DF_1_CONFALT;
+ }
+ if (val & DF_1_ENDFILTEE)
+ {
+ printf (" ENDFILTEE");
+ val ^= DF_1_ENDFILTEE;
+ }
+ if (val & DF_1_DISPRELDNE)
{
- printf (" CONLFAT");
- val ^= DF_1_CONLFAT;
+ printf (" DISPRELDNE");
+ val ^= DF_1_DISPRELDNE;
+ }
+ if (val & DF_1_DISPRELPND)
+ {
+ printf (" DISPRELPND");
+ val ^= DF_1_DISPRELPND;
+ }
+ if (val & DF_1_NODIRECT)
+ {
+ printf (" NODIRECT");
+ val ^= DF_1_NODIRECT;
+ }
+ if (val & DF_1_IGNMULDEF)
+ {
+ printf (" IGNMULDEF");
+ val ^= DF_1_IGNMULDEF;
+ }
+ if (val & DF_1_NOKSYMS)
+ {
+ printf (" NOKSYMS");
+ val ^= DF_1_NOKSYMS;
+ }
+ if (val & DF_1_NOHDR)
+ {
+ printf (" NOHDR");
+ val ^= DF_1_NOHDR;
+ }
+ if (val & DF_1_EDITED)
+ {
+ printf (" EDITED");
+ val ^= DF_1_EDITED;
+ }
+ if (val & DF_1_NORELOC)
+ {
+ printf (" NORELOC");
+ val ^= DF_1_NORELOC;
+ }
+ if (val & DF_1_SYMINTPOSE)
+ {
+ printf (" SYMINTPOSE");
+ val ^= DF_1_SYMINTPOSE;
+ }
+ if (val & DF_1_GLOBAUDIT)
+ {
+ printf (" GLOBAUDIT");
+ val ^= DF_1_GLOBAUDIT;
+ }
+ if (val & DF_1_SINGLETON)
+ {
+ printf (" SINGLETON");
+ val ^= DF_1_SINGLETON;
}
if (val != 0)
printf (" %lx", val);
int j;
int isum;
- /* Check for negative or very large indicies. */
- if ((unsigned char *) edefs + idx < (unsigned char *) edefs)
+ /* Check for very large indicies. */
+ if (idx > (size_t) (endbuf - (char *) edefs))
break;
vstart = ((char *) edefs) + idx;
ent.vd_ndx, ent.vd_cnt);
/* Check for overflow. */
- if ((unsigned char *)(vstart + ent.vd_aux) < (unsigned char *) vstart
- || (unsigned char *)(vstart + ent.vd_aux) > (unsigned char *) endbuf)
+ if (ent.vd_aux > (size_t) (endbuf - vstart))
break;
vstart += ent.vd_aux;
for (j = 1; j < ent.vd_cnt; j++)
{
/* Check for overflow. */
- if ((unsigned char *)(vstart + aux.vda_next) < (unsigned char *) vstart
- || (unsigned char *)(vstart + aux.vda_next) > (unsigned char *) endbuf)
+ if (aux.vda_next > (size_t) (endbuf - vstart))
break;
isum += aux.vda_next;
int isum;
char * vstart;
- if ((unsigned char *) eneed + idx < (unsigned char *) eneed)
+ if (idx > (size_t) (endbuf - (char *) eneed))
break;
vstart = ((char *) eneed) + idx;
printf (_(" Cnt: %d\n"), ent.vn_cnt);
/* Check for overflow. */
- if ((unsigned char *)(vstart + ent.vn_aux) < (unsigned char *) vstart
- || (unsigned char *)(vstart + ent.vn_aux) > (unsigned char *) endbuf)
+ if (ent.vn_aux > (size_t) (endbuf - vstart))
break;
vstart += ent.vn_aux;
get_ver_flags (aux.vna_flags), aux.vna_other);
/* Check for overflow. */
- if ((unsigned char *)(vstart + aux.vna_next) < (unsigned char *) vstart
- || (unsigned char *)(vstart + aux.vna_next) > (unsigned char *) endbuf)
+ if (aux.vna_next > (size_t) (endbuf - vstart))
break;
isum += aux.vna_next;
return reloc_type == 1; /* R_MCORE_ADDR32. */
case EM_CYGNUS_MEP:
return reloc_type == 4; /* R_MEP_32. */
+ case EM_METAG:
+ return reloc_type == 2; /* R_METAG_ADDR32. */
case EM_MICROBLAZE:
return reloc_type == 1; /* R_MICROBLAZE_32. */
case EM_MIPS:
case EM_MT:
return reloc_type == 2; /* R_MT_32. */
case EM_ALTERA_NIOS2:
+ return reloc_type == 12; /* R_NIOS2_BFD_RELOC_32. */
case EM_NIOS32:
return reloc_type == 1; /* R_NIOS_32. */
case EM_OPENRISC:
case EM_CYGNUS_V850:
case EM_V850:
return reloc_type == 6; /* R_V850_ABS32. */
+ case EM_V800:
+ return reloc_type == 0x33; /* R_V810_WORD. */
case EM_VAX:
return reloc_type == 1; /* R_VAX_32. */
case EM_X86_64:
case EM_M32C_OLD:
case EM_M32C:
return reloc_type == 1; /* R_M32C_16 */
- case EM_MSP430_OLD:
case EM_MSP430:
+ case EM_MSP430_OLD:
return reloc_type == 5; /* R_MSP430_16_BYTE. */
case EM_ALTERA_NIOS2:
+ return reloc_type == 13; /* R_NIOS2_BFD_RELOC_16. */
case EM_NIOS32:
return reloc_type == 9; /* R_NIOS_16. */
case EM_TI_C6000:
case EM_TILEPRO: /* R_TILEPRO_NONE. */
case EM_XC16X:
case EM_C166: /* R_XC16X_NONE. */
+ case EM_ALTERA_NIOS2: /* R_NIOS2_NONE. */
+ case EM_NIOS32: /* R_NIOS_NONE. */
return reloc_type == 0;
case EM_AARCH64:
return reloc_type == 0 || reloc_type == 256;
|| reloc_type == 17 /* R_XTENSA_DIFF8. */
|| reloc_type == 18 /* R_XTENSA_DIFF16. */
|| reloc_type == 19 /* R_XTENSA_DIFF32. */);
+ case EM_METAG:
+ return reloc_type == 3; /* R_METAG_NONE. */
}
return FALSE;
}
return _("NT_PPC_VMX (ppc Altivec registers)");
case NT_PPC_VSX:
return _("NT_PPC_VSX (ppc VSX registers)");
+ case NT_386_TLS:
+ return _("NT_386_TLS (x86 TLS information)");
+ case NT_386_IOPERM:
+ return _("NT_386_IOPERM (x86 I/O permissions)");
case NT_X86_XSTATE:
return _("NT_X86_XSTATE (x86 XSAVE extended state)");
case NT_S390_HIGH_GPRS:
return _("NT_S390_CTRS (s390 control registers)");
case NT_S390_PREFIX:
return _("NT_S390_PREFIX (s390 prefix register)");
+ case NT_S390_LAST_BREAK:
+ return _("NT_S390_LAST_BREAK (s390 last breaking event address)");
+ case NT_S390_SYSTEM_CALL:
+ return _("NT_S390_SYSTEM_CALL (s390 system call restart data)");
case NT_ARM_VFP:
return _("NT_ARM_VFP (arm VFP registers)");
+ case NT_ARM_TLS:
+ return _("NT_ARM_TLS (AArch TLS registers)");
+ case NT_ARM_HW_BREAK:
+ return _("NT_ARM_HW_BREAK (AArch hardware breakpoint registers)");
+ case NT_ARM_HW_WATCH:
+ return _("NT_ARM_HW_WATCH (AArch hardware watchpoint registers)");
case NT_PSTATUS:
return _("NT_PSTATUS (pstatus structure)");
case NT_FPREGS:
return 0;
pnotes = (Elf_External_Note *) get_data (NULL, file, offset, 1, length,
- _("notes"));
+ _("notes"));
if (pnotes == NULL)
return 0;
external = pnotes;
- printf (_("\nNotes at offset 0x%08lx with length 0x%08lx:\n"),
+ printf (_("\nDisplaying notes found at file offset 0x%08lx with length 0x%08lx:\n"),
(unsigned long) offset, (unsigned long) length);
printf (_(" %-20s %10s\tDescription\n"), _("Owner"), _("Data size"));
- while (external < (Elf_External_Note *) ((char *) pnotes + length))
+ while ((char *) external < (char *) pnotes + length)
{
- Elf_External_Note * next;
Elf_Internal_Note inote;
+ size_t min_notesz;
+ char *next;
char * temp = NULL;
+ size_t data_remaining = ((char *) pnotes + length) - (char *) external;
if (!is_ia64_vms ())
- {
- inote.type = BYTE_GET (external->type);
- inote.namesz = BYTE_GET (external->namesz);
- inote.namedata = external->name;
- inote.descsz = BYTE_GET (external->descsz);
- inote.descdata = inote.namedata + align_power (inote.namesz, 2);
- inote.descpos = offset + (inote.descdata - (char *) pnotes);
-
- next = (Elf_External_Note *) (inote.descdata + align_power (inote.descsz, 2));
- }
+ {
+ /* PR binutils/15191
+ Make sure that there is enough data to read. */
+ min_notesz = offsetof (Elf_External_Note, name);
+ if (data_remaining < min_notesz)
+ {
+ warn (_("Corrupt note: only %d bytes remain, not enough for a full note\n"),
+ (int) data_remaining);
+ break;
+ }
+ inote.type = BYTE_GET (external->type);
+ inote.namesz = BYTE_GET (external->namesz);
+ inote.namedata = external->name;
+ inote.descsz = BYTE_GET (external->descsz);
+ inote.descdata = inote.namedata + align_power (inote.namesz, 2);
+ inote.descpos = offset + (inote.descdata - (char *) pnotes);
+ next = inote.descdata + align_power (inote.descsz, 2);
+ }
else
- {
- Elf64_External_VMS_Note *vms_external;
-
- vms_external = (Elf64_External_VMS_Note *)external;
- inote.type = BYTE_GET (vms_external->type);
- inote.namesz = BYTE_GET (vms_external->namesz);
- inote.namedata = vms_external->name;
- inote.descsz = BYTE_GET (vms_external->descsz);
- inote.descdata = inote.namedata + align_power (inote.namesz, 3);
- inote.descpos = offset + (inote.descdata - (char *) pnotes);
-
- next = (Elf_External_Note *)
- (inote.descdata + align_power (inote.descsz, 3));
- }
+ {
+ Elf64_External_VMS_Note *vms_external;
+
+ /* PR binutils/15191
+ Make sure that there is enough data to read. */
+ min_notesz = offsetof (Elf64_External_VMS_Note, name);
+ if (data_remaining < min_notesz)
+ {
+ warn (_("Corrupt note: only %d bytes remain, not enough for a full note\n"),
+ (int) data_remaining);
+ break;
+ }
- if ( ((char *) next > ((char *) pnotes) + length)
- || ((char *) next < (char *) pnotes))
+ vms_external = (Elf64_External_VMS_Note *) external;
+ inote.type = BYTE_GET (vms_external->type);
+ inote.namesz = BYTE_GET (vms_external->namesz);
+ inote.namedata = vms_external->name;
+ inote.descsz = BYTE_GET (vms_external->descsz);
+ inote.descdata = inote.namedata + align_power (inote.namesz, 3);
+ inote.descpos = offset + (inote.descdata - (char *) pnotes);
+ next = inote.descdata + align_power (inote.descsz, 3);
+ }
+
+ if (inote.descdata < (char *) external + min_notesz
+ || next < (char *) external + min_notesz
+ || data_remaining < (size_t)(next - (char *) external))
{
- warn (_("corrupt note found at offset %lx into core notes\n"),
+ warn (_("note with invalid namesz and/or descsz found at offset 0x%lx\n"),
(unsigned long) ((char *) external - (char *) pnotes));
- warn (_(" type: %lx, namesize: %08lx, descsize: %08lx\n"),
+ warn (_(" type: 0x%lx, namesize: 0x%08lx, descsize: 0x%08lx\n"),
inote.type, inote.namesz, inote.descsz);
break;
}
- external = next;
-
- /* Prevent out-of-bounds indexing. */
- if (inote.namedata + inote.namesz > (char *) pnotes + length
- || inote.namedata + inote.namesz < inote.namedata)
- {
- warn (_("corrupt note found at offset %lx into core notes\n"),
- (unsigned long) ((char *) external - (char *) pnotes));
- warn (_(" type: %lx, namesize: %08lx, descsize: %08lx\n"),
- inote.type, inote.namesz, inote.descsz);
- break;
- }
+ external = (Elf_External_Note *) next;
/* Verify that name is null terminated. It appears that at least
one version of Linux (RedHat 6.0) generates corefiles that don't
}
else if (is_thin_archive)
{
+ /* PR 15140: Allow for corrupt thin archives. */
+ if (nested_arch.file == NULL)
+ {
+ error (_("%s: contains corrupt thin archive: %s\n"),
+ file_name, name);
+ ret = 1;
+ break;
+ }
+
/* This is a proxy for a member of a nested archive. */
archive_file_offset = arch.nested_member_origin + sizeof arch.arhdr;