From 4f9583e9c45482e111d30f94df650a3f2cf36b99 Mon Sep 17 00:00:00 2001 From: Nick Clifton Date: Tue, 24 Mar 2015 12:25:25 +0000 Subject: Import fixes from trunk sources to correct invalid memory access issues with various binutils programs. Apply from master: 2015-02-26 Nick Clifton PR binutils/17512 * coffgrok.c (do_type): Check for an out of range tag index. Check for integer overflow computing array dimension. (do_define): Likewise. 2015-02-26 Nick Clifton PR binutils/17512 * resrc.c (write_rc_messagetable): Tighten check for invalid message lengths. 2015-02-13 Nick Clifton * coffgrok.c (do_define): Add check for type size overflow. * srconv.c (walk_tree_sfile): Check that enough sections are available before parsing. (prescan): Likewise. 2015-02-03 Nick Clifton PR binutils/17512 * objdump.c (display_any_bfd): Fail if archives nest too deeply. 2015-01-27 Nick Clifton PR binutils/17512 * dlltool.c (identify_search_archive): If the last archive was the same as the current archive, terminate the loop. * addr2line.c (slurp_symtab): If the symcount is zero, free the symbol table pointer. * rcparse.y: Add checks to avoid integer divide by zero. * rescoff.c (read_coff_rsrc): Add check on the size of the resource section. (read_coff_res_dir): Add check on the nesting level. Check for resource names overrunning the buffer. * resrc.c (write_rc_messagetable): Update formatting. Add check of 'elen' being zero. 2015-01-23 Nick Clifton * nlmconv.c (powerpc_mangle_relocs): Fix build errors introduced by recent delta, when compiling on for a 32-bit host. 2015-01-21 Nick Clifton PR binutils/17512 * addr2line.c (main): Call bfd_set_error_program_name. * ar.c (main): Likewise. * coffdump.c (main): Likewise. * cxxfilt.c (main): Likewise. * dlltool.c (main): Likewise. * nlmconv.c (main): Likewise. * nm.c (main): Likewise. * objdump.c (main): Likewise. * size.c (main): Likewise. * srconv.c (main): Likewise. * strings.c (main): Likewise. * sysdump.c (main): Likewise. * windmc.c (main): Likewise. * windres.c (main): Likewise. * objcopy.c (main): Likewise. (copy_relocations_in_section): Check for relocs without associated symbol pointers. 2015-01-21 Nick Clifton PR binutils/17512 * coffgrok.c (do_type): Check that computed ref exists. (doit): Add range checks when computing section for scope. 2015-01-08 Nick Clifton PR binutils/17512 * ojcopy.c (copy_object): Free the symbol table if no symbols could be loaded. (copy_file): Use bfd_close_all_done to close files that could not be copied. * sysdump.c (getINT): Fail if reading off the end of the buffer. Replace call to abort with a call to fatal. (getCHARS): Prevetn reading off the end of the buffer. * nlmconv.c (i386_mangle_relocs): Skip relocs without an associated symbol. (powerpc_mangle_relocs): Skip unrecognised relocs. Check address range before applying a reloc. 2015-01-07 Nick Clifton PR binutils/17512 * dlltool.c (scan_obj_file): Break loop if the last archive displayed matches the current archive. * objdump.c (display_any_bfd): Add a depth limit to nested archive display in order to avoid infinite loops. * srconv.c: Replace calls to abort with calls to fatal with an error message. 2015-01-06 Nick Clifton PR binutils/17512 * coffdump.c (dump_coff_section): Check for a symbol being available before printing its name. (main): Check the return value from coff_grok. * coffgrok.c: Reformat and tidy. Add range checks to most functions. (coff_grok): Return NULL if the input bfd is not in a COFF format. * coffgrok.h: Reformat and tidy. (struct coff_section): Change the nrelocs field to unsigned. * srconv.c (main): Check the return value from coff_grok. 2015-01-05 Nick Clifton PR binutils/17512 * nm.c (print_symbol): Add 'is_synthetic' parameter. Use it to help initialize the info.elfinfo field. (print_size_symbols): Add 'synth_count' parameter. Use it to set the is_synthetic parameter when calling print_symbol. (print_symbols): Likewise. (display_rel_file): Pass synth_count to printing function. (display_archive): Break loop if the last archive displayed matches the current archive. --- binutils/nm.c | 72 ++++++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 51 insertions(+), 21 deletions(-) (limited to 'binutils/nm.c') diff --git a/binutils/nm.c b/binutils/nm.c index ecd147e..ed1ed12 100644 --- a/binutils/nm.c +++ b/binutils/nm.c @@ -806,7 +806,11 @@ get_relocs (bfd *abfd, asection *sec, void *dataarg) /* Print a single symbol. */ static void -print_symbol (bfd *abfd, asymbol *sym, bfd_vma ssize, bfd *archive_bfd) +print_symbol (bfd * abfd, + asymbol * sym, + bfd_vma ssize, + bfd * archive_bfd, + bfd_boolean is_synthetic) { symbol_info syminfo; struct extended_symbol_info info; @@ -816,12 +820,12 @@ print_symbol (bfd *abfd, asymbol *sym, bfd_vma ssize, bfd *archive_bfd) format->print_symbol_filename (archive_bfd, abfd); bfd_get_symbol_info (abfd, sym, &syminfo); + info.sinfo = &syminfo; info.ssize = ssize; - if (bfd_get_flavour (abfd) == bfd_target_elf_flavour) - info.elfinfo = (elf_symbol_type *) sym; - else - info.elfinfo = NULL; + /* Synthetic symbols do not have a full elf_symbol_type set of data available. */ + info.elfinfo = is_synthetic ? NULL : elf_symbol_from (abfd, sym); + format->print_symbol_info (&info, abfd); if (line_numbers) @@ -941,12 +945,17 @@ print_symbol (bfd *abfd, asymbol *sym, bfd_vma ssize, bfd *archive_bfd) /* Print the symbols when sorting by size. */ static void -print_size_symbols (bfd *abfd, bfd_boolean is_dynamic, - struct size_sym *symsizes, long symcount, - bfd *archive_bfd) +print_size_symbols (bfd * abfd, + bfd_boolean is_dynamic, + struct size_sym * symsizes, + long symcount, + long synth_count, + bfd * archive_bfd) { asymbol *store; - struct size_sym *from, *fromend; + struct size_sym *from; + struct size_sym *fromend; + struct size_sym *fromsynth; store = bfd_make_empty_symbol (abfd); if (store == NULL) @@ -954,6 +963,8 @@ print_size_symbols (bfd *abfd, bfd_boolean is_dynamic, from = symsizes; fromend = from + symcount; + fromsynth = symsizes + (symcount - synth_count); + for (; from < fromend; from++) { asymbol *sym; @@ -962,20 +973,34 @@ print_size_symbols (bfd *abfd, bfd_boolean is_dynamic, if (sym == NULL) bfd_fatal (bfd_get_filename (abfd)); - print_symbol (abfd, sym, from->size, archive_bfd); + print_symbol (abfd, sym, from->size, archive_bfd, from >= fromsynth); } } -/* Print the symbols. If ARCHIVE_BFD is non-NULL, it is the archive - containing ABFD. */ +/* Print the symbols of ABFD that are held in MINISYMS. + + If ARCHIVE_BFD is non-NULL, it is the archive containing ABFD. + + SYMCOUNT is the number of symbols in MINISYMS and SYNTH_COUNT + is the number of these that are synthetic. Synthetic symbols, + if any are present, always come at the end of the MINISYMS. + + SIZE is the size of a symbol in MINISYMS. */ static void -print_symbols (bfd *abfd, bfd_boolean is_dynamic, void *minisyms, long symcount, - unsigned int size, bfd *archive_bfd) +print_symbols (bfd * abfd, + bfd_boolean is_dynamic, + void * minisyms, + long symcount, + long synth_count, + unsigned int size, + bfd * archive_bfd) { asymbol *store; - bfd_byte *from, *fromend; + bfd_byte *from; + bfd_byte *fromend; + bfd_byte *fromsynth; store = bfd_make_empty_symbol (abfd); if (store == NULL) @@ -983,6 +1008,8 @@ print_symbols (bfd *abfd, bfd_boolean is_dynamic, void *minisyms, long symcount, from = (bfd_byte *) minisyms; fromend = from + symcount * size; + fromsynth = (bfd_byte *) minisyms + ((symcount - synth_count) * size); + for (; from < fromend; from += size) { asymbol *sym; @@ -991,7 +1018,7 @@ print_symbols (bfd *abfd, bfd_boolean is_dynamic, void *minisyms, long symcount, if (sym == NULL) bfd_fatal (bfd_get_filename (abfd)); - print_symbol (abfd, sym, (bfd_vma) 0, archive_bfd); + print_symbol (abfd, sym, (bfd_vma) 0, archive_bfd, from >= fromsynth); } } @@ -1001,6 +1028,7 @@ static void display_rel_file (bfd *abfd, bfd *archive_bfd) { long symcount; + long synth_count = 0; void *minisyms; unsigned int size; struct size_sym *symsizes; @@ -1031,11 +1059,10 @@ display_rel_file (bfd *abfd, bfd *archive_bfd) non_fatal (_("%s: no symbols"), bfd_get_filename (abfd)); return; } - + if (show_synthetic && size == sizeof (asymbol *)) { asymbol *synthsyms; - long synth_count; asymbol **static_syms = NULL; asymbol **dyn_syms = NULL; long static_count = 0; @@ -1061,6 +1088,7 @@ display_rel_file (bfd *abfd, bfd *archive_bfd) bfd_fatal (bfd_get_filename (abfd)); } } + synth_count = bfd_get_synthetic_symtab (abfd, static_count, static_syms, dyn_count, dyn_syms, &synthsyms); if (synth_count > 0) @@ -1106,9 +1134,9 @@ display_rel_file (bfd *abfd, bfd *archive_bfd) } if (! sort_by_size) - print_symbols (abfd, dynamic, minisyms, symcount, size, archive_bfd); + print_symbols (abfd, dynamic, minisyms, symcount, synth_count, size, archive_bfd); else - print_size_symbols (abfd, dynamic, symsizes, symcount, archive_bfd); + print_size_symbols (abfd, dynamic, symsizes, symcount, synth_count, archive_bfd); free (minisyms); free (symsizes); @@ -1181,6 +1209,8 @@ display_archive (bfd *file) bfd_close (last_arfile); lineno_cache_bfd = NULL; lineno_cache_rel_bfd = NULL; + if (arfile == last_arfile) + return; } last_arfile = arfile; } @@ -1434,7 +1464,6 @@ print_symbol_info_bsd (struct extended_symbol_info *info, bfd *abfd) print_value (abfd, SYM_SIZE (info)); else print_value (abfd, SYM_VALUE (info)); - if (print_size && SYM_SIZE (info)) { printf (" "); @@ -1541,6 +1570,7 @@ main (int argc, char **argv) program_name = *argv; xmalloc_set_program_name (program_name); + bfd_set_error_program_name (program_name); #if BFD_SUPPORTS_PLUGINS bfd_plugin_set_program_name (program_name); #endif -- cgit v1.1