aboutsummaryrefslogtreecommitdiff
path: root/bfd/syms.c
diff options
context:
space:
mode:
authorAlan Modra <amodra@gmail.com>2024-10-08 10:05:39 +1030
committerAlan Modra <amodra@gmail.com>2024-10-08 15:12:19 +1030
commit124deb310116982fbd921ab1dc83fa75a8252391 (patch)
tree8a21c057e3103c2d33e1741b483af9df64292024 /bfd/syms.c
parentcc516199d64768b32bc4f8572ade82b4865eccfa (diff)
downloadgdb-124deb310116982fbd921ab1dc83fa75a8252391.zip
gdb-124deb310116982fbd921ab1dc83fa75a8252391.tar.gz
gdb-124deb310116982fbd921ab1dc83fa75a8252391.tar.bz2
Revised "Don't return (null) from bfd_elf_sym_name"
Commit 68bbe1183379 results in a lot of follow up work, much of which likely is still to be done. (And yes, since this is all for corrupted or fuzzed object files, a whole lot of work doesn't much benefit anyone. It was a bad idea to put NULL in asymbol->name.) So I'm changing the approach to instead put a unique empty string for symbols with a corrupted st_name. An empty string won't require much work to ensure nm, objcopy, objdump etc. won't crash, since these tools already must work with unnamed local symbols. The unique empty string is called bfd_symbol_error_name. This patch uses that name string for corrupted symbols in the ELF and COFF backends. Such symbols are displayed by nm and objdump as the translated string "<corrupt>", which is what the COFF backend used to put directly into corrupted symbols. ie. it's the way I should have written the original patch, plus a few tides and cleanups I retained from the reverted patches.
Diffstat (limited to 'bfd/syms.c')
-rw-r--r--bfd/syms.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/bfd/syms.c b/bfd/syms.c
index b370a33..68f0730 100644
--- a/bfd/syms.c
+++ b/bfd/syms.c
@@ -342,6 +342,11 @@ EXTERNAL
. const char *stab_name; {* String for stab type. *}
.} symbol_info;
.
+.{* An empty string that will not match the address of any other
+. symbol name, even unnamed local symbols which will also have empty
+. string names. This can be used to flag a symbol as corrupt if its
+. name uses an out of range string table index. *}
+.extern const char bfd_symbol_error_name[];
*/
#include "sysdep.h"
@@ -351,6 +356,8 @@ EXTERNAL
#include "bfdlink.h"
#include "aout/stab_gnu.h"
+const char bfd_symbol_error_name[] = { 0 };
+
/*
DOCDD
INODE
@@ -394,7 +401,7 @@ bfd_is_local_label (bfd *abfd, asymbol *sym)
if we didn't reject them here. */
if ((sym->flags & (BSF_GLOBAL | BSF_WEAK | BSF_FILE | BSF_SECTION_SYM)) != 0)
return false;
- if (sym->name == NULL)
+ if (sym->name == NULL || sym->name == bfd_symbol_error_name)
return false;
return bfd_is_local_label_name (abfd, sym->name);
}
@@ -777,7 +784,8 @@ bfd_symbol_info (asymbol *symbol, symbol_info *ret)
else
ret->value = symbol->value + symbol->section->vma;
- ret->name = symbol->name;
+ ret->name = (symbol->name != bfd_symbol_error_name
+ ? symbol->name : _("<corrupt>"));
}
/*