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] x86 map file textrel


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

commit 826c3f1edc2f9da4594aed86b57a7b447a46016d
Author: Alan Modra <amodra@gmail.com>
Date:   Sat Dec 2 14:48:50 2017 +1030

    x86 map file textrel
    
    bfd/
    	* elfxx-x86.c (readonly_dynrelocs): New function.
    	(maybe_set_textrel): New function.  Always prints via minfo and
    	correct "readonly" to "read-only" in warning message., replacing..
    	(_bfd_x86_elf_readonly_dynrelocs): ..this.
    	(_bfd_x86_elf_size_dynamic_sections): Correct "readonly" to
    	"read-only" in warning message.  Formatting.
    	(_bfd_x86_elf_adjust_dynamic_symbol): Use readonly_dynrelocs.
    	* linker.c (bfd_link_hash_traverse): Comment typo fix.
    ld/
    	* testsuite/ld-i386/pr17935-1.d: Adjust expected error.
    	* testsuite/ld-i386/pr17935-2.d: Likewise.
    	* testsuite/ld-x86-64/pr17935-1.d: Likewise.
    	* testsuite/ld-x86-64/pr17935-2.d: Likewise.

Diff:
---
 bfd/ChangeLog                      | 11 +++++
 bfd/elfxx-x86.c                    | 91 ++++++++++++++++++++------------------
 bfd/linker.c                       |  2 +-
 ld/ChangeLog                       |  7 +++
 ld/testsuite/ld-i386/pr17935-1.d   |  2 +-
 ld/testsuite/ld-i386/pr17935-2.d   |  2 +-
 ld/testsuite/ld-x86-64/pr17935-1.d |  2 +-
 ld/testsuite/ld-x86-64/pr17935-2.d |  2 +-
 8 files changed, 72 insertions(+), 47 deletions(-)

diff --git a/bfd/ChangeLog b/bfd/ChangeLog
index 95fb5cd..b20003b 100644
--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -1,3 +1,14 @@
+2017-12-04  Alan Modra  <amodra@gmail.com>
+
+	* elfxx-x86.c (readonly_dynrelocs): New function.
+	(maybe_set_textrel): New function.  Always prints via minfo and
+	correct "readonly" to "read-only" in warning message., replacing..
+	(_bfd_x86_elf_readonly_dynrelocs): ..this.
+	(_bfd_x86_elf_size_dynamic_sections): Correct "readonly" to
+	"read-only" in warning message.  Formatting.
+	(_bfd_x86_elf_adjust_dynamic_symbol): Use readonly_dynrelocs.
+	* linker.c (bfd_link_hash_traverse): Comment typo fix.
+
 2017-12-01  H.J. Lu  <hongjiu.lu@intel.com>
 
 	* elfxx-x86.c (_bfd_x86_elf_readonly_dynrelocs): Print symbol
diff --git a/bfd/elfxx-x86.c b/bfd/elfxx-x86.c
index 3899c13..1a9e5ef 100644
--- a/bfd/elfxx-x86.c
+++ b/bfd/elfxx-x86.c
@@ -521,45 +521,58 @@ elf_x86_allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf)
   return TRUE;
 }
 
-/* Find any dynamic relocs that apply to read-only sections.  */
+/* Find dynamic relocs for H that apply to read-only sections.  */
 
