This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: [committed, PATCH] Properly convert objects between different ELF classes
- From: Andrew Stubbs <ams at codesourcery dot com>
- To: "H.J. Lu" <hjl dot tools at gmail dot com>, <binutils at sourceware dot org>
- Date: Thu, 24 Sep 2015 16:10:09 +0100
- Subject: Re: [committed, PATCH] Properly convert objects between different ELF classes
- Authentication-results: sourceware.org; auth=none
- References: <20150710214315 dot GA17734 at intel dot com>
On 10/07/15 22:43, H.J. Lu wrote:
- size = bfd_get_section_size (isection);
+ /* The output SHF_COMPRESSED section size is different from input if
+ ELF classes of input and output aren't the same. We must use the
+ output section size here, which has been updated in setup_section
+ via bfd_convert_section_size. */
+ size = bfd_get_section_size (osection);
This change has broken objcopy when padding has been added to the output
section size. In my case, the output is binary format.
The bug causes a buffer read overrun which results in intermittent
failures. It also looks like it will break byte reversal and interleaving.
The attached patch fixes the problem.
OK to commit?
Andrew
2015-09-24 Andrew Stubbs <ams@codesourcery.com>
binutils/
* objcopy.c (copy_section): Use input section size for the copy.
Index: binutils/objcopy.c
===================================================================
--- binutils/objcopy.c (revision 455071)
+++ binutils/objcopy.c (working copy)
@@ -3126,22 +3126,17 @@
bfd *obfd = (bfd *) obfdarg;
struct section_list *p;
sec_ptr osection;
- bfd_size_type size;
if (skip_section (ibfd, isection))
return;
osection = isection->output_section;
- /* The output SHF_COMPRESSED section size is different from input if
- ELF classes of input and output aren't the same. We must use the
- output section size here, which has been updated in setup_section
- via bfd_convert_section_size. */
- size = bfd_get_section_size (osection);
if (bfd_get_section_flags (ibfd, isection) & SEC_HAS_CONTENTS
&& bfd_get_section_flags (obfd, osection) & SEC_HAS_CONTENTS)
{
bfd_byte *memhunk = NULL;
+ bfd_size_type size;
if (!bfd_get_full_section_contents (ibfd, isection, &memhunk)
|| !bfd_convert_section_contents (ibfd, isection, obfd,
@@ -3152,6 +3147,9 @@
return;
}
+ /* Use the input size *after* conversion. */
+ size = bfd_get_section_size (isection);
+
if (reverse_bytes)
{
/* We don't handle leftover bytes (too many possible behaviors,
@@ -3210,6 +3208,7 @@
FALSE, SECTION_CONTEXT_SET_FLAGS)) != NULL
&& (p->flags & SEC_HAS_CONTENTS) != 0)
{
+ bfd_size_type size = bfd_get_section_size (osection);
void *memhunk = xmalloc (size);
/* We don't permit the user to turn off the SEC_HAS_CONTENTS