<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 - Symbol assignments within output sections are not relative to enclosing section"
   href="https://bugs.llvm.org/show_bug.cgi?id=41169">41169</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Symbol assignments within output sections are not relative to enclosing section
          </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>pkmx.tw@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org, peter.smith@linaro.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>To reproduce:

$ cat > test.ld <<EOF
SECTIONS {
  .foo 0x10000 : {
    . = 4;
    foo = .;
  }
}
EOF

$ clang -xc - -o empty.o < /dev/null
$ ld.lld empty.o -Ttest.ld
ld.lld: error: test.ld:3: unable to move location counter backward for: .foo
ld.lld: error: section .foo at 0x10000 of size 0xFFFFFFFFFFFF0004 exceeds
available address space

It works with ld.bfd:

$ ld.bfd empty.o -Ttest.ld
$ readelf -s a.out | grep foo
     4: 0000000000010004     0 NOTYPE  GLOBAL DEFAULT    1 foo

---------------------------------

ld.bfd treats numbers in an output section as relative to the beginning of the
section
(<a href="https://sourceware.org/binutils/docs/ld/Expression-Section.html#Expression-Section">https://sourceware.org/binutils/docs/ld/Expression-Section.html#Expression-Section</a>),
so the assignment `. = 4` actually moves dot to 0x10004.

In lld, `. = 4` tries to move dot backwards to absolute address 4, which is not
allowed within an output section.</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>