public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: Alan Modra <amodra@gmail.com>
To: Richard Henderson <rth@redhat.com>
Cc: binutils@sourceware.org
Subject: Alpha DT_RELA
Date: Mon, 20 Feb 2017 10:31:00 -0000	[thread overview]
Message-ID: <20170220103127.GZ3731@bubble.grove.modra.org> (raw)

Hi Richard,
Most modern targets supported by binutils do not emit DT_RELA when
DT_RELASZ is zero, ie. you have .rela.plt relocs but no .rela.dyn
relocs.  This brings Alpha into line with the rest.  The ELF spec is
arguable regarding this practice so you might not see this as a
desirable change (but see PR21181).  OK?

diff --git a/bfd/ChangeLog b/bfd/ChangeLog
index 3e90624..b58ed37 100644
--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -1,3 +1,8 @@
+2017-02-17  Alan Modra  <amodra@gmail.com>
+
+	* elf64-alpha.c (elf64_alpha_size_dynamic_sections): Only emit
+	DT_RELA, DT_RELASZ, and DT_RELAENT when DT_RELASZ is non-zero.
+
 2017-02-20  Alan Modra  <amodra@gmail.com>
 
 	PR 21181
diff --git a/bfd/elf64-alpha.c b/bfd/elf64-alpha.c
index b4a50f4..43c6ed8 100644
--- a/bfd/elf64-alpha.c
+++ b/bfd/elf64-alpha.c
@@ -2879,7 +2879,7 @@ elf64_alpha_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
 {
   bfd *dynobj;
   asection *s;
-  bfd_boolean relplt;
+  bfd_boolean relplt, relocs;
   struct alpha_elf_link_hash_table * htab;
 
   htab = alpha_elf_hash_table (info);
@@ -2916,6 +2916,7 @@ elf64_alpha_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
      determined the sizes of the various dynamic sections.  Allocate
      memory for them.  */
   relplt = FALSE;
+  relocs = FALSE;
   for (s = dynobj->sections; s != NULL; s = s->next)
     {
       const char *name;
@@ -2933,6 +2934,8 @@ elf64_alpha_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
 	    {
 	      if (strcmp (name, ".rela.plt") == 0)
 		relplt = TRUE;
+	      else
+		relocs = TRUE;
 
 	      /* We use the reloc_count field as a counter if we need
 		 to copy relocs into the output file.  */
@@ -2997,15 +3000,18 @@ elf64_alpha_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
 	    return FALSE;
 	}
 
-      if (!add_dynamic_entry (DT_RELA, 0)
-	  || !add_dynamic_entry (DT_RELASZ, 0)
-	  || !add_dynamic_entry (DT_RELAENT, sizeof (Elf64_External_Rela)))
-	return FALSE;
-
-      if (info->flags & DF_TEXTREL)
+      if (relocs)
 	{
-	  if (!add_dynamic_entry (DT_TEXTREL, 0))
+	  if (!add_dynamic_entry (DT_RELA, 0)
+	      || !add_dynamic_entry (DT_RELASZ, 0)
+	      || !add_dynamic_entry (DT_RELAENT, sizeof (Elf64_External_Rela)))
 	    return FALSE;
+
+	  if (info->flags & DF_TEXTREL)
+	    {
+	      if (!add_dynamic_entry (DT_TEXTREL, 0))
+		return FALSE;
+	    }
 	}
     }
 #undef add_dynamic_entry

-- 
Alan Modra
Australia Development Lab, IBM

             reply	other threads:[~2017-02-20 10:31 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-02-20 10:31 Alan Modra [this message]
2017-02-20 20:19 ` Richard Henderson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170220103127.GZ3731@bubble.grove.modra.org \
    --to=amodra@gmail.com \
    --cc=binutils@sourceware.org \
    --cc=rth@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).