This is the mail archive of the
mailing list for the binutils project.
Re: deleting relocs, objcopy and BFD
- From: Nick Clifton <nickc at redhat dot com>
- To: "Jose E. Marchesi" <jose dot marchesi at oracle dot com>, binutils at sourceware dot org
- Date: Tue, 2 May 2017 15:50:20 +0100
- Subject: Re: deleting relocs, objcopy and BFD
- Authentication-results: sourceware.org; auth=none
- Authentication-results: ext-mx04.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com
- Authentication-results: ext-mx04.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=nickc at redhat dot com
- Dkim-filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 2DF9EDF3CE
- Dmarc-filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 2DF9EDF3CE
- References: <email@example.com>
> 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.
diff --git a/binutils/objcopy.c b/binutils/objcopy.c
index 42c7775..36952ec 100644
@@ -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;