diff options
author | Alan Modra <amodra@gmail.com> | 2024-10-02 09:02:16 +0930 |
---|---|---|
committer | Alan Modra <amodra@gmail.com> | 2024-10-03 12:31:45 +0930 |
commit | d2ea1a941173223907ef8a91d674af3417ba9dbc (patch) | |
tree | b6430629ea4fc53d618b5cd0acbf9da03d394201 /binutils/nm.c | |
parent | 68bbe118337939aa0b52e007a7415c8a157579a1 (diff) | |
download | binutils-d2ea1a941173223907ef8a91d674af3417ba9dbc.zip binutils-d2ea1a941173223907ef8a91d674af3417ba9dbc.tar.gz binutils-d2ea1a941173223907ef8a91d674af3417ba9dbc.tar.bz2 |
nm: don't try to print line numbers for symbols without names
It doesn't make much sense trying to print line numbers for what are
usually broken symbols, and there is a possibility of a segfault if
we pass strcmp a NULL.
Diffstat (limited to 'binutils/nm.c')
-rw-r--r-- | binutils/nm.c | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/binutils/nm.c b/binutils/nm.c index faf27c5..7acf9a2 100644 --- a/binutils/nm.c +++ b/binutils/nm.c @@ -1227,7 +1227,8 @@ print_symbol (bfd * abfd, format->print_symbol_info (&info, abfd); - if (line_numbers) + const char *symname = bfd_asymbol_name (sym); + if (line_numbers && symname != NULL && symname[0] != 0) { struct lineno_cache *lc = bfd_usrdata (abfd); const char *filename, *functionname; @@ -1258,7 +1259,6 @@ print_symbol (bfd * abfd, else if (bfd_is_und_section (bfd_asymbol_section (sym))) { unsigned int i; - const char *symname; /* For an undefined symbol, we try to find a reloc for the symbol, and print the line number of the reloc. */ @@ -1274,7 +1274,6 @@ print_symbol (bfd * abfd, bfd_map_over_sections (abfd, get_relocs, &rinfo); } - symname = bfd_asymbol_name (sym); for (i = 0; i < lc->seccount; i++) { long j; @@ -1287,6 +1286,7 @@ print_symbol (bfd * abfd, if (r->sym_ptr_ptr != NULL && (*r->sym_ptr_ptr)->section == sym->section && (*r->sym_ptr_ptr)->value == sym->value + && bfd_asymbol_name (*r->sym_ptr_ptr) != NULL && strcmp (symname, bfd_asymbol_name (*r->sym_ptr_ptr)) == 0 && bfd_find_nearest_line (abfd, lc->secs[i], lc->syms, |