<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - Wrong generation of PT_LOAD program headers"
   href="https://bugs.llvm.org/show_bug.cgi?id=50558">50558</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Wrong generation of PT_LOAD program headers
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>lld
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>unspecified
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>enhancement
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>ELF
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>konstantin.schwarz@hightec-rt.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org, smithp352@googlemail.com
          </td>
        </tr></table>
      <p>
        <div>
        <pre>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.</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>