This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

PATCH: Ignore section symbols without a BFD section


Hi,

GNU linker never puts .shstrtab, .symtab and .strtab section symbols in
symtab while Solaris linker does.  When there are .shstrtab, .symtab and
.strtab section symbols in symtab in input, objcopy just puts some
random section index in symtab since we never create BFD section for
them.  This patch ignores section symbols without a BFD section and
also checks bad section index in symtab.  OK to install?

Thanks.


H.J.
---
bfd/

	PR binutils/14493
	* elf.c (ignore_section_sym): Also ignore section symbols without
	a BFD section.
 
binutils/

	PR binutils/14493
	* readelf.c (get_symbol_index_type): Check bad section index.

diff --git a/bfd/elf.c b/bfd/elf.c
index 0208e05..b4043b1 100644
--- a/bfd/elf.c
+++ b/bfd/elf.c
@@ -3264,13 +3264,21 @@ sym_is_global (bfd *abfd, asymbol *sym)
 }
 
 /* Don't output section symbols for sections that are not going to be
-   output, or that are duplicates.  */
+   output, that are duplicates or there is no BFD section.  */
 
 static bfd_boolean
 ignore_section_sym (bfd *abfd, asymbol *sym)
 {
-  return ((sym->flags & BSF_SECTION_SYM) != 0
-	  && !(sym->section->owner == abfd
+  elf_symbol_type *type_ptr;
+
+  if ((sym->flags & BSF_SECTION_SYM) == 0)
+    return FALSE;
+
+  type_ptr = elf_symbol_from (abfd, sym);
+  return ((type_ptr != NULL
+	   && type_ptr->internal_elf_sym.st_shndx != 0
+	   && bfd_is_abs_section (sym->section))
+	  || !(sym->section->owner == abfd
 	       || (sym->section->output_section->owner == abfd
 		   && sym->section->output_offset == 0)
 	       || bfd_is_abs_section (sym->section)));

diff --git a/binutils/readelf.c b/binutils/readelf.c
index 89cff24..2fbf2ae 100644
--- a/binutils/readelf.c
+++ b/binutils/readelf.c
@@ -8974,6 +8974,8 @@ get_symbol_index_type (unsigned int type)
 	sprintf (buff, "OS [0x%04x]", type & 0xffff);
       else if (type >= SHN_LORESERVE)
 	sprintf (buff, "RSV[0x%04x]", type & 0xffff);
+      else if (type >= elf_header.e_shnum)
+	sprintf (buff, "bad section index[%3d]", type);
       else
 	sprintf (buff, "%3d", type);
       break;
-- 
1.7.11.2


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]