objcopy: Fix for pr19005 on machines for more than one octet per byte.

Message ID 20200216100022.14813-1-ceggers@gmx.de
State Superseded
Headers show
Series
  • objcopy: Fix for pr19005 on machines for more than one octet per byte.
Related show

Commit Message

Christian Eggers Feb. 16, 2020, 10 a.m.
On machines with more than one octet per byte, objcopy fills only a part
of the gap between sections.

	* objcopy.c (copy_object): Convert from bytes to octets for
	--gap-fill.

Signed-off-by: Christian Eggers <ceggers@gmx.de>

---
 binutils/objcopy.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

--
2.16.4

Comments

Alan Modra Feb. 19, 2020, 9:30 a.m. | #1
On Sun, Feb 16, 2020 at 11:00:22AM +0100, Christian Eggers wrote:
> On machines with more than one octet per byte, objcopy fills only a part

> of the gap between sections.

> 

> 	* objcopy.c (copy_object): Convert from bytes to octets for

> 	--gap-fill.


OK.  I think to --pad-to support needs a similar octets_per_byte fix.

-- 
Alan Modra
Australia Development Lab, IBM

Patch

diff --git a/binutils/objcopy.c b/binutils/objcopy.c
index fd94d63773e..f8ca0843937 100644
--- a/binutils/objcopy.c
+++ b/binutils/objcopy.c
@@ -3101,8 +3101,10 @@  copy_object (bfd *ibfd, bfd *obfd, const bfd_arch_info_type *input_arch)
 	  for (i = 0; i < c - 1; i++)
 	    {
 	      flagword flags;
-	      bfd_size_type size;
-	      bfd_vma gap_start, gap_stop;
+	      bfd_size_type size;           /* octets */
+	      bfd_vma gap_start, gap_stop;  /* octets */
+	      unsigned int opb1 = bfd_octets_per_byte (obfd, osections[i]);
+	      unsigned int opb2 = bfd_octets_per_byte (obfd, osections[i+1]);

 	      flags = bfd_section_flags (osections[i]);
 	      if ((flags & SEC_HAS_CONTENTS) == 0
@@ -3110,8 +3112,8 @@  copy_object (bfd *ibfd, bfd *obfd, const bfd_arch_info_type *input_arch)
 		continue;

 	      size = bfd_section_size (osections[i]);
-	      gap_start = bfd_section_lma (osections[i]) + size;
-	      gap_stop = bfd_section_lma (osections[i + 1]);
+	      gap_start = bfd_section_lma (osections[i]) * opb1 + size;
+	      gap_stop = bfd_section_lma (osections[i + 1]) * opb2;
 	      if (gap_start < gap_stop)
 		{
 		  if (!bfd_set_section_size (osections[i],