aboutsummaryrefslogtreecommitdiff
path: root/binutils/objdump.c
diff options
context:
space:
mode:
authorAlan Modra <amodra@gmail.com>2023-02-08 14:41:58 +1030
committerAlan Modra <amodra@gmail.com>2023-02-09 09:39:45 +1030
commit87d206578e152d81d903a0beec8bd3927154eb30 (patch)
tree500c3b7e2446dcfb3b2f9107250be86644de97d9 /binutils/objdump.c
parent4fd74b5f05e63c5b4e705080c331da961fac7394 (diff)
downloadbinutils-87d206578e152d81d903a0beec8bd3927154eb30.zip
binutils-87d206578e152d81d903a0beec8bd3927154eb30.tar.gz
binutils-87d206578e152d81d903a0beec8bd3927154eb30.tar.bz2
Clear cached file size when bfd changed to BFD_IN_MEMORY
If file size is calculated by bfd_get_file_size, as it is by _bfd_alloc_and_read calls in coff_object_p, then it is cached and when pe_ILF_build_a_bfd converts an archive entry over to BFD_IN_MEMORY, the file size is no longer valid. Found when attempting objdump -t on a very small (27 bytes) ILF file and hitting the pr24707 fix (commit 781152ec18f5). So, clear file size when setting BFD_IN_MEMORY on bfds that may have been read. (It's not necessary in writable bfds, because caching is ignored by bfd_get_size when bfd_write_p.) I also think the PR 24707 fix is no longer neeeded. All of the testcases in that PR and in PR24712 are caught earlier by file size checks when reading the symbols from file. So I'm reverting that fix, which just compared the size of an array of symbol pointers against file size. That's only valid if on-disk symbols are larger than a host pointer, so the test is better done in format-specific code. bfd/ * coff-alpha.c (alpha_ecoff_get_elt_at_filepos): Clear cached file size when making a BFD_IN_MEMORY bfd. * opncls.c (bfd_make_readable): Likewise. * peicode.h (pe_ILF_build_a_bfd): Likewise. binutils/ PR 24707 * objdump.c (slurp_symtab): Revert PR24707 fix. Tidy. (slurp_dynamic_symtab): Tidy.
Diffstat (limited to 'binutils/objdump.c')
-rw-r--r--binutils/objdump.c51
1 files changed, 13 insertions, 38 deletions
diff --git a/binutils/objdump.c b/binutils/objdump.c
index 9e76684..4292c23 100644
--- a/binutils/objdump.c
+++ b/binutils/objdump.c
@@ -994,45 +994,22 @@ dump_headers (bfd *abfd)
static asymbol **
slurp_symtab (bfd *abfd)
{
- asymbol **sy = NULL;
- long storage;
-
+ symcount = 0;
if (!(bfd_get_file_flags (abfd) & HAS_SYMS))
- {
- symcount = 0;
- return NULL;
- }
+ return NULL;
- storage = bfd_get_symtab_upper_bound (abfd);
+ long storage = bfd_get_symtab_upper_bound (abfd);
if (storage < 0)
{
- non_fatal (_("failed to read symbol table from: %s"), bfd_get_filename (abfd));
+ non_fatal (_("failed to read symbol table from: %s"),
+ bfd_get_filename (abfd));
bfd_fatal (_("error message was"));
}
- if (storage)
- {
- 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);
- }
+ if (storage == 0)
+ return NULL;
+ asymbol **sy = (asymbol **) xmalloc (storage);
symcount = bfd_canonicalize_symtab (abfd, sy);
if (symcount < 0)
bfd_fatal (bfd_get_filename (abfd));
@@ -1044,26 +1021,24 @@ slurp_symtab (bfd *abfd)
static asymbol **
slurp_dynamic_symtab (bfd *abfd)
{
- asymbol **sy = NULL;
- long storage;
-
- storage = bfd_get_dynamic_symtab_upper_bound (abfd);
+ dynsymcount = 0;
+ long storage = bfd_get_dynamic_symtab_upper_bound (abfd);
if (storage < 0)
{
if (!(bfd_get_file_flags (abfd) & DYNAMIC))
{
non_fatal (_("%s: not a dynamic object"), bfd_get_filename (abfd));
exit_status = 1;
- dynsymcount = 0;
return NULL;
}
bfd_fatal (bfd_get_filename (abfd));
}
- if (storage)
- sy = (asymbol **) xmalloc (storage);
+ if (storage == 0)
+ return NULL;
+ asymbol **sy = (asymbol **) xmalloc (storage);
dynsymcount = bfd_canonicalize_dynamic_symtab (abfd, sy);
if (dynsymcount < 0)
bfd_fatal (bfd_get_filename (abfd));