<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 - --stack-first should be the default WASM memory layout"
   href="https://bugs.llvm.org/show_bug.cgi?id=44297">44297</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>--stack-first should be the default WASM memory layout
          </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>All
          </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>wasm
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>bholley@mozilla.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org, sbc@chromium.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>At present, lldb defaults to locating global variables first in linear memory,
followed by the stack. This improves code-size by reducing the size of
instructions which load globals via constant offset, since smaller constants
can be represented with fewer bits. However, it also means that stack overflows
will clobber those globals before wrapping past address zero and faulting.

lld offers the --stack-first option, which rustc adopted [1] after struggling
with inexplicable memory corruption caused by stack overflows. I think this
should probably be the default, so that clang inherits the same behavior. Given
that stack overflows in native code generally fault rather than triggering
memory corruption, C/C++ developers tend not to work very hard to ensure they
never happen.

[1]
<a href="https://github.com/rust-lang/rust/blob/d825e35ee8325146e6c175a4c61bcb645b347d5e/src/librustc_target/spec/wasm32_base.rs#L25">https://github.com/rust-lang/rust/blob/d825e35ee8325146e6c175a4c61bcb645b347d5e/src/librustc_target/spec/wasm32_base.rs#L25</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>