This is the mail archive of the binutils-cvs@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]

[binutils-gdb] Properly set sh_info for .rela.plt/rel.plt section


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=bd53a53af486c6e5ab88b7f64342244392be1f1f

commit bd53a53af486c6e5ab88b7f64342244392be1f1f
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Mon Mar 30 04:40:33 2015 -0700

    Properly set sh_info for .rela.plt/rel.plt section
    
    Since .rela.plt/rel.plt section may contain relocations against .got.plt
    section, we set sh_info for .rela.plt/rel.plt section to .got.plt section
    index if target has .got.plt section.
    
    bfd/
    
    	PR ld/18169
    	* elf-bfd.h (elf_backend_data): Add get_reloc_section.
    	(_bfd_elf_get_reloc_section): New.
    	* elf.c (_bfd_elf_get_reloc_section): Likewise.
    	(assign_section_numbers): Call get_reloc_section to look up the
    	section the relocs apply.
    	* elfxx-target.h (elf_backend_get_reloc_section): Likewise.
    	(elfNN_bed): Initialize get_reloc_section with
    	elf_backend_get_reloc_section.
    
    ld/testsuite/
    
    	PR ld/18169
    	* ld-elf/linkinfo1a.d: Updated.
    	* ld-elf/linkinfo1b.d: Likewise.

Diff:
---
 bfd/ChangeLog                    | 12 +++++++++++
 bfd/elf-bfd.h                    |  5 +++++
 bfd/elf.c                        | 43 ++++++++++++++++++++++++++++++++--------
 bfd/elfxx-target.h               |  5 +++++
 ld/testsuite/ChangeLog           |  6 ++++++
 ld/testsuite/ld-elf/linkinfo1a.d |  4 +++-
 ld/testsuite/ld-elf/linkinfo1b.d |  4 +++-
 7 files changed, 69 insertions(+), 10 deletions(-)

diff --git a/bfd/ChangeLog b/bfd/ChangeLog
index 062e636..25bec34 100644
--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -1,3 +1,15 @@
+2015-03-30  H.J. Lu  <hongjiu.lu@intel.com>
+
+	PR ld/18169
+	* elf-bfd.h (elf_backend_data): Add get_reloc_section.
+	(_bfd_elf_get_reloc_section): New.
+	* elf.c (_bfd_elf_get_reloc_section): Likewise.
+	(assign_section_numbers): Call get_reloc_section to look up the
+	section the relocs apply.
+	* elfxx-target.h (elf_backend_get_reloc_section): Likewise.
+	(elfNN_bed): Initialize get_reloc_section with
+	elf_backend_get_reloc_section.
+
 2015-03-29  H.J. Lu  <hongjiu.lu@intel.com>
 
 	* Makefile.am (ZLIB): New.
diff --git a/bfd/elf-bfd.h b/bfd/elf-bfd.h
index 53ef9d8..e435e52 100644
--- a/bfd/elf-bfd.h
+++ b/bfd/elf-bfd.h
@@ -1239,6 +1239,9 @@ struct elf_backend_data
   bfd_size_type (*maybe_function_sym) (const asymbol *sym, asection *sec,
 				       bfd_vma *code_off);
 
+  /* Return the section which RELOC_SEC applies to.  */
+  asection *(*get_reloc_section) (asection *reloc_sec);
+
   /* Used to handle bad SHF_LINK_ORDER input.  */
   bfd_error_handler_type link_order_error_handler;
 
@@ -2247,6 +2250,8 @@ extern bfd_boolean _bfd_elf_is_function_type (unsigned int);
 extern bfd_size_type _bfd_elf_maybe_function_sym (const asymbol *, asection *,
 						  bfd_vma *);
 
+extern asection *_bfd_elf_get_reloc_section (asection *);
+
 extern int bfd_elf_get_default_section_type (flagword);
 
 extern bfd_boolean bfd_elf_lookup_section_flags
diff --git a/bfd/elf.c b/bfd/elf.c
index c4defda..f3c9050 100644
--- a/bfd/elf.c
+++ b/bfd/elf.c
@@ -3074,6 +3074,40 @@ bfd_elf_set_group_contents (bfd *abfd, asection *sec, void *failedptrarg)
   H_PUT_32 (abfd, sec->flags & SEC_LINK_ONCE ? GRP_COMDAT : 0, loc);
 }
 
+/* Return the section which RELOC_SEC applies to.  */
+
+asection *
+_bfd_elf_get_reloc_section (asection *reloc_sec)
+{
+  const char *name;
+  unsigned int type;
+  bfd *abfd;
+
+  if (reloc_sec == NULL)
+    return NULL;
+
+  type = elf_section_data (reloc_sec)->this_hdr.sh_type;
+  if (type != SHT_REL && type != SHT_RELA)
+    return NULL;
+
+  /* We look up the section the relocs apply to by name.  */
+  name = reloc_sec->name;
+  if (type == SHT_REL)
+    name += 4;
+  else
+    name += 5;
+
+  /* If a target needs .got.plt section, relocations in rela.plt/rel.plt
+     section apply to .got.plt section.  */
+  abfd = reloc_sec->owner;
+  if (get_elf_backend_data (abfd)->want_got_plt
+      && strcmp (name, ".plt") == 0)
+    name = ".got.plt";
+
+  reloc_sec = bfd_get_section_by_name (abfd, name);
+  return reloc_sec;
+}
+
 /* Assign all ELF section numbers.  The dummy first section is handled here
    too.  The link/info pointers for the standard section types are filled
    in here too, while we're at it.  */
