[llvm-bugs] [Bug 50558] New: Wrong generation of PT_LOAD program headers

via llvm-bugs llvm-bugs at lists.llvm.org
Wed Jun 2 02:50:06 PDT 2021


https://bugs.llvm.org/show_bug.cgi?id=50558

            Bug ID: 50558
           Summary: Wrong generation of PT_LOAD program headers
           Product: lld
           Version: unspecified
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: ELF
          Assignee: unassignedbugs at nondot.org
          Reporter: konstantin.schwarz at hightec-rt.com
                CC: llvm-bugs at lists.llvm.org, smithp352 at googlemail.com

For the following simplified test case, ld.lld produces a
"section .data3 load address range overlaps with .data4" error.

Assembly file:
```
.section .a.data, "aw"
.word 0xabcdef01

.section .b.data, "aw"
.word 0xbcdefa12

.text
.globl _start
_start:
    nop
```

Linkerscript:
```
MEMORY
{
    CODE (rx)  : ORIGIN = 0x08000000, LENGTH = 512K
    DATA (rw) : ORIGIN = 0x20000400, LENGTH = 512K
}
SECTIONS
{
    .text :
    {
        *(.text)
    } > CODE

    .data :
    {
        *(.a.data)
    } > DATA AT> CODE

    .data2 (NOLOAD) :
    {
        . += 4;
    } > DATA

    .data3 :
    {
        *(.b.data)
    } > DATA AT> CODE

    .data4 :
    {
        LONG(-1); LONG(-1); LONG(-1);
    } > CODE
}
```

The problem seems to be the way PT_LOAD headers are created in createPhdrs in
this case.
.data starts a new PT_LOAD segment, then .data2 is skipped (because of NOLOAD),
then .data3 continues the previous PT_LOAD.

However, .data2 occupies memory in the DATA memory region, thus .data3 may not
continue the previous PT_LOAD segment.

In this simplified linkerscript, the order of the output sections could be
changed to make the link succeed, however in the actual application there are
several linkerscript fragments that are included into the main script. In this
scenario, the outer context is not known and re-ordering doesn't work.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20210602/8a42c2dc/attachment.html>


More information about the llvm-bugs mailing list