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.
This commit is contained in:
Alan Modra 2024-10-01 14:08:08 +09:30
parent a3aa9cb83f
commit 68bbe11833
6 changed files with 24 additions and 24 deletions

View file

@ -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);
}
}
}

View file

@ -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)

View file

@ -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;
}

View file

@ -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;

View file

@ -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>";
}
/*

View file

@ -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;