diff options
author | Alan Modra <amodra@gmail.com> | 2024-10-01 14:08:08 +0930 |
---|---|---|
committer | Alan Modra <amodra@gmail.com> | 2024-10-03 12:31:45 +0930 |
commit | 68bbe118337939aa0b52e007a7415c8a157579a1 (patch) | |
tree | 71b25a79d7662c93097e0e1dddf34de5f69fcf28 | |
parent | a3aa9cb83fd2576c78031f7f052ec74965d9178f (diff) | |
download | binutils-68bbe118337939aa0b52e007a7415c8a157579a1.zip binutils-68bbe118337939aa0b52e007a7415c8a157579a1.tar.gz binutils-68bbe118337939aa0b52e007a7415c8a157579a1.tar.bz2 |
Don't return "(null)" from bfd_elf_sym_name
A NULL return from bfd_elf_string_from_elf_section indicates an error.
That shouldn't be masked by bfd_elf_sym_name but rather passed up to
callers such as group_signature. If we want to print "(null)" then
that should be done at a higher level. That's what this patch does,
except that I chose to print "<null>" instead, like readelf. If we
see "(null)" we're probably passing a NULL to printf. I haven't
changed aoutx.h or pdp11.c print_symbol functions because they already
handle NULL names by omitting the name. I also haven't changed
mach-o.c, mmo.c, som.c, srec.c, tekhex.c, vms-alpha.c and
wasm-module.c print_symbol function because it looks like they will
never have NULL symbol names.
bfd/
* elf.c (bfd_elf_sym_name): Don't turn a NULL name into a
pointer to "(null)".
(bfd_elf_print_symbol): Print "<null>" for NULL symbol names.
* coffgen.c (coff_print_symbol): Likewise.
* ecoff.c (_bfd_ecoff_print_symbol): Likewise.
* pef.c (bfd_pef_print_symbol): Likewise.
* syms.c (bfd_symbol_info): Return "<null>" in symbol_info.name
if symbol name is NULL.
ld/
* ldlang.c (ld_is_local_symbol): Don't check for "(null)"
symbol name.
-rw-r--r-- | bfd/coffgen.c | 12 | ||||
-rw-r--r-- | bfd/ecoff.c | 5 | ||||
-rw-r--r-- | bfd/elf.c | 19 | ||||
-rw-r--r-- | bfd/pef.c | 7 | ||||
-rw-r--r-- | bfd/syms.c | 2 | ||||
-rw-r--r-- | ld/ldlang.c | 3 |
6 files changed, 24 insertions, 24 deletions
diff --git a/bfd/coffgen.c b/bfd/coffgen.c index cc1c655..ff382a7 100644 --- a/bfd/coffgen.c +++ b/bfd/coffgen.c @@ -2161,11 +2161,12 @@ coff_print_symbol (bfd *abfd, bfd_print_symbol_type how) { FILE * file = (FILE *) filep; + const char *symname = symbol->name ? symbol->name : "<null>"; switch (how) { case bfd_print_symbol_name: - fprintf (file, "%s", symbol->name); + fprintf (file, "%s", symname); break; case bfd_print_symbol_more: @@ -2189,7 +2190,7 @@ coff_print_symbol (bfd *abfd, if (combined < obj_raw_syments (abfd) || combined >= obj_raw_syments (abfd) + obj_raw_syment_count (abfd)) { - fprintf (file, _("<corrupt info> %s"), symbol->name); + fprintf (file, _("<corrupt info> %s"), symname); break; } @@ -2207,7 +2208,7 @@ coff_print_symbol (bfd *abfd, combined->u.syment.n_sclass, combined->u.syment.n_numaux); bfd_fprintf_vma (abfd, file, val); - fprintf (file, " %s", symbol->name); + fprintf (file, " %s", symname); for (aux = 0; aux < combined->u.syment.n_numaux; aux++) { @@ -2297,7 +2298,8 @@ coff_print_symbol (bfd *abfd, if (l) { - fprintf (file, "\n%s :", l->u.sym->name); + fprintf (file, "\n%s :", + l->u.sym->name ? l->u.sym->name : "<null>"); l++; while (l->line_number) { @@ -2317,7 +2319,7 @@ coff_print_symbol (bfd *abfd, symbol->section->name, coffsymbol (symbol)->native ? "n" : "g", coffsymbol (symbol)->lineno ? "l" : " ", - symbol->name); + symname); } } } diff --git a/bfd/ecoff.c b/bfd/ecoff.c index 5ee7ffa..93b93f3 100644 --- a/bfd/ecoff.c +++ b/bfd/ecoff.c @@ -1452,11 +1452,12 @@ _bfd_ecoff_print_symbol (bfd *abfd, const struct ecoff_debug_swap * const debug_swap = &ecoff_backend (abfd)->debug_swap; FILE *file = (FILE *)filep; + const char *symname = symbol->name ? symbol->name : "<null>"; switch (how) { case bfd_print_symbol_name: - fprintf (file, "%s", symbol->name); + fprintf (file, "%s", symname); break; case bfd_print_symbol_more: if (ecoffsymbol (symbol)->local) @@ -1526,7 +1527,7 @@ _bfd_ecoff_print_symbol (bfd *abfd, (unsigned) ecoff_ext.asym.sc, (unsigned) ecoff_ext.asym.index, jmptbl, cobol_main, weakext, - symbol->name); + symname); if (ecoffsymbol (symbol)->fdr != NULL && ecoff_ext.asym.index != indexNil) @@ -549,9 +549,7 @@ bfd_elf_sym_name (bfd *abfd, } name = bfd_elf_string_from_elf_section (abfd, shindex, iname); - if (name == NULL) - name = "(null)"; - else if (sym_sec && *name == '\0') + if (sym_sec && name && *name == '\0') name = bfd_section_name (sym_sec); return name; @@ -2314,10 +2312,12 @@ bfd_elf_print_symbol (bfd *abfd, bfd_print_symbol_type how) { FILE *file = (FILE *) filep; + const char *symname = symbol->name ? symbol->name : "<null>"; + switch (how) { case bfd_print_symbol_name: - fprintf (file, "%s", symbol->name); + fprintf (file, "%s", symname); break; case bfd_print_symbol_more: fprintf (file, "elf "); @@ -2340,11 +2340,10 @@ bfd_elf_print_symbol (bfd *abfd, if (bed->elf_backend_print_symbol_all) name = (*bed->elf_backend_print_symbol_all) (abfd, filep, symbol); - if (name == NULL) - { - name = symbol->name; - bfd_print_symbol_vandf (abfd, file, symbol); - } + if (name != NULL) + symname = name; + else + bfd_print_symbol_vandf (abfd, file, symbol); fprintf (file, " %s\t", section_name); /* Print the "other" value for a symbol. For common symbols, @@ -2391,7 +2390,7 @@ bfd_elf_print_symbol (bfd *abfd, fprintf (file, " 0x%02x", (unsigned int) st_other); } - fprintf (file, " %s", name); + fprintf (file, " %s", symname); } break; } @@ -210,16 +210,17 @@ bfd_pef_print_symbol (bfd *abfd, bfd_print_symbol_type how) { FILE *file = (FILE *) afile; + const char *symname = symbol->name ? symbol->name : "<null>"; switch (how) { case bfd_print_symbol_name: - fprintf (file, "%s", symbol->name); + fprintf (file, "%s", symname); break; default: bfd_print_symbol_vandf (abfd, (void *) file, symbol); - fprintf (file, " %-5s %s", symbol->section->name, symbol->name); - if (startswith (symbol->name, "__traceback_")) + fprintf (file, " %-5s %s", symbol->section->name, symname); + if (startswith (symname, "__traceback_")) { unsigned char *buf; size_t offset = symbol->value + 4; @@ -777,7 +777,7 @@ bfd_symbol_info (asymbol *symbol, symbol_info *ret) else ret->value = symbol->value + symbol->section->vma; - ret->name = symbol->name; + ret->name = symbol->name ? symbol->name : "<null>"; } /* diff --git a/ld/ldlang.c b/ld/ldlang.c index 7f9e3d2..343c4de 100644 --- a/ld/ldlang.c +++ b/ld/ldlang.c @@ -4895,9 +4895,6 @@ ld_is_local_symbol (asymbol * sym) if (name == NULL || *name == 0) return false; - if (strcmp (name, "(null)") == 0) - return false; - /* Skip .Lxxx and such like. */ if (bfd_is_local_label (link_info.output_bfd, sym)) return false; |