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

            Bug ID: 33720
           Summary: ld.bfd unexpectedly places segment overlapping another
           Product: binutils
           Version: 2.45.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: ld
          Assignee: unassigned at sourceware dot org
          Reporter: slipher at protonmail dot com
  Target Milestone: ---

Created attachment 16520
  --> https://sourceware.org/bugzilla/attachment.cgi?id=16520&action=edit
archive with object file and linker script

We have a bug in ld.bfd that occurs when creating an executable from a single
object file (attached) with a custom linker script (attached). The executable
cannot run because two segments are unexpectedly overlapping, clobbering the
program code. The command line is `ld.bfd --script nacl_bootstrap.x
nacl_bootstrap.c.o -m elf_x86_64 --build-id`.

Expected behavior: the "r_debug" segment (as named in the linker script) is
loaded into memory starting at 0x14000, the value of "." when it is specified.
Actual behavior: the "r_debug" segment starts at memory address 0x10158 and
overwrites the text section with zeroes when it is loaded, as shown below.

Program Header:
    LOAD off    0x0000000000000000 vaddr 0x0000000000010000 paddr
0x0000000000010000 align 2**12
         filesz 0x0000000000001298 memsz 0x0000000000001298 flags r-x
    LOAD off    0x0000000000000000 vaddr 0x0000000000012000 paddr
0x0000000000012000 align 2**12
         filesz 0x0000000000000000 memsz 0x0000000000001008 flags rw-
    LOAD off    0x0000000000002158 vaddr 0x0000000000010158 paddr
0x0000000000010158 align 2**12
         filesz 0x0000000000003ed0 memsz 0x0000000000003ed0 flags rw-
    NOTE off    0x0000000000000188 vaddr 0x0000000000010188 paddr
0x0000000000010188 align 2**2
         filesz 0x0000000000000024 memsz 0x0000000000000024 flags r--
   STACK off    0x0000000000000000 vaddr 0x0000000000000000 paddr
0x0000000000000000 align 2**3
         filesz 0x0000000000000000 memsz 0x0000000000000000 flags rw-

The bug is present in binutils 2.45.1 provided by Arch Linux. It can also be
observed at least as far back as binutils 2.34 from Ubuntu 20.04.

Note 1: The bug is triggered by the presence of the .note.gnu.property section
in the input (as compared to systems where it works correctly).
Note 2: If :text is explicitly specified for the .rodata output section in the
linker script, the script works as expected. This is strange since :text was
specified for the previous section so it shouldn't make any difference.

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

Reply via email to