-bfd_boolean
-_bfd_x86_elf_readonly_dynrelocs (struct elf_link_hash_entry *h,
-				 void *inf)
+static asection *
+readonly_dynrelocs (struct elf_link_hash_entry *h)
 {
-  struct elf_x86_link_hash_entry *eh;
   struct elf_dyn_relocs *p;
 
+  for (p = elf_x86_hash_entry (h)->dyn_relocs; p != NULL; p = p->next)
+    {
+      asection *s = p->sec->output_section;
+
+      if (s != NULL && (s->flags & SEC_READONLY) != 0)
+	return p->sec;
+    }
+  return NULL;
+}
+
+/* Set DF_TEXTREL if we find any dynamic relocs that apply to
+   read-only sections.  */
+
+static bfd_boolean
+maybe_set_textrel (struct elf_link_hash_entry *h, void *inf)
+{
+  asection *sec;
+
+  if (h->root.type == bfd_link_hash_indirect)
+    return TRUE;
+
   /* Skip local IFUNC symbols. */
   if (h->forced_local && h->type == STT_GNU_IFUNC)
     return TRUE;
 
-  eh = (struct elf_x86_link_hash_entry *) h;
-  for (p = eh->dyn_relocs; p != NULL; p = p->next)
+  sec = readonly_dynrelocs (h);
+  if (sec != NULL)
     {
-      asection *s = p->sec->output_section;
-
-      if (s != NULL && (s->flags & SEC_READONLY) != 0)
-	{
-	  struct bfd_link_info *info = (struct bfd_link_info *) inf;
+      struct bfd_link_info *info = (struct bfd_link_info *) inf;
 
-	  info->flags |= DF_TEXTREL;
+      info->flags |= DF_TEXTREL;
+      /* xgettext:c-format */
+      info->callbacks->minfo (_("%B: dynamic relocation against `%T' "
+				"in read-only section `%A'\n"),
+			      sec->owner, h->root.root.string, sec);
 
-	  if ((info->warn_shared_textrel && bfd_link_pic (info))
-	      || info->error_textrel)
-	    /* xgettext:c-format */
-	    info->callbacks->einfo (_("%P: %B: warning: relocation against `%s' in readonly section `%A'\n"),
-				    p->sec->owner, h->root.root.string,
-				    p->sec);
-	  else
-	    /* xgettext:c-format */
-	    info->callbacks->minfo
-	      (_("%B: dynamic relocation against `%T' in read-only section `%A'\n"),
-	       p->sec->owner, h->root.root.string, p->sec);
+      if ((info->warn_shared_textrel && bfd_link_pic (info))
+	  || info->error_textrel)
+	/* xgettext:c-format */
+	info->callbacks->einfo (_("%P: %B: warning: relocation against `%s' "
+				  "in read-only section `%A'\n"),
+				sec->owner, h->root.root.string, sec);
 
-	  /* Not an error, just cut short the traversal.  */
-	  return FALSE;
-	}
+      /* Not an error, just cut short the traversal.  */
+      return FALSE;
     }
   return TRUE;
 }
@@ -937,8 +950,10 @@ _bfd_x86_elf_size_dynamic_sections (bfd *output_bfd,
 		      if ((info->warn_shared_textrel && bfd_link_pic (info))
 			  || info->error_textrel)
 			/* xgettext:c-format */
-			info->callbacks->einfo (_("%P: %B: warning: relocation in readonly section `%A'\n"),
-						p->sec->owner, p->sec);
+			info->callbacks->einfo
+			  (_("%P: %B: warning: relocation "
+			     "in read-only section `%A'\n"),
+			   p->sec->owner, p->sec);
 		    }
 		}
 	    }
