X-Git-Url: http://drtracing.org/?a=blobdiff_plain;f=binutils%2Freadelf.c;h=20cfc473d94749111ea90422b3f48ab90eafb8eb;hb=5656ba2c217cff434621d6caf135cbda5ae92ac4;hp=a0d6f327896df359fbb3bc1303472e2a31bc16a1;hpb=570286220e28e606e199b37a06cd199cadb592ba;p=deliverable%2Fbinutils-gdb.git diff --git a/binutils/readelf.c b/binutils/readelf.c index a0d6f32789..20cfc473d9 100644 --- a/binutils/readelf.c +++ b/binutils/readelf.c @@ -567,7 +567,7 @@ printable_section_name (Elf_Internal_Shdr * sec) { if (remaining < 2) break; - + * buf ++ = '^'; * buf ++ = c + 0x40; remaining -= 2; @@ -1611,7 +1611,10 @@ dump_relocations (FILE * file, { bfd_signed_vma off = rels[i].r_addend; - if (off < 0) + /* PR 17531: file: 2e63226f. */ + if (off == ((bfd_signed_vma) 1) << ((sizeof (bfd_signed_vma) * 8) - 1)) + printf (" + %" BFD_VMA_FMT "x", off); + else if (off < 0) printf (" - %" BFD_VMA_FMT "x", - off); else printf (" + %" BFD_VMA_FMT "x", off); @@ -1623,7 +1626,10 @@ dump_relocations (FILE * file, bfd_signed_vma off = rels[i].r_addend; printf ("%*c", is_32bit_elf ? 12 : 20, ' '); - if (off < 0) + /* PR 17531: file: 2e63226f. */ + if (off == ((bfd_signed_vma) 1) << ((sizeof (bfd_signed_vma) * 8) - 1)) + printf ("%" BFD_VMA_FMT "x", off); + else if (off < 0) printf ("-%" BFD_VMA_FMT "x", - off); else printf ("%" BFD_VMA_FMT "x", off); @@ -2274,12 +2280,6 @@ decode_ARM_machine_flags (unsigned e_flags, char buf[]) 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) { @@ -2946,12 +2946,8 @@ get_machine_flags (unsigned e_flags, unsigned e_machine) { 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; @@ -3133,7 +3129,7 @@ get_machine_flags (unsigned e_flags, unsigned e_machine) if (e_flags & EF_SH_FDPIC) strcat (buf, ", fdpic"); break; - + case EM_OR1K: if (e_flags & EF_OR1K_NODELAY) strcat (buf, ", no delay"); @@ -3752,6 +3748,20 @@ get_msp430x_section_type_name (unsigned int sh_type) } } +static const char * +get_v850_section_type_name (unsigned int sh_type) +{ + switch (sh_type) + { + case SHT_V850_SCOMMON: return "V850 Small Common"; + case SHT_V850_TCOMMON: return "V850 Tiny Common"; + case SHT_V850_ZCOMMON: return "V850 Zero Common"; + case SHT_RENESAS_IOP: return "RENESAS IOP"; + case SHT_RENESAS_INFO: return "RENESAS INFO"; + default: return NULL; + } +} + static const char * get_section_type_name (unsigned int sh_type) { @@ -3820,6 +3830,11 @@ get_section_type_name (unsigned int sh_type) case EM_MSP430: result = get_msp430x_section_type_name (sh_type); break; + case EM_V800: + case EM_V850: + case EM_CYGNUS_V850: + result = get_v850_section_type_name (sh_type); + break; default: result = NULL; break; @@ -3850,7 +3865,19 @@ get_section_type_name (unsigned int sh_type) sprintf (buff, "LOOS+%x", sh_type - SHT_LOOS); } else if ((sh_type >= SHT_LOUSER) && (sh_type <= SHT_HIUSER)) - sprintf (buff, "LOUSER+%x", sh_type - SHT_LOUSER); + { + switch (elf_header.e_machine) + { + case EM_V800: + case EM_V850: + case EM_CYGNUS_V850: + return get_v850_section_type_name (sh_type); + default: + break; + } + + sprintf (buff, "LOUSER+%x", sh_type - SHT_LOUSER); + } else /* This message is probably going to be displayed in a 15 character wide field, so put the hex value first. */ @@ -4205,11 +4232,6 @@ parse_args (int argc, char ** argv) && !do_section_groups && !do_archive_index && !do_dyn_syms) usage (stderr); - else if (argc < 3) - { - warn (_("Nothing to do.\n")); - usage (stderr); - } } static const char * @@ -4484,7 +4506,7 @@ process_program_headers (FILE * file) /* PR binutils/12467. */ if (elf_header.e_phoff != 0) warn (_("possibly corrupt ELF header - it has a non-zero program" - " header offset, but no program headers")); + " header offset, but no program headers\n")); else if (do_segments) printf (_("\nThere are no program headers in this file.\n")); return 0; @@ -6433,71 +6455,53 @@ process_relocs (FILE * file) return 1; } -/* Process the unwind section. */ - -#include "unwind-ia64.h" - /* An absolute address consists of a section and an offset. If the section is NULL, the offset itself is the address, otherwise, the address equals to LOAD_ADDRESS(section) + offset. */ struct absaddr - { - unsigned short section; - bfd_vma offset; - }; +{ + unsigned short section; + bfd_vma offset; +}; #define ABSADDR(a) \ ((a).section \ ? section_headers [(a).section].sh_addr + (a).offset \ : (a).offset) -struct ia64_unw_table_entry - { - struct absaddr start; - struct absaddr end; - struct absaddr info; - }; - -struct ia64_unw_aux_info - { - - struct ia64_unw_table_entry *table; /* Unwind table. */ - unsigned long table_len; /* Length of unwind table. */ - unsigned char * info; /* Unwind info. */ - unsigned long info_size; /* Size of unwind info. */ - bfd_vma info_addr; /* starting address of unwind info. */ - bfd_vma seg_base; /* Starting address of segment. */ - Elf_Internal_Sym * symtab; /* The symbol table. */ - unsigned long nsyms; /* Number of symbols. */ - char * strtab; /* The string table. */ - unsigned long strtab_size; /* Size of string table. */ - }; +/* Find the nearest symbol at or below ADDR. Returns the symbol + name, if found, and the offset from the symbol to ADDR. */ static void find_symbol_for_address (Elf_Internal_Sym * symtab, - unsigned long nsyms, - const char * strtab, - unsigned long strtab_size, - struct absaddr addr, - const char ** symname, - bfd_vma * offset) + unsigned long nsyms, + const char * strtab, + unsigned long strtab_size, + struct absaddr addr, + const char ** symname, + bfd_vma * offset) { bfd_vma dist = 0x100000; Elf_Internal_Sym * sym; + Elf_Internal_Sym * beg; + Elf_Internal_Sym * end; Elf_Internal_Sym * best = NULL; - unsigned long i; REMOVE_ARCH_BITS (addr.offset); + beg = symtab; + end = symtab + nsyms; - for (i = 0, sym = symtab; i < nsyms; ++i, ++sym) + while (beg < end) { - bfd_vma value = sym->st_value; + bfd_vma value; + sym = beg + (end - beg) / 2; + + value = sym->st_value; REMOVE_ARCH_BITS (value); - if (ELF_ST_TYPE (sym->st_info) == STT_FUNC - && sym->st_name != 0 + if (sym->st_name != 0 && (addr.section == SHN_UNDEF || addr.section == sym->st_shndx) && addr.offset >= value && addr.offset - value < dist) @@ -6507,6 +6511,11 @@ find_symbol_for_address (Elf_Internal_Sym * symtab, if (!dist) break; } + + if (addr.offset < value) + end = sym; + else + beg = sym + 1; } if (best) @@ -6521,12 +6530,56 @@ find_symbol_for_address (Elf_Internal_Sym * symtab, *offset = addr.offset; } +static int +symcmp (const void *p, const void *q) +{ + Elf_Internal_Sym *sp = (Elf_Internal_Sym *) p; + Elf_Internal_Sym *sq = (Elf_Internal_Sym *) q; + + return sp->st_value > sq->st_value ? 1 : (sp->st_value < sq->st_value ? -1 : 0); +} + +/* Process the unwind section. */ + +#include "unwind-ia64.h" + +struct ia64_unw_table_entry +{ + struct absaddr start; + struct absaddr end; + struct absaddr info; +}; + +struct ia64_unw_aux_info +{ + struct ia64_unw_table_entry *table; /* Unwind table. */ + unsigned long table_len; /* Length of unwind table. */ + unsigned char * info; /* Unwind info. */ + unsigned long info_size; /* Size of unwind info. */ + bfd_vma info_addr; /* Starting address of unwind info. */ + bfd_vma seg_base; /* Starting address of segment. */ + Elf_Internal_Sym * symtab; /* The symbol table. */ + unsigned long nsyms; /* Number of symbols. */ + Elf_Internal_Sym * funtab; /* Sorted table of STT_FUNC symbols. */ + unsigned long nfuns; /* Number of entries in funtab. */ + char * strtab; /* The string table. */ + unsigned long strtab_size; /* Size of string table. */ +}; + static void dump_ia64_unwind (struct ia64_unw_aux_info * aux) { struct ia64_unw_table_entry * tp; + unsigned long j, nfuns; int in_body; + aux->funtab = xmalloc (aux->nsyms * sizeof (Elf_Internal_Sym)); + for (nfuns = 0, j = 0; j < aux->nsyms; j++) + if (aux->symtab[j].st_value && ELF_ST_TYPE (aux->symtab[j].st_info) == STT_FUNC) + aux->funtab[nfuns++] = aux->symtab[j]; + aux->nfuns = nfuns; + qsort (aux->funtab, aux->nfuns, sizeof (Elf_Internal_Sym), symcmp); + for (tp = aux->table; tp < aux->table + aux->table_len; ++tp) { bfd_vma stamp; @@ -6536,7 +6589,7 @@ dump_ia64_unwind (struct ia64_unw_aux_info * aux) const unsigned char * end; const char * procname; - find_symbol_for_address (aux->symtab, aux->nsyms, aux->strtab, + find_symbol_for_address (aux->funtab, aux->nfuns, aux->strtab, aux->strtab_size, tp->start, &procname, &offset); fputs ("\n<", stdout); @@ -6592,6 +6645,8 @@ dump_ia64_unwind (struct ia64_unw_aux_info * aux) for (dp = head + 8; dp < end;) dp = unw_decode (dp, in_body, & in_body); } + + free (aux->funtab); } static bfd_boolean @@ -6692,7 +6747,7 @@ slurp_ia64_unwind_table (FILE * file, warn (_("Skipping unknown relocation type: %u\n"), get_reloc_type (rp->r_info)); continue; } - + if (! const_strneq (relname, "R_IA64_SEGREL")) { warn (_("Skipping unexpected relocation type: %s\n"), relname); @@ -6890,7 +6945,7 @@ struct hppa_unw_table_entry { struct absaddr start; struct absaddr end; - unsigned int Cannot_unwind:1; /* 0 */ + unsigned int Cannot_unwind:1; /* 0 */ unsigned int Millicode:1; /* 1 */ unsigned int Millicode_save_sr0:1; /* 2 */ unsigned int Region_description:2; /* 3..4 */ @@ -6899,52 +6954,62 @@ struct hppa_unw_table_entry unsigned int Entry_FR:4; /* number saved */ /* 7..10 */ unsigned int Entry_GR:5; /* number saved */ /* 11..15 */ unsigned int Args_stored:1; /* 16 */ - unsigned int Variable_Frame:1; /* 17 */ - unsigned int Separate_Package_Body:1; /* 18 */ + unsigned int Variable_Frame:1; /* 17 */ + unsigned int Separate_Package_Body:1; /* 18 */ unsigned int Frame_Extension_Millicode:1; /* 19 */ - unsigned int Stack_Overflow_Check:1; /* 20 */ - unsigned int Two_Instruction_SP_Increment:1; /* 21 */ + unsigned int Stack_Overflow_Check:1; /* 20 */ + unsigned int Two_Instruction_SP_Increment:1;/* 21 */ unsigned int Ada_Region:1; /* 22 */ unsigned int cxx_info:1; /* 23 */ - unsigned int cxx_try_catch:1; /* 24 */ - unsigned int sched_entry_seq:1; /* 25 */ + unsigned int cxx_try_catch:1; /* 24 */ + unsigned int sched_entry_seq:1; /* 25 */ unsigned int reserved2:1; /* 26 */ - unsigned int Save_SP:1; /* 27 */ - unsigned int Save_RP:1; /* 28 */ + unsigned int Save_SP:1; /* 27 */ + unsigned int Save_RP:1; /* 28 */ unsigned int Save_MRP_in_frame:1; /* 29 */ unsigned int extn_ptr_defined:1; /* 30 */ - unsigned int Cleanup_defined:1; /* 31 */ + unsigned int Cleanup_defined:1; /* 31 */ - unsigned int MPE_XL_interrupt_marker:1; /* 0 */ - unsigned int HP_UX_interrupt_marker:1; /* 1 */ + unsigned int MPE_XL_interrupt_marker:1; /* 0 */ + unsigned int HP_UX_interrupt_marker:1; /* 1 */ unsigned int Large_frame:1; /* 2 */ - unsigned int Pseudo_SP_Set:1; /* 3 */ + unsigned int Pseudo_SP_Set:1; /* 3 */ unsigned int reserved4:1; /* 4 */ unsigned int Total_frame_size:27; /* 5..31 */ }; struct hppa_unw_aux_info - { - struct hppa_unw_table_entry *table; /* Unwind table. */ - unsigned long table_len; /* Length of unwind table. */ - bfd_vma seg_base; /* Starting address of segment. */ - Elf_Internal_Sym * symtab; /* The symbol table. */ - unsigned long nsyms; /* Number of symbols. */ - char * strtab; /* The string table. */ - unsigned long strtab_size; /* Size of string table. */ - }; +{ + struct hppa_unw_table_entry * table; /* Unwind table. */ + unsigned long table_len; /* Length of unwind table. */ + bfd_vma seg_base; /* Starting address of segment. */ + Elf_Internal_Sym * symtab; /* The symbol table. */ + unsigned long nsyms; /* Number of symbols. */ + Elf_Internal_Sym * funtab; /* Sorted table of STT_FUNC symbols. */ + unsigned long nfuns; /* Number of entries in funtab. */ + char * strtab; /* The string table. */ + unsigned long strtab_size; /* Size of string table. */ +}; static void dump_hppa_unwind (struct hppa_unw_aux_info * aux) { struct hppa_unw_table_entry * tp; + unsigned long j, nfuns; + + aux->funtab = xmalloc (aux->nsyms * sizeof (Elf_Internal_Sym)); + for (nfuns = 0, j = 0; j < aux->nsyms; j++) + if (aux->symtab[j].st_value && ELF_ST_TYPE (aux->symtab[j].st_info) == STT_FUNC) + aux->funtab[nfuns++] = aux->symtab[j]; + aux->nfuns = nfuns; + qsort (aux->funtab, aux->nfuns, sizeof (Elf_Internal_Sym), symcmp); for (tp = aux->table; tp < aux->table + aux->table_len; ++tp) { bfd_vma offset; const char * procname; - find_symbol_for_address (aux->symtab, aux->nsyms, aux->strtab, + find_symbol_for_address (aux->funtab, aux->nfuns, aux->strtab, aux->strtab_size, tp->start, &procname, &offset); @@ -6998,6 +7063,8 @@ dump_hppa_unwind (struct hppa_unw_aux_info * aux) } printf ("\n"); + + free (aux->funtab); } static int @@ -7234,6 +7301,8 @@ struct arm_unw_aux_info FILE * file; /* The file containing the unwind sections. */ Elf_Internal_Sym * symtab; /* The file's symbol table. */ unsigned long nsyms; /* Number of symbols. */ + Elf_Internal_Sym * funtab; /* Sorted table of STT_FUNC symbols. */ + unsigned long nfuns; /* Number of these symbols. */ char * strtab; /* The file's string table. */ unsigned long strtab_size; /* Size of string table. */ }; @@ -7248,7 +7317,7 @@ arm_print_vma_and_name (struct arm_unw_aux_info *aux, if (addr.section == SHN_UNDEF) addr.offset = fn; - find_symbol_for_address (aux->symtab, aux->nsyms, aux->strtab, + find_symbol_for_address (aux->funtab, aux->nfuns, aux->strtab, aux->strtab_size, addr, &procname, &sym_offset); @@ -7543,11 +7612,13 @@ decode_tic6x_unwind_regmask (unsigned int mask) printf ("0x%02x ", OP) static void -decode_arm_unwind_bytecode (struct arm_unw_aux_info *aux, - unsigned int word, unsigned int remaining, - unsigned int more_words, - bfd_vma data_offset, Elf_Internal_Shdr *data_sec, - struct arm_section *data_arm_sec) +decode_arm_unwind_bytecode (struct arm_unw_aux_info * aux, + unsigned int word, + unsigned int remaining, + unsigned int more_words, + bfd_vma data_offset, + Elf_Internal_Shdr * data_sec, + struct arm_section * data_arm_sec) { struct absaddr addr; @@ -7754,11 +7825,13 @@ decode_arm_unwind_bytecode (struct arm_unw_aux_info *aux, } static void -decode_tic6x_unwind_bytecode (struct arm_unw_aux_info *aux, - unsigned int word, unsigned int remaining, - unsigned int more_words, - bfd_vma data_offset, Elf_Internal_Shdr *data_sec, - struct arm_section *data_arm_sec) +decode_tic6x_unwind_bytecode (struct arm_unw_aux_info * aux, + unsigned int word, + unsigned int remaining, + unsigned int more_words, + bfd_vma data_offset, + Elf_Internal_Shdr * data_sec, + struct arm_section * data_arm_sec) { struct absaddr addr; @@ -7876,7 +7949,7 @@ decode_tic6x_unwind_bytecode (struct arm_unw_aux_info *aux, warn (_("Corrupt stack pointer adjustment detected\n")); return; } - + offset = read_uleb128 (buf, &len, buf + i + 1); assert (len == i + 1); offset = offset * 8 + 0x408; @@ -8071,11 +8144,19 @@ dump_arm_unwind (struct arm_unw_aux_info *aux, Elf_Internal_Shdr *exidx_sec) { struct arm_section exidx_arm_sec, extab_arm_sec; unsigned int i, exidx_len; + unsigned long j, nfuns; memset (&exidx_arm_sec, 0, sizeof (exidx_arm_sec)); memset (&extab_arm_sec, 0, sizeof (extab_arm_sec)); exidx_len = exidx_sec->sh_size / 8; + aux->funtab = xmalloc (aux->nsyms * sizeof (Elf_Internal_Sym)); + for (nfuns = 0, j = 0; j < aux->nsyms; j++) + if (aux->symtab[j].st_value && ELF_ST_TYPE (aux->symtab[j].st_info) == STT_FUNC) + aux->funtab[nfuns++] = aux->symtab[j]; + aux->nfuns = nfuns; + qsort (aux->funtab, aux->nfuns, sizeof (Elf_Internal_Sym), symcmp); + for (i = 0; i < exidx_len; i++) { unsigned int exidx_fn, exidx_entry; @@ -8089,6 +8170,7 @@ dump_arm_unwind (struct arm_unw_aux_info *aux, Elf_Internal_Shdr *exidx_sec) || ! get_unwind_section_word (aux, & exidx_arm_sec, exidx_sec, 8 * i + 4, & exidx_entry, & entry_addr, NULL)) { + free (aux->funtab); arm_free_section (& exidx_arm_sec); arm_free_section (& extab_arm_sec); return; @@ -8152,6 +8234,7 @@ dump_arm_unwind (struct arm_unw_aux_info *aux, Elf_Internal_Shdr *exidx_sec) printf ("\n"); + free (aux->funtab); arm_free_section (&exidx_arm_sec); arm_free_section (&extab_arm_sec); } @@ -9745,7 +9828,7 @@ process_version_sections (FILE * file) _("version def")) == NULL) { ivd.vd_next = 0; - /* PR 17531: file: 046-1082287-0.004. */ + /* PR 17531: file: 046-1082287-0.004. */ ivd.vd_ndx = (data[cnt + j] & VERSYM_VERSION) + 1; break; } @@ -10102,7 +10185,7 @@ get_dynamic_data (FILE * file, bfd_size_type number, unsigned int ent_size) (unsigned long long) number, ent_size); return NULL; } - + /* Be kind to memory chekers (eg valgrind, address sanitizer) by not attempting to allocate memory when the read is bound to fail. */ if (ent_size * number > current_file_size) @@ -10716,6 +10799,7 @@ process_symbol_table (FILE * file) unsigned long maxlength = 0; unsigned long nzero_counts = 0; unsigned long nsyms = 0; + unsigned long chained; printf (_("\nHistogram for bucket list length (total of %lu buckets):\n"), (unsigned long) nbuckets); @@ -10730,21 +10814,23 @@ process_symbol_table (FILE * file) printf (_(" Length Number %% of total Coverage\n")); for (hn = 0; hn < nbuckets; ++hn) { - for (si = buckets[hn]; si > 0 && si < nchains && si < nbuckets; si = chains[si]) + for (si = buckets[hn], chained = 0; + si > 0 && si < nchains && si < nbuckets && chained <= nchains; + si = chains[si], ++chained) { ++nsyms; if (maxlength < ++lengths[hn]) ++maxlength; - - /* PR binutils/17531: A corrupt binary could contain broken - histogram data. Do not go into an infinite loop trying - to process it. */ - if (chains[si] == si) - { - error (_("histogram chain links to itself\n")); - break; - } } + + /* PR binutils/17531: A corrupt binary could contain broken + histogram data. Do not go into an infinite loop trying + to process it. */ + if (chained > nchains) + { + error (_("histogram chain is corrupt\n")); + break; + } } counts = (unsigned long *) calloc (maxlength + 1, sizeof (*counts)); @@ -12279,7 +12365,7 @@ static const char * arm_attr_tag_ABI_FP_number_model[] = static const char * arm_attr_tag_ABI_enum_size[] = {"Unused", "small", "int", "forced to int"}; static const char * arm_attr_tag_ABI_HardFP_use[] = - {"As Tag_FP_arch", "SP only", "DP only", "SP and DP"}; + {"As Tag_FP_arch", "SP only", "Reserved", "Deprecated"}; static const char * arm_attr_tag_ABI_VFP_args[] = {"AAPCS", "VFP registers", "custom", "compatible"}; static const char * arm_attr_tag_ABI_WMMX_args[] = @@ -13843,7 +13929,7 @@ process_mips_specific (FILE * file) /* Find the section header so that we get the size. */ sect = find_section_by_type (SHT_MIPS_OPTIONS); - /* PR 17533 file: 012-277276-0.004. */ + /* PR 17533 file: 012-277276-0.004. */ if (sect == NULL) { error (_("No MIPS_OPTIONS header found\n")); @@ -13880,9 +13966,8 @@ process_mips_specific (FILE * file) if (option->size < sizeof (* eopt) || offset + option->size > sect->sh_size) { - warn (_("Invalid size (%u) for MIPS option\n"), option->size); - option->size = sizeof (* eopt); - break; + error (_("Invalid size (%u) for MIPS option\n"), option->size); + return 0; } offset += option->size; @@ -14154,7 +14239,7 @@ process_mips_specific (FILE * file) error (_("Too many GOT symbols: %lu\n"), (unsigned long) symtabno); return 0; } - + offset = offset_from_vma (file, pltgot, global_end - pltgot); data = (unsigned char *) get_data (NULL, file, offset, global_end - pltgot, 1, @@ -14508,6 +14593,10 @@ get_note_type (unsigned e_type) return _("NT_S390_SYSTEM_CALL (s390 system call restart data)"); case NT_S390_TDB: return _("NT_S390_TDB (s390 transaction diagnostic block)"); + case NT_S390_VXRS_LOW: + return _("NT_S390_VXRS_LOW (s390 vector registers 0-15 upper half)"); + case NT_S390_VXRS_HIGH: + return _("NT_S390_VXRS_HIGH (s390 vector registers 16-31)"); case NT_ARM_VFP: return _("NT_ARM_VFP (arm VFP registers)"); case NT_ARM_TLS: @@ -14734,6 +14823,85 @@ print_gnu_note (Elf_Internal_Note *pnote) return 1; } +static const char * +get_v850_elf_note_type (enum v850_notes n_type) +{ + static char buff[64]; + + switch (n_type) + { + case V850_NOTE_ALIGNMENT: return _("Alignment of 8-byte objects"); + case V850_NOTE_DATA_SIZE: return _("Sizeof double and long double"); + case V850_NOTE_FPU_INFO: return _("Type of FPU support needed"); + case V850_NOTE_SIMD_INFO: return _("Use of SIMD instructions"); + case V850_NOTE_CACHE_INFO: return _("Use of cache"); + case V850_NOTE_MMU_INFO: return _("Use of MMU"); + default: + snprintf (buff, sizeof (buff), _("Unknown note type: (0x%08x)"), n_type); + return buff; + } +} + +static int +print_v850_note (Elf_Internal_Note * pnote) +{ + unsigned int val; + + if (pnote->descsz != 4) + return 0; + val = byte_get ((unsigned char *) pnote->descdata, pnote->descsz); + + if (val == 0) + { + printf (_("not set\n")); + return 1; + } + + switch (pnote->type) + { + case V850_NOTE_ALIGNMENT: + switch (val) + { + case EF_RH850_DATA_ALIGN4: printf (_("4-byte\n")); return 1; + case EF_RH850_DATA_ALIGN8: printf (_("8-byte\n")); return 1; + } + break; + + case V850_NOTE_DATA_SIZE: + switch (val) + { + case EF_RH850_DOUBLE32: printf (_("4-bytes\n")); return 1; + case EF_RH850_DOUBLE64: printf (_("8-bytes\n")); return 1; + } + break; + + case V850_NOTE_FPU_INFO: + switch (val) + { + case EF_RH850_FPU20: printf (_("FPU-2.0\n")); return 1; + case EF_RH850_FPU30: printf (_("FPU-3.0\n")); return 1; + } + break; + + case V850_NOTE_MMU_INFO: + case V850_NOTE_CACHE_INFO: + case V850_NOTE_SIMD_INFO: + if (val == EF_RH850_SIMD) + { + printf (_("yes\n")); + return 1; + } + break; + + default: + /* An 'unknown note type' message will already have been displayed. */ + break; + } + + printf (_("unknown value: %x\n"), val); + return 0; +} + static const char * get_netbsd_elfcore_note_type (unsigned e_type) { @@ -14916,7 +15084,7 @@ print_ia64_vms_note (Elf_Internal_Note * pnote) case NT_VMS_FPMODE: printf (_(" Floating Point mode: ")); printf ("0x%016" BFD_VMA_FMT "x\n", - (bfd_vma)byte_get ((unsigned char *)pnote->descdata, 8)); + (bfd_vma) byte_get ((unsigned char *)pnote->descdata, 8)); break; case NT_VMS_LINKTIME: printf (_(" Link time: ")); @@ -14939,9 +15107,9 @@ print_ia64_vms_note (Elf_Internal_Note * pnote) ((bfd_int64_t) byte_get ((unsigned char *)pnote->descdata + 8, 8)); printf (_("\n Link flags : ")); printf ("0x%016" BFD_VMA_FMT "x\n", - (bfd_vma)byte_get ((unsigned char *)pnote->descdata + 16, 8)); + (bfd_vma) byte_get ((unsigned char *)pnote->descdata + 16, 8)); printf (_(" Header flags: 0x%08x\n"), - (unsigned)byte_get ((unsigned char *)pnote->descdata + 24, 4)); + (unsigned) byte_get ((unsigned char *)pnote->descdata + 24, 4)); printf (_(" Image id : %s\n"), pnote->descdata + 32); break; #endif @@ -15026,6 +15194,7 @@ process_corefile_note_segment (FILE * file, bfd_vma offset, bfd_vma length) { Elf_External_Note * pnotes; Elf_External_Note * external; + char * end; int res = 1; if (length <= 0) @@ -15042,13 +15211,14 @@ process_corefile_note_segment (FILE * file, bfd_vma offset, bfd_vma length) (unsigned long) offset, (unsigned long) length); printf (_(" %-20s %10s\tDescription\n"), _("Owner"), _("Data size")); - while ((char *) external < (char *) pnotes + length) + end = (char *) pnotes + length; + while ((char *) external < end) { Elf_Internal_Note inote; size_t min_notesz; char *next; char * temp = NULL; - size_t data_remaining = ((char *) pnotes + length) - (char *) external; + size_t data_remaining = end - (char *) external; if (!is_ia64_vms ()) { @@ -15066,6 +15236,14 @@ process_corefile_note_segment (FILE * file, bfd_vma offset, bfd_vma length) inote.namedata = external->name; inote.descsz = BYTE_GET (external->descsz); inote.descdata = inote.namedata + align_power (inote.namesz, 2); + /* PR 17531: file: 3443835e. */ + if (inote.descdata < (char *) pnotes || inote.descdata > end) + { + warn (_("Corrupt note: name size is too big: %lx\n"), inote.namesz); + inote.descdata = inote.namedata; + inote.namesz = 0; + } + inote.descpos = offset + (inote.descdata - (char *) pnotes); next = inote.descdata + align_power (inote.descsz, 2); } @@ -15167,6 +15345,87 @@ process_corefile_note_segments (FILE * file) return res; } +static int +process_v850_notes (FILE * file, bfd_vma offset, bfd_vma length) +{ + Elf_External_Note * pnotes; + Elf_External_Note * external; + char * end; + int res = 1; + + if (length <= 0) + return 0; + + pnotes = (Elf_External_Note *) get_data (NULL, file, offset, 1, length, + _("v850 notes")); + if (pnotes == NULL) + return 0; + + external = pnotes; + end = (char*) pnotes + length; + + printf (_("\nDisplaying contents of Renesas V850 notes section at offset 0x%lx with length 0x%lx:\n"), + (unsigned long) offset, (unsigned long) length); + + while ((char *) external + sizeof (Elf_External_Note) < end) + { + Elf_External_Note * next; + Elf_Internal_Note inote; + + 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); + + if (inote.descdata < (char *) pnotes || inote.descdata >= end) + { + warn (_("Corrupt note: name size is too big: %lx\n"), inote.namesz); + inote.descdata = inote.namedata; + inote.namesz = 0; + } + + next = (Elf_External_Note *) (inote.descdata + align_power (inote.descsz, 2)); + + if ( ((char *) next > end) + || ((char *) next < (char *) pnotes)) + { + warn (_("corrupt descsz found in note at offset 0x%lx\n"), + (unsigned long) ((char *) external - (char *) pnotes)); + warn (_(" type: 0x%lx, namesize: 0x%lx, descsize: 0x%lx\n"), + inote.type, inote.namesz, inote.descsz); + break; + } + + external = next; + + /* Prevent out-of-bounds indexing. */ + if ( inote.namedata + inote.namesz > end + || inote.namedata + inote.namesz < inote.namedata) + { + warn (_("corrupt namesz found in note at offset 0x%lx\n"), + (unsigned long) ((char *) external - (char *) pnotes)); + warn (_(" type: 0x%lx, namesize: 0x%lx, descsize: 0x%lx\n"), + inote.type, inote.namesz, inote.descsz); + break; + } + + printf (" %s: ", get_v850_elf_note_type (inote.type)); + + if (! print_v850_note (& inote)) + { + res = 0; + printf ("\n", + inote.namesz, inote.descsz); + } + } + + free (pnotes); + + return res; +} + static int process_note_sections (FILE * file) { @@ -15178,13 +15437,26 @@ process_note_sections (FILE * file) for (i = 0, section = section_headers; i < elf_header.e_shnum && section != NULL; i++, section++) - if (section->sh_type == SHT_NOTE) - { - res &= process_corefile_note_segment (file, - (bfd_vma) section->sh_offset, - (bfd_vma) section->sh_size); - n++; - } + { + if (section->sh_type == SHT_NOTE) + { + res &= process_corefile_note_segment (file, + (bfd_vma) section->sh_offset, + (bfd_vma) section->sh_size); + n++; + } + + if (( elf_header.e_machine == EM_V800 + || elf_header.e_machine == EM_V850 + || elf_header.e_machine == EM_CYGNUS_V850) + && section->sh_type == SHT_RENESAS_INFO) + { + res &= process_v850_notes (file, + (bfd_vma) section->sh_offset, + (bfd_vma) section->sh_size); + n++; + } + } if (n == 0) /* Try processing NOTE segments instead. */ @@ -15854,6 +16126,11 @@ main (int argc, char ** argv) if (optind < (argc - 1)) show_name = 1; + else if (optind >= argc) + { + warn (_("Nothing to do.\n")); + usage (stderr); + } err = 0; while (optind < argc)