public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: "Jose E. Marchesi" <jose.marchesi@oracle.com>
To: binutils@sourceware.org
Subject: [PATCH V2 2/3] bfd: fix the deletion of relocs in sparc64
Date: Fri, 05 May 2017 12:10:00 -0000	[thread overview]
Message-ID: <1493986217-9037-3-git-send-email-jose.marchesi@oracle.com> (raw)
In-Reply-To: <1493986217-9037-1-git-send-email-jose.marchesi@oracle.com>

This patch fixes the deletion of relocations in BFD sections in
sparc64 targets.

A specialized `_bfd_set_reloc' function is provided that updates the
internal canon_reloc_count(sec) counter instead of sec->reloc_count.
Additionally, the `write_relocs' callback in elf64-sparc is adapted to
use the canon_reloc_count to traverse `sec->orelocation'.

Tested in sparc64-linux-gnu targets.
Fixes an existing failure in the merge-notes objcopy test.
No regressions.

bfd/ChangeLog:

2017-05-05  Jose E. Marchesi  <jose.marchesi@oracle.com>

	* elf64-sparc.c (elf64_sparc_set_reloc): New function.
	(bfd_elf64_set_reloc): Define.
	(elf64_sparc_write_relocs): Use `canon_reloc_count'.
---
 bfd/ChangeLog     |  6 ++++++
 bfd/elf64-sparc.c | 24 +++++++++++++++++++-----
 2 files changed, 25 insertions(+), 5 deletions(-)

diff --git a/bfd/ChangeLog b/bfd/ChangeLog
index 9002dfa..d8ec8a7 100644
--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -1,5 +1,11 @@
 2017-05-05  Jose E. Marchesi  <jose.marchesi@oracle.com>
 
+	* elf64-sparc.c (elf64_sparc_set_reloc): New function.
+	(bfd_elf64_set_reloc): Define.
+	(elf64_sparc_write_relocs): Use `canon_reloc_count'.
+
+2017-05-05  Jose E. Marchesi  <jose.marchesi@oracle.com>
+
 	* targets.c (BFD_JUMP_TABLE_RELOCS): Add NAME##_set_reloc.
 	(struct bfd_target): New field _bfd_set_reloc.
 	* bfd.c (bfd_set_reloc): Call backend _set_bfd.
diff --git a/bfd/elf64-sparc.c b/bfd/elf64-sparc.c
index 9456b59..3e0772d 100644
--- a/bfd/elf64-sparc.c
+++ b/bfd/elf64-sparc.c
@@ -278,6 +278,18 @@ elf64_sparc_canonicalize_dynamic_reloc (bfd *abfd, arelent **storage,
   return ret;
 }
 
+/* Install a new set of internal relocs.  */
+
+static void
+elf64_sparc_set_reloc (bfd *abfd ATTRIBUTE_UNUSED,
+                       asection *asect,
+                       arelent **location,
+                       unsigned int count)
+{
+  asect->orelocation = location;
+  canon_reloc_count (asect) = count;
+}
+
 /* Write out the relocs.  */
 
 static void
@@ -302,14 +314,14 @@ elf64_sparc_write_relocs (bfd *abfd, asection *sec, void * data)
      reloc_count field to zero to inhibit writing them here.  Also,
      sometimes the SEC_RELOC flag gets set even when there aren't any
      relocs.  */
-  if (sec->reloc_count == 0)
+  if (canon_reloc_count (sec) == 0)
     return;
 
   /* We can combine two relocs that refer to the same address
      into R_SPARC_OLO10 if first one is R_SPARC_LO10 and the
      latter is R_SPARC_13 with no associated symbol.  */
   count = 0;
-  for (idx = 0; idx < sec->reloc_count; idx++)
+  for (idx = 0; idx < canon_reloc_count (sec); idx++)
     {
       bfd_vma addr;
 
@@ -317,7 +329,7 @@ elf64_sparc_write_relocs (bfd *abfd, asection *sec, void * data)
 
       addr = sec->orelocation[idx]->address;
       if (sec->orelocation[idx]->howto->type == R_SPARC_LO10
-	  && idx < sec->reloc_count - 1)
+	  && idx < canon_reloc_count (sec) - 1)
 	{
 	  arelent *r = sec->orelocation[idx + 1];
 
@@ -354,7 +366,7 @@ elf64_sparc_write_relocs (bfd *abfd, asection *sec, void * data)
   outbound_relocas = (Elf64_External_Rela *) rela_hdr->contents;
   src_rela = outbound_relocas;
 
-  for (idx = 0; idx < sec->reloc_count; idx++)
+  for (idx = 0; idx < canon_reloc_count (sec); idx++)
     {
       Elf_Internal_Rela dst_rela;
       arelent *ptr;
@@ -388,7 +400,7 @@ elf64_sparc_write_relocs (bfd *abfd, asection *sec, void * data)
 	}
 
       if (ptr->howto->type == R_SPARC_LO10
-	  && idx < sec->reloc_count - 1)
+	  && idx < canon_reloc_count (sec) - 1)
 	{
 	  arelent *r = sec->orelocation[idx + 1];
 
@@ -854,6 +866,8 @@ const struct elf_size_info elf64_sparc_size_info =
   elf64_sparc_canonicalize_reloc
 #define bfd_elf64_canonicalize_dynamic_reloc \
   elf64_sparc_canonicalize_dynamic_reloc
+#define bfd_elf64_set_reloc \
+  elf64_sparc_set_reloc
 #define elf_backend_add_symbol_hook \
   elf64_sparc_add_symbol_hook
 #define elf_backend_get_symbol_type \
-- 
2.3.4

  parent reply	other threads:[~2017-05-05 12:10 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-05 12:10 [PATCH V2 0/3] Fix relocation deletion problems in SPARC and MIPS Jose E. Marchesi
2017-05-05 12:10 ` [PATCH V2 1/3] bfd: new BFD target entry point _bfd_set_reloc Jose E. Marchesi
2017-05-07  2:53   ` Alan Modra
2017-05-10 16:49     ` Jose E. Marchesi
2017-05-05 12:10 ` [PATCH V2 3/3] bfd: fix the deletion of relocs in mips64 Jose E. Marchesi
2017-05-17 15:29   ` Maciej W. Rozycki
2017-05-17 16:14     ` Jose E. Marchesi
2017-05-19 14:14       ` [PATCH] MIPS/BFD: For n64 hold the number of internal relocs in `->reloc_count' Maciej W. Rozycki
2017-05-19 15:01         ` Jose E. Marchesi
2017-05-19 15:47           ` Maciej W. Rozycki
2017-05-20  9:56         ` Maciej W. Rozycki
2017-05-22  9:21           ` Jose E. Marchesi
2017-05-22 17:51           ` Joseph Myers
2017-05-22 20:48             ` Maciej W. Rozycki
2017-05-05 12:10 ` Jose E. Marchesi [this message]
2017-05-10 16:51   ` [PATCH V2 2/3] bfd: fix the deletion of relocs in sparc64 Jose E. Marchesi

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=1493986217-9037-3-git-send-email-jose.marchesi@oracle.com \
    --to=jose.marchesi@oracle.com \
    --cc=binutils@sourceware.org \
    /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).