@@ -3209,7 +3243,6 @@ assign_section_numbers (bfd *abfd, struct bfd_link_info *link_info)
   for (sec = abfd->sections; sec; sec = sec->next)
     {
       asection *s;
-      const char *name;
 
       d = elf_section_data (sec);
 
@@ -3313,13 +3346,7 @@ assign_section_numbers (bfd *abfd, struct bfd_link_info *link_info)
 	  if (s != NULL)
 	    d->this_hdr.sh_link = elf_section_data (s)->this_idx;
 
-	  /* We look up the section the relocs apply to by name.  */
-	  name = sec->name;
-	  if (d->this_hdr.sh_type == SHT_REL)
-	    name += 4;
-	  else
-	    name += 5;
-	  s = bfd_get_section_by_name (abfd, name);
+	  s = get_elf_backend_data (abfd)->get_reloc_section (sec);
 	  if (s != NULL)
 	    {
 	      d->this_hdr.sh_info = elf_section_data (s)->this_idx;
diff --git a/bfd/elfxx-target.h b/bfd/elfxx-target.h
index 9760db4..5623662 100644
--- a/bfd/elfxx-target.h
+++ b/bfd/elfxx-target.h
@@ -672,6 +672,10 @@
 #define elf_backend_maybe_function_sym _bfd_elf_maybe_function_sym
 #endif
 
+#ifndef elf_backend_get_reloc_section
+#define elf_backend_get_reloc_section _bfd_elf_get_reloc_section
+#endif
+
 #ifndef elf_match_priority
 #define elf_match_priority \
   (ELF_ARCH == bfd_arch_unknown ? 2 : ELF_OSABI == ELFOSABI_NONE ? 1 : 0)
@@ -769,6 +773,7 @@ static struct elf_backend_data elfNN_bed =
   elf_backend_hash_symbol,
   elf_backend_is_function_type,
   elf_backend_maybe_function_sym,
+  elf_backend_get_reloc_section,
   elf_backend_link_order_error_handler,
   elf_backend_relplt_name,
   ELF_MACHINE_ALT1,
diff --git a/ld/testsuite/ChangeLog b/ld/testsuite/ChangeLog
index 8911a9a..ff9ba66 100644
--- a/ld/testsuite/ChangeLog
+++ b/ld/testsuite/ChangeLog
@@ -1,3 +1,9 @@
+2015-03-30  H.J. Lu  <hongjiu.lu@intel.com>
+
+	PR ld/18169
+	* ld-elf/linkinfo1a.d: Updated.
+	* ld-elf/linkinfo1b.d: Likewise.
+
 2015-03-27  H.J. Lu  <hongjiu.lu@intel.com>
 
 	* ld-x86-64/pr18160.d: Don't run for x86_64-*-nacl* target.
diff --git a/ld/testsuite/ld-elf/linkinfo1a.d b/ld/testsuite/ld-elf/linkinfo1a.d
index 8c6fb71..b5ccf6f 100644
--- a/ld/testsuite/ld-elf/linkinfo1a.d
+++ b/ld/testsuite/ld-elf/linkinfo1a.d
@@ -4,5 +4,7 @@
 #target: x86_64-* i?86-*
 
 #...
-  \[[ 0-9]+\] \.rel[a]?\.plt[ \t]+REL[A]?[ \t][ \t0-9a-f]+AI[ \t0-9a-f]+
+  \[[ 0-9]+\] \.rel[a]?\.plt[ \t]+REL[A]?[ \t][ \t0-9a-f]+AI[ \t]+[0-9a-f]+[ \t]+9[ \t]+[0-9a-f]+
+#...
+  \[[ 9\] \.got.plt[ \t]+PROGBITS?[ \t][ \t0-9a-f]+WA[ \t]+[0-9a-f]+[ \t]+0[ \t]+[0-9a-f]+
 #pass
diff --git a/ld/testsuite/ld-elf/linkinfo1b.d b/ld/testsuite/ld-elf/linkinfo1b.d
index cc3aaed..cb17683 100644
--- a/ld/testsuite/ld-elf/linkinfo1b.d
+++ b/ld/testsuite/ld-elf/linkinfo1b.d
@@ -5,5 +5,7 @@
 #target: x86_64-* i?86-*
 
 #...
-  \[[ 0-9]+\] \.rel[a]?\.plt[ \t]+REL[A]?[ \t][ \t0-9a-f]+AI[ \t0-9a-f]+
+  \[[ 0-9]+\] \.rel[a]?\.plt[ \t]+REL[A]?[ \t][ \t0-9a-f]+AI[ \t]+[0-9a-f]+[ \t]+9[ \t]+[0-9a-f]+
+#...
+  \[[ 9\] \.got.plt[ \t]+PROGBITS?[ \t][ \t0-9a-f]+WA[ \t]+[0-9a-f]+[ \t]+0[ \t]+[0-9a-f]+
 #pass


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