public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* Linker generating incorrect sh_info values for .dynsym section
@ 2016-08-12 11:59 Nick Clifton
  2016-08-12 13:07 ` Alan Modra
  0 siblings, 1 reply; 3+ messages in thread
From: Nick Clifton @ 2016-08-12 11:59 UTC (permalink / raw)
  To: binutils

Hi Guys,

  It appears that the linker is generating incorrect values for the
  sh_info field of the .dynsym section.  The field is meant to contain
  the index of the first non-local symbol in the .dynsym section, but
  often it does not.

  I created a patch for readelf (see below) to report this problem,
  but when I ran regression tests I found that it triggered for nearly
  all the ELF based targets, including x86_64 and PowerPC.  Two tests in
  particular - PROVIDE HIDDEN test 4 and PROVIDE HIDDEN test 10 seem to
  trigger this problem every time.

  I have spent a day looking through the code in elflink.c but I am not
  getting very far, so I am reaching out for help.  Does anyone have an
  idea as to what might be causing this problem ?

Cheers
  Nick

diff --git a/binutils/readelf.c b/binutils/readelf.c
index e6674c2..586d13c 100644
--- a/binutils/readelf.c
+++ b/binutils/readelf.c
@@ -11114,6 +11114,11 @@ process_symbol_table (FILE * file)
                }
 
              putchar ('\n');
+
+             if (ELF_ST_BIND (psym->st_info) == STB_LOCAL
+                 && si >= section->sh_info)
+               warn (_("local symbol %u found at index >= %s's sh_info value of %u\n"),
+                     si, printable_section_name (section), section->sh_info);
            }
 
          free (symtab);

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Linker generating incorrect sh_info values for .dynsym section
  2016-08-12 11:59 Linker generating incorrect sh_info values for .dynsym section Nick Clifton
@ 2016-08-12 13:07 ` Alan Modra
  2016-08-12 14:44   ` Alan Modra
  0 siblings, 1 reply; 3+ messages in thread
From: Alan Modra @ 2016-08-12 13:07 UTC (permalink / raw)
  To: Nick Clifton; +Cc: binutils

On Fri, Aug 12, 2016 at 12:58:56PM +0100, Nick Clifton wrote:
>   It appears that the linker is generating incorrect values for the
>   sh_info field of the .dynsym section.

Should be fixed with the following.  As yet untested.

diff --git a/bfd/elf-bfd.h b/bfd/elf-bfd.h
index bb3371f..424ea30 100644
--- a/bfd/elf-bfd.h
+++ b/bfd/elf-bfd.h
@@ -524,6 +524,7 @@ struct elf_link_hash_table
   /* The number of symbols found in the link which is intended for the
      mandatory DT_SYMTAB tag (.dynsym section) in .dynamic section.  */
   bfd_size_type dynsymcount;
+  bfd_size_type local_dynsymcount;
 
   /* The string table of dynamic symbols, which becomes the .dynstr
      section.  */
diff --git a/bfd/elflink.c b/bfd/elflink.c
index 5bc5740..9e9a33c 100644
--- a/bfd/elflink.c
+++ b/bfd/elflink.c
@@ -904,6 +904,7 @@ _bfd_elf_link_renumber_dynsyms (bfd *output_bfd,
       for (p = elf_hash_table (info)->dynlocal; p ; p = p->next)
 	p->dynindx = ++dynsymcount;
     }
+  elf_hash_table (info)->local_dynsymcount = dynsymcount;
 
   elf_link_hash_traverse (elf_hash_table (info),
 			  elf_link_renumber_hash_table_dynsyms,
@@ -11781,7 +11782,10 @@ bfd_elf_final_link (bfd *abfd, struct bfd_link_info *info)
     {
       Elf_Internal_Sym sym;
       bfd_byte *dynsym = elf_hash_table (info)->dynsym->contents;
-      long last_local = 0;
+
+      o = elf_hash_table (info)->dynsym->output_section;
+      elf_section_data (o)->this_hdr.sh_info
+	= elf_hash_table (info)->local_dynsymcount + 1;
 
       /* Write out the section symbols for the output sections.  */
       if (bfd_link_pic (info)
@@ -11811,8 +11815,6 @@ bfd_elf_final_link (bfd *abfd, struct bfd_link_info *info)
 		return FALSE;
 	      sym.st_value = s->vma;
 	      dest = dynsym + dynindx * bed->s->sizeof_sym;
-	      if (last_local < dynindx)
-		last_local = dynindx;
 	      bed->s->swap_symbol_out (abfd, &sym, dest, 0);
 	    }
 	}
@@ -11845,16 +11847,10 @@ bfd_elf_final_link (bfd *abfd, struct bfd_link_info *info)
 				  + e->isym.st_value);
 		}
 
-	      if (last_local < e->dynindx)
-		last_local = e->dynindx;
-
 	      dest = dynsym + e->dynindx * bed->s->sizeof_sym;
 	      bed->s->swap_symbol_out (abfd, &sym, dest, 0);
 	    }
 	}
-
-      elf_section_data (elf_hash_table (info)->dynsym->output_section)->this_hdr.sh_info =
-	last_local + 1;
     }
 
   /* We get the global symbols from the hash table.  */

-- 
Alan Modra
Australia Development Lab, IBM

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Linker generating incorrect sh_info values for .dynsym section
  2016-08-12 13:07 ` Alan Modra
@ 2016-08-12 14:44   ` Alan Modra
  0 siblings, 0 replies; 3+ messages in thread
From: Alan Modra @ 2016-08-12 14:44 UTC (permalink / raw)
  To: Nick Clifton; +Cc: binutils

On Fri, Aug 12, 2016 at 10:37:40PM +0930, Alan Modra wrote:
> On Fri, Aug 12, 2016 at 12:58:56PM +0100, Nick Clifton wrote:
> >   It appears that the linker is generating incorrect values for the
> >   sh_info field of the .dynsym section.
> 
> Should be fixed with the following.  As yet untested.

Tested and committed along with the inevitable testsuite update.

bfd/
	* elf-bfd.h (struct elf_link_hash_table): Add local_dynsymcount.
	* elflink.c (_bfd_elf_link_renumber_dynsyms): Set local_dynsymcount.
	(bfd_elf_final_link): Set .dynsym sh_info from local_dynsymcount.
ld/
	* testsuite/ld-tic6x/shlib-1.rd: Correct expected .dynsym sh_info.
	* testsuite/ld-tic6x/shlib-1b.rd: Likewise.
	* testsuite/ld-tic6x/shlib-1r.rd: Likewise.
	* testsuite/ld-tic6x/shlib-1rb.rd: Likewise.
	* testsuite/ld-tic6x/shlib-app-1.rd: Likewise.
	* testsuite/ld-tic6x/shlib-app-1b.rd: Likewise.
	* testsuite/ld-tic6x/shlib-app-1r.rd: Likewise.
	* testsuite/ld-tic6x/shlib-app-1rb.rd: Likewise.
	* testsuite/ld-tic6x/shlib-noindex.rd: Likewise.
	* testsuite/ld-tic6x/static-app-1.rd: Likewise.
	* testsuite/ld-tic6x/static-app-1b.rd: Likewise.
	* testsuite/ld-tic6x/static-app-1r.rd: Likewise.
	* testsuite/ld-tic6x/static-app-1rb.rd: Likewise.

-- 
Alan Modra
Australia Development Lab, IBM

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2016-08-12 14:44 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-08-12 11:59 Linker generating incorrect sh_info values for .dynsym section Nick Clifton
2016-08-12 13:07 ` Alan Modra
2016-08-12 14:44   ` Alan Modra

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).