This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: deleting relocs, objcopy and BFD
- From: "H.J. Lu" <hjl dot tools at gmail dot com>
- To: Nick Clifton <nickc at redhat dot com>
- Cc: "Jose E. Marchesi" <jose dot marchesi at oracle dot com>, Binutils <binutils at sourceware dot org>
- Date: Tue, 2 May 2017 12:20:03 -0700
- Subject: Re: deleting relocs, objcopy and BFD
- Authentication-results: sourceware.org; auth=none
- References: <878tmluaag.fsf@oracle.com> <303e32fb-9b29-7959-24e1-056d8042be35@redhat.com>
On Tue, May 2, 2017 at 7:50 AM, Nick Clifton <nickc@redhat.com> wrote:
> 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.
>
I checked in this to fix build on 32-bit hosts.
--
H.J.
From 2ecf0cc317d065cfeb960c61688897351521bce0 Mon Sep 17 00:00:00 2001
From: "H.J. Lu" <hjl.tools@gmail.com>
Date: Tue, 2 May 2017 12:16:26 -0700
Subject: [PATCH] Cast relcount to unsigned long when comparing with
sec->reloc_count
The type of relcount is long and the type of sec->reloc_count is
unsigned int. On 32-bit hosts, GCC issues an error:
objcopy.c:2144:20: error: comparison between signed and unsigned integer expressions [-Werror=sign-compare]
if (relcount > sec->reloc_count)
Cast relcount to unsigned long to silence GCC.
* objcopy.c (merge_gnu_build_notes): Cast relcount to unsigned
long when comparing with sec->reloc_count.
---
binutils/ChangeLog | 5 +++++
binutils/objcopy.c | 2 +-
2 files changed, 6 insertions(+), 1 deletion(-)
diff --git a/binutils/ChangeLog b/binutils/ChangeLog
index d13dbb6..b3a539a 100644
--- a/binutils/ChangeLog
+++ b/binutils/ChangeLog
@@ -1,3 +1,8 @@
+2017-05-02 H.J. Lu <hongjiu.lu@intel.com>
+
+ * objcopy.c (merge_gnu_build_notes): Cast relcount to unsigned
+ long when comparing with sec->reloc_count.
+
2017-05-02 Nick Clifton <nickc@redhat.com>
* objcopy.c (merge_gnu_build_notes): Disable merge if there are
diff --git a/binutils/objcopy.c b/binutils/objcopy.c
index 36952ec..ccb5e12 100644
--- a/binutils/objcopy.c
+++ b/binutils/objcopy.c
@@ -2141,7 +2141,7 @@ merge_gnu_build_notes (bfd * abfd, asection * sec, bfd_size_type size, bfd_byte
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)
+ if ((unsigned long) relcount > sec->reloc_count)
goto done;
/* Eliminate the duplicates. */
--
2.9.3