[PATCH 04/11] alpha: factor out elf64_alpha_sym_name

Matt Turner <[email protected]>
Newsgroups gmane.comp.gnu.binutils
Message-ID <[email protected]>
relocate_section spells out how to name the symbol a relocation refers
to, which is one thing for a global symbol and another for a local one.
Later diagnostics need the same, so give it a name.

The open-coded version is replaced by bfd_elf_sym_name, which every
other backend uses here. It names a section symbol by its section rather
than by an empty string, and a symbol whose name cannot be read comes
out empty rather than as "<unknown>".
---
 bfd/elf64-alpha.c | 27 ++++++++++++++++-----------
 1 file changed, 16 insertions(+), 11 deletions(-)

diff --git ./bfd/elf64-alpha.c ./bfd/elf64-alpha.c
index 86a59ba0937..fef3c0127aa 100644
--- ./bfd/elf64-alpha.c
+++ ./bfd/elf64-alpha.c
@@ -4104,6 +4104,20 @@ elf64_alpha_relocate_section_r (struct bfd_link_info *info ATTRIBUTE_UNUSED,
   return ret_val;
 }
 
+/* The name of the symbol a relocation refers to, for diagnostics.  H
+   describes the symbol when it is global and SYM when it is local.  */
+
+static const char *
+elf64_alpha_sym_name (bfd *abfd, Elf_Internal_Shdr *symtab_hdr,
+		      struct alpha_elf_link_hash_entry *h,
+		      Elf_Internal_Sym *sym, asection *sec)
+{
+  if (h != NULL)
+    return h->root.root.root.string;
+
+  return bfd_elf_sym_name (abfd, symtab_hdr, sym, sec);
+}
+
 /* Relocate an Alpha ELF section.  */
 
 static int
@@ -4443,17 +4457,8 @@ elf64_alpha_relocate_section (struct bfd_link_info *info,
 		value += 8;
 		break;
 	      default:
-		if (h != NULL)
-		  name = h->root.root.root.string;
-		else
-		  {
-		    name = (bfd_elf_string_from_elf_section
-			    (input_bfd, symtab_hdr->sh_link, sym->st_name));
-		    if (name == NULL)
-		      name = _("<unknown>");
-		    else if (name[0] == 0)
-		      name = bfd_section_name (sec);
-		  }
+		name = elf64_alpha_sym_name (input_bfd, symtab_hdr, h, sym,
+					     sec);
 		_bfd_error_handler
 		  /* xgettext:c-format */
 		  (_("%pB: !samegp reloc against symbol without .prologue: %s"),
-- 
2.54.0
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.