/* 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, 2013
- 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/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_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_CYGNUS_V850:
switch (e_flags & EF_V850_ARCH)
{
+ case E_V850E3V5_ARCH:
+ strcat (buf, ", v850e3v5");
+ break;
case E_V850E2V3_ARCH:
strcat (buf, ", v850e2v3");
break;
#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))
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;
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_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;
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 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;