diff options
author | Alan Modra <amodra@gmail.com> | 2021-02-14 16:40:01 +1030 |
---|---|---|
committer | Alan Modra <amodra@gmail.com> | 2021-02-14 22:54:12 +1030 |
commit | 1944212b426d2e13cc4bb24aa1a850bbc572e624 (patch) | |
tree | 2eeb87749918f031c33dc4a8a64c2a3f5e077e6e /binutils/objdump.c | |
parent | 0d0a0d86c841a95226d9cc7c247c770c38fdc81b (diff) | |
download | gdb-1944212b426d2e13cc4bb24aa1a850bbc572e624.zip gdb-1944212b426d2e13cc4bb24aa1a850bbc572e624.tar.gz gdb-1944212b426d2e13cc4bb24aa1a850bbc572e624.tar.bz2 |
objdump: don't add an extra entry to syms array
Space for a NULL is there in every backend bfd_get_symtab_upper_bound
or bfd_get_dynamic_symtab_upper_bound when the symbol count is non-zero,
and placed as a terminator by bfd_canonicalize_symtab. Many backends
even return a single NULL entry array for zero symbol count, and while
there are a few that return a NULL array for no symbols, that case is
handled fine in objdump. So don't have objdump add yet another NULL
entry.
* objdump.c (slurp_symtab): Don't add an extra entry for NULL
to the symbol array.
(slurp_dynamic_symtab): Likewise.
(dump_bfd): Formatting. Copy terminating NULL from extra_syms.
Diffstat (limited to 'binutils/objdump.c')
-rw-r--r-- | binutils/objdump.c | 53 |
1 files changed, 25 insertions, 28 deletions
diff --git a/binutils/objdump.c b/binutils/objdump.c index fde5f59..3047850 100644 --- a/binutils/objdump.c +++ b/binutils/objdump.c @@ -748,32 +748,33 @@ slurp_symtab (bfd *abfd) non_fatal (_("failed to read symbol table from: %s"), bfd_get_filename (abfd)); bfd_fatal (_("error message was")); } - /* Add an extra entry (at the end) with a NULL pointer. */ - storage += sizeof (asymbol *); - off_t filesize = bfd_get_file_size (abfd); - - /* qv PR 24707. */ - if (filesize > 0 - && filesize < storage - /* The MMO file format supports its own special compression - technique, so its sections can be larger than the file size. */ - && bfd_get_flavour (abfd) != bfd_target_mmo_flavour) + if (storage) { - bfd_nonfatal_message (bfd_get_filename (abfd), abfd, NULL, - _("error: symbol table size (%#lx) is larger than filesize (%#lx)"), - storage, (long) filesize); - exit_status = 1; - symcount = 0; - return NULL; + off_t filesize = bfd_get_file_size (abfd); + + /* qv PR 24707. */ + if (filesize > 0 + && filesize < storage + /* The MMO file format supports its own special compression + technique, so its sections can be larger than the file size. */ + && bfd_get_flavour (abfd) != bfd_target_mmo_flavour) + { + bfd_nonfatal_message (bfd_get_filename (abfd), abfd, NULL, + _("error: symbol table size (%#lx) " + "is larger than filesize (%#lx)"), + storage, (long) filesize); + exit_status = 1; + symcount = 0; + return NULL; + } + + sy = (asymbol **) xmalloc (storage); } - sy = (asymbol **) xmalloc (storage); symcount = bfd_canonicalize_symtab (abfd, sy); if (symcount < 0) bfd_fatal (bfd_get_filename (abfd)); - /* assert (symcount < (storage / sizeof (asymbol *))) */ - sy[symcount] = NULL; return sy; } @@ -786,7 +787,6 @@ slurp_dynamic_symtab (bfd *abfd) long storage; storage = bfd_get_dynamic_symtab_upper_bound (abfd); - /* Add an extra entry (at the end) with a NULL pointer. */ if (storage < 0) { if (!(bfd_get_file_flags (abfd) & DYNAMIC)) @@ -800,14 +800,12 @@ slurp_dynamic_symtab (bfd *abfd) bfd_fatal (bfd_get_filename (abfd)); } - storage += sizeof (asymbol *); - sy = (asymbol **) xmalloc (storage); + if (storage) + sy = (asymbol **) xmalloc (storage); dynsymcount = bfd_canonicalize_dynamic_symtab (abfd, sy); if (dynsymcount < 0) bfd_fatal (bfd_get_filename (abfd)); - /* assert (symcount < (storage / sizeof (asymbol *))) */ - sy[dynsymcount] = NULL; return sy; } @@ -4915,12 +4913,11 @@ dump_bfd (bfd *abfd, bfd_boolean is_mainfile) } else { - syms = xrealloc (syms, (symcount + old_symcount + 1) * sizeof (asymbol *)); + syms = xrealloc (syms, ((symcount + old_symcount + 1) + * sizeof (asymbol *))); memcpy (syms + old_symcount, extra_syms, - symcount * sizeof (asymbol *)); - /* Preserve the NULL entry at the end of the symbol table. */ - syms[symcount + old_symcount] = NULL; + (symcount + 1) * sizeof (asymbol *)); } } |