This is the mail archive of the 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]

Re: deleting relocs, objcopy and BFD

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.

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;

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