aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Beulich <jbeulich@suse.com>2025-04-07 12:45:30 +0200
committerJan Beulich <jbeulich@suse.com>2025-04-07 12:45:30 +0200
commite71f5f09ce75ed54c75fd5a7ca47f0452081e26e (patch)
tree69867a0a1db28a6518a634e7af818837d7a93964
parent6fe5e01b131716e3000edb5c6b4a1d1a26dd144c (diff)
downloadbinutils-e71f5f09ce75ed54c75fd5a7ca47f0452081e26e.zip
binutils-e71f5f09ce75ed54c75fd5a7ca47f0452081e26e.tar.gz
binutils-e71f5f09ce75ed54c75fd5a7ca47f0452081e26e.tar.bz2
nm: fall back to heuristic when ELF symbol has zero size
Size being set for a symbol isn't a strict requirement in ELF. For ones not having their size set, fall back to the same logic as used for non- ELF, non-COFF symbols. While there switch to using elf_symbol_from() instead of kind of open- coding it.
-rw-r--r--binutils/nm.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/binutils/nm.c b/binutils/nm.c
index 1a8615e..7ef5d61 100644
--- a/binutils/nm.c
+++ b/binutils/nm.c
@@ -80,6 +80,7 @@ struct extended_symbol_info
#define SYM_STAB_OTHER(sym) (sym->sinfo->stab_other)
#define SYM_SIZE(sym) \
(sym->elfinfo \
+ && sym->elfinfo->internal_elf_sym.st_size \
? sym->elfinfo->internal_elf_sym.st_size \
: sym->coffinfo \
&& ISFCN (sym->coffinfo->native->u.syment.n_type) \
@@ -1088,6 +1089,7 @@ sort_symbols_by_size (bfd *abfd, bool is_dynamic, void *minisyms,
asection *sec;
bfd_vma sz;
asymbol *temp;
+ const elf_symbol_type *elfsym;
const coff_symbol_type *coffsym;
if (from + size < fromend)
@@ -1108,8 +1110,9 @@ sort_symbols_by_size (bfd *abfd, bool is_dynamic, void *minisyms,
we can't rely on that information for the symbol size. Ditto for
bfd/section.c:global_syms like *ABS*. */
if ((sym->flags & (BSF_SECTION_SYM | BSF_SYNTHETIC)) == 0
- && bfd_get_flavour (abfd) == bfd_target_elf_flavour)
- sz = ((elf_symbol_type *) sym)->internal_elf_sym.st_size;
+ && (elfsym = elf_symbol_from (sym)) != NULL
+ && elfsym->internal_elf_sym.st_size != 0)
+ sz = elfsym->internal_elf_sym.st_size;
else if ((sym->flags & (BSF_SECTION_SYM | BSF_SYNTHETIC)) == 0
&& (coffsym = coff_symbol_from (sym)) != NULL
&& ISFCN (coffsym->native->u.syment.n_type)