<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 - LLD wasm: alignment assert + a segfault"
   href="https://bugs.llvm.org/show_bug.cgi?id=35369">35369</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>LLD wasm: alignment assert + a segfault
          </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>Windows NT
          </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>All Bugs
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>alex@crichton.co
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=19448" name="attach_19448" title="test object file that fails">attachment 19448</a> <a href="attachment.cgi?id=19448&action=edit" title="test object file that fails">[details]</a></span>
test object file that fails

I've experimented trying to integrate LLD into Rust's support for WebAssembly
but unfortunately the "hello world" was generating a few asserts and segfaults
in LLD. For reduction I've extracted just one object file on the linker line
which reproduces the issue.

If I execute:

    $ wasm-ld test.o -o test --allow-undefined

it'll fail with:

    wasm-ld: /home/alex/code/llvm/include/llvm/Support/MathExtras.h:678:
uint64_t llvm::alignTo(uint64_t, uint64_t, uint64_t): Assertion `Align != 0u &&
"Align can't be 0."' failed.

I tried tracing in gdb and it looks like this is a case where the data section
has an alignment of 0 (unsure why). I then attempted to apply a small patch [1]
but then lld segfaulted right afterwards. Then I gave up and decided to open a
bug!

To be clear the object file here doesn't actually do anything useful. This was
part of a much larger link line and this is just one object file reduced. If
it's helpful I can provide all the various inputs as well!

[1]: <a href="https://gist.github.com/alexcrichton/8f5ddc7778586011eabe58aa2e11baeb">https://gist.github.com/alexcrichton/8f5ddc7778586011eabe58aa2e11baeb</a></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>