aboutsummaryrefslogtreecommitdiff
path: root/binutils
diff options
context:
space:
mode:
authorAlan Modra <amodra@gmail.com>2023-03-08 09:19:38 +1030
committerAlan Modra <amodra@gmail.com>2023-03-08 11:24:55 +1030
commit160f20077865425a5874ed327540ab0bf33fb0d1 (patch)
tree93ed7fe4f476be5978cf0b82058c642b804f1283 /binutils
parentd64c8f7181fd21f90983f8d55369f6f9a2960c43 (diff)
downloadgdb-160f20077865425a5874ed327540ab0bf33fb0d1.zip
gdb-160f20077865425a5874ed327540ab0bf33fb0d1.tar.gz
gdb-160f20077865425a5874ed327540ab0bf33fb0d1.tar.bz2
Re: Move nm.c cached line number info to bfd usrdata
Commit e3f450f3933d resulted in a nm -l segfault on object files without undefined symbols. Fix that, and be paranoid about bfd section count changing. * nm.c (struct lineno_cache): Add seccount. (free_lineno_cache): Don't segfault on NULL lc->relocs. (print_symbol): Stash section count when creating arrays.
Diffstat (limited to 'binutils')
-rw-r--r--binutils/nm.c13
1 files changed, 7 insertions, 6 deletions
diff --git a/binutils/nm.c b/binutils/nm.c
index 8b6b249..f96cfa3 100644
--- a/binutils/nm.c
+++ b/binutils/nm.c
@@ -62,6 +62,7 @@ struct lineno_cache
long *relcount;
asymbol **syms;
long symcount;
+ unsigned int seccount;
};
struct extended_symbol_info
@@ -1165,9 +1166,8 @@ free_lineno_cache (bfd *abfd)
if (lc)
{
- unsigned int seccount = bfd_count_sections (abfd);
- for (unsigned int i = 0; i < seccount; i++)
- if (lc->relocs[i] != NULL)
+ if (lc->relocs)
+ for (unsigned int i = 0; i < lc->seccount; i++)
free (lc->relocs[i]);
free (lc->relcount);
free (lc->relocs);
@@ -1254,12 +1254,13 @@ print_symbol (bfd * abfd,
{
unsigned int i;
const char *symname;
- unsigned int seccount = bfd_count_sections (abfd);
/* For an undefined symbol, we try to find a reloc for the
symbol, and print the line number of the reloc. */
if (lc->relocs == NULL)
{
+ unsigned int seccount = bfd_count_sections (abfd);
+ lc->seccount = seccount;
lc->secs = xmalloc (seccount * sizeof (*lc->secs));
lc->relocs = xmalloc (seccount * sizeof (*lc->relocs));
lc->relcount = xmalloc (seccount * sizeof (*lc->relcount));
@@ -1269,7 +1270,7 @@ print_symbol (bfd * abfd,
}
symname = bfd_asymbol_name (sym);
- for (i = 0; i < seccount; i++)
+ for (i = 0; i < lc->seccount; i++)
{
long j;
@@ -1290,7 +1291,7 @@ print_symbol (bfd * abfd,
{
/* We only print the first one we find. */
printf ("\t%s:%u", filename, lineno);
- i = seccount;
+ i = lc->seccount;
break;
}
}