bug-binutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Bug binutils/21564] New: binary output should scale address by octets p


From: joe.zbiciak at leftturnonly dot info
Subject: [Bug binutils/21564] New: binary output should scale address by octets per byte
Date: Sat, 10 Jun 2017 23:24:35 +0000

https://sourceware.org/bugzilla/show_bug.cgi?id=21564

            Bug ID: 21564
           Summary: binary output should scale address by octets per byte
           Product: binutils
           Version: 2.28
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: binutils
          Assignee: unassigned at sourceware dot org
          Reporter: joe.zbiciak at leftturnonly dot info
  Target Milestone: ---

I'm porting binutils to an architecture which sets bits_per_byte to 16, and
therefore has octets_per_byte == 2.  When I used objcopy to copy my ELF file
out to a binary file, I found that the starting position of each section in the
resulting output file was incorrect.

For example, I had an ELF file with two sections, one at LMA 0x5000 - 0x5013,
and one at LMA 0x5014 - 0x5083.  When I used objcopy input.elf -O binary
output.bin, I found that the second section started at offset 0x14 in the file,
rather than 0x28 as expected.

I eventually traced it down to bfd/binary.c, and made the following tweak:

--- bfd/binary.c        (revision 3151)
+++ bfd/binary.c        (working copy)
@@ -252,7 +252,7 @@

       for (s = abfd->sections; s != NULL; s = s->next)
        {
-         s->filepos = s->lma - low;
+         s->filepos = (s->lma - low) * bfd_octets_per_byte(abfd);

          /* Skip following warning check for sections that will not
             occupy file space.  */

Since objcopy sets the architecture info correctly for the output BFD, the
bfd_octets_per_byte(abfd) will return the correct octets per byte for the
input.  Thus, the output binary's mapping of address to octets should match the
input.

With that tweak, my generated object is correct.

I do not have a test case I can easily share, as my binutils port is still a
work in progress.  However, if someone can suggest an architecture in the tree
that sets bits_per_byte to 16 or larger, I can perhaps generate a test based on
that platform if needed.

-- 
You are receiving this mail because:
You are on the CC list for the bug.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]