@@ -1262,16 +1277,15 @@ _bfd_x86_elf_size_dynamic_sections (bfd *output_bfd,
 	  /* If any dynamic relocs apply to a read-only section,
 	     then we need a DT_TEXTREL entry.  */
 	  if ((info->flags & DF_TEXTREL) == 0)
-	    elf_link_hash_traverse (&htab->elf,
-				    _bfd_x86_elf_readonly_dynrelocs,
-				    info);
+	    elf_link_hash_traverse (&htab->elf, maybe_set_textrel, info);
 
 	  if ((info->flags & DF_TEXTREL) != 0)
 	    {
 	      if (htab->readonly_dynrelocs_against_ifunc)
 		{
 		  info->callbacks->einfo
-		    (_("%P%X: read-only segment has dynamic IFUNC relocations; recompile with -fPIC\n"));
+		    (_("%P%X: read-only segment has dynamic IFUNC relocations;"
+		       " recompile with -fPIC\n"));
 		  bfd_set_error (bfd_error_bad_value);
 		  return FALSE;
 		}
@@ -1824,17 +1838,10 @@ _bfd_x86_elf_adjust_dynamic_symbol (struct bfd_link_info *info,
 	  || (!eh->gotoff_ref
 	      && htab->target_os != is_vxworks)))
     {
-      for (p = eh->dyn_relocs; p != NULL; p = p->next)
-	{
-	  s = p->sec->output_section;
-	  if (s != NULL && (s->flags & SEC_READONLY) != 0)
-	    break;
-	}
-
-      /* If we didn't find any dynamic relocs in read-only sections,
+      /* If we don't find any dynamic relocs in read-only sections,
 	 then we'll be keeping the dynamic relocs and avoiding the copy
 	 reloc.  */
-      if (p == NULL)
+      if (!readonly_dynrelocs (h))
 	{
 	  h->non_got_ref = 0;
 	  return TRUE;
diff --git a/bfd/linker.c b/bfd/linker.c
index 9c19df4..77e2032 100644
--- a/bfd/linker.c
+++ b/bfd/linker.c
@@ -632,7 +632,7 @@ unwrap_hash_lookup (struct bfd_link_info *info,
 /* Traverse a generic link hash table.  Differs from bfd_hash_traverse
    in the treatment of warning symbols.  When warning symbols are
    created they replace the real symbol, so you don't get to see the
-   real symbol in a bfd_hash_travere.  This traversal calls func with
+   real symbol in a bfd_hash_traverse.  This traversal calls func with
    the real symbol.  */
 
 void
diff --git a/ld/ChangeLog b/ld/ChangeLog
index c970625..6b0e026 100644
--- a/ld/ChangeLog
+++ b/ld/ChangeLog
@@ -1,5 +1,12 @@
 2017-12-04  Alan Modra  <amodra@gmail.com>
 
+	* testsuite/ld-i386/pr17935-1.d: Adjust expected error.
+	* testsuite/ld-i386/pr17935-2.d: Likewise.
+	* testsuite/ld-x86-64/pr17935-1.d: Likewise.
+	* testsuite/ld-x86-64/pr17935-2.d: Likewise.
+
+2017-12-04  Alan Modra  <amodra@gmail.com>
+
 	* testsuite/ld-powerpc/powerpc.exp (ppceabitests): Add -a32 -mbig
 	to assembler options, and -melf32ppc to linker options.  Always
 	run these tests.
diff --git a/ld/testsuite/ld-i386/pr17935-1.d b/ld/testsuite/ld-i386/pr17935-1.d
index 5303ea2..e73da59 100644
--- a/ld/testsuite/ld-i386/pr17935-1.d
+++ b/ld/testsuite/ld-i386/pr17935-1.d
@@ -1,3 +1,3 @@
 # as: --32
 # ld: -m elf_i386 -shared -z text
-# error: warning: relocation against `foo' in readonly section `.text'
+# error: warning: relocation against `foo' in read-only section `.text'
diff --git a/ld/testsuite/ld-i386/pr17935-2.d b/ld/testsuite/ld-i386/pr17935-2.d
index c1080f4..2b1046e 100644
--- a/ld/testsuite/ld-i386/pr17935-2.d
+++ b/ld/testsuite/ld-i386/pr17935-2.d
@@ -1,3 +1,3 @@
 # as: --32
 # ld: -m elf_i386 -shared -z text
-# error: warning: relocation in readonly section `.text'
+# error: warning: relocation in read-only section `.text'
diff --git a/ld/testsuite/ld-x86-64/pr17935-1.d b/ld/testsuite/ld-x86-64/pr17935-1.d
index 5734eab..b3329bd 100644
--- a/ld/testsuite/ld-x86-64/pr17935-1.d
+++ b/ld/testsuite/ld-x86-64/pr17935-1.d
@@ -1,3 +1,3 @@
 # as: --64
 # ld: -m elf_x86_64 -shared -z text
-# error: warning: relocation against `foo' in readonly section `.text'
+# error: warning: relocation against `foo' in read-only section `.text'
diff --git a/ld/testsuite/ld-x86-64/pr17935-2.d b/ld/testsuite/ld-x86-64/pr17935-2.d
index 81df652..c15a79b 100644
--- a/ld/testsuite/ld-x86-64/pr17935-2.d
+++ b/ld/testsuite/ld-x86-64/pr17935-2.d
@@ -1,3 +1,3 @@
 # as: --64
 # ld: -m elf_x86_64 -shared -z text
-# error: warning: relocation in readonly section `.text'
+# error: warning: relocation in read-only section `.text'


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