bug-binutils
[Top][All Lists]
Advanced

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

[Bug binutils/25662] New: objcopy sets invalid sh_offset for the first s


From: jozef.l at mittosystems dot com
Subject: [Bug binutils/25662] New: objcopy sets invalid sh_offset for the first section in a no_contents segment containing program headers
Date: Thu, 12 Mar 2020 14:24:13 +0000

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

            Bug ID: 25662
           Summary: objcopy sets invalid sh_offset for the first section
                    in a no_contents segment containing program headers
           Product: binutils
           Version: 2.34
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: binutils
          Assignee: unassigned at sourceware dot org
          Reporter: jozef.l at mittosystems dot com
  Target Milestone: ---

The Binutils "simple objcopy of executable" test is failing for
msp430-elf/-mlarge since

  commit 30fe183248b2523ecff9da36853e2f893c4c4b91
  Author: Alan Modra <address@hidden>
  Date:   Wed Oct 23 17:40:51 2019 +1030

      PR4499, assign file positions assumes segment offsets increasing

This is similar to PR23595, where the fact that the first segment contains the
program headers and a section of type SHT_NOBITS causes problems.

This time, the difference between the original executable file, and the output
from copying that file using objcopy is the sh_offset of the .bss section,
which
is the only section in the first segment, and also contains the program
headers.

Original executable:
  Section Headers:
    [Nr] Name  Type     Addr     Off    Size   ES Flg Lk Inf Al
    [ 5] .data PROGBITS 00000500 0001b0 00013e 00  WA  0   0  2
    [ 7] .bss  NOBITS   0000063e 000116 000028 00  WA  0   0  2
  ...
  Program Headers:
    Type   Offset   VirtAddr   PhysAddr   FileSiz MemSiz  Flg Align
    LOAD   0x000000 0x00000528 0x00000528 0x00114 0x0013e RW  0x4
  ...
   Section to Segment mapping:
    Segment Sections...
     00     .bss

Objcopy output executable:
  Section Headers:
    [Nr] Name  Type     Addr     Off    Size   ES Flg Lk Inf Al
    [ 5] .data PROGBITS 00000500 0001b0 00013e 00  WA  0   0  2
    [ 7] .bss  NOBITS   0000063e 000114 000028 00  WA  0   0  2

Note 0x116 sh_offset in the original, and 0x114 sh_offset in the objcopy
output.

The problem is that copy_elf_program_header calculates a p_vaddr_offset of -2
for the segment, since .bss is offset 2 bytes from the end of the program
headers in that segment, due to the required alignment of the segment.

So p_vaddr is temporarily being calculated as 0x63c, which means in
assign_file_positions_for_load_sections segment aligment is not required
since (0x63c + 0x114) % 4 == 0.

Hence the .bss sh_offset is output incorrectly - (0x63e + 0x114) % 4 = 2.
Since .bss is the first loadable section in the segment, it must be aligned to
the segment align of 4 rather than the section alignment of 2, right?

-- 
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]