public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: Nick Clifton <nickc@redhat.com>
To: "Jose E. Marchesi" <jose.marchesi@oracle.com>, binutils@sourceware.org
Subject: Re: deleting relocs, objcopy and BFD
Date: Tue, 02 May 2017 14:50:00 -0000	[thread overview]
Message-ID: <303e32fb-9b29-7959-24e1-056d8042be35@redhat.com> (raw)
In-Reply-To: <878tmluaag.fsf@oracle.com>

[-- Attachment #1: Type: text/plain, Size: 1059 bytes --]

Hi Guys,

> Problem 1: incoherence with internal relocs and external relocs breaks> the API.
I am checking in the attached patch in order to stop objcopy from attempting
to merge notes when the internal reloc count is greater than the external 
reloc count.  This does not fix the underlying problem, but it should at
least make objcopy safe, for now.

> b) To remove the API limitation/bug in BFD, somehow.  Maybe adding
>     end-of-list sentinels to `sec->relocation' and `sec->orelocation',
>     adjusting `bfd_set_reloc' to install it according to its `relcount'
>     argument, leaving `sec->reloc_count' untouched, and also making
>     `elfNN_BE_write_relocs' to use the sentinel when writing.

I think that option b) would be better.  I wonder though whether it might
be simpler to just let targets override the bfd_set_reloc () function with
their own implementation, should they have special requirements.  I have not
investigated this yet, but it seems like it would be the simplest solution,
provided that it can be made to work.

Cheers
  Nick

[-- Attachment #2: objcopy.reloc-count.patch --]
[-- Type: text/x-patch, Size: 697 bytes --]

diff --git a/binutils/objcopy.c b/binutils/objcopy.c
index 42c7775..36952ec 100644
--- a/binutils/objcopy.c
+++ b/binutils/objcopy.c
@@ -2137,6 +2137,13 @@ merge_gnu_build_notes (bfd * abfd, asection * sec, bfd_size_type size, bfd_byte
 	    relcount = 0;
 	}
 
+      /* A few targets (eg MIPS, SPARC) create multiple internal relocs to
+	 represent a single external reloc.  Unfortunately the current BFD
+	 API does not handle deleting relocs in such situations very well
+	 and so it is unsafe to proceed.  */
+      if (relcount > sec->reloc_count)
+	goto done;
+
       /* Eliminate the duplicates.  */
       new = new_contents = xmalloc (size);
       for (pnote = pnotes, old = contents;

  parent reply	other threads:[~2017-05-02 14:50 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-27 15:43 Jose E. Marchesi
2017-05-01  4:45 ` Alan Modra
2017-05-01 11:20   ` Jose E. Marchesi
2017-05-02 11:11   ` Nick Clifton
2017-05-02 10:16 ` Maciej W. Rozycki
2017-05-02 14:50 ` Nick Clifton [this message]
2017-05-02 16:47   ` Jose E. Marchesi
2017-05-02 19:20   ` H.J. Lu

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=303e32fb-9b29-7959-24e1-056d8042be35@redhat.com \
    --to=nickc@redhat.com \
    --cc=binutils@sourceware.org \
    --cc=jose.marchesi@oracle.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).