<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/62243>62243</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            wasm-ld crash when LTO enabled: `__cxx_global_var_init.1` present in "init functions" but not defined
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            lld,
            backend:WebAssembly
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          sbc100
      </td>
    </tr>
</table>

<pre>
    We've seen certain situations where in LTO builds wasm-ld will crash during `Writer::createCallCtorsFunction` because one of the init function in the generted LTO object file (` __cxx_global_var_init.1`) in undefined and does not get assigned a function index (so crashes in `sym->getFunctionIndex()`).

I'm still working on reducing the repro case as more.

This seems to have started with https://reviews.llvm.org/D135427, which I guess makes sense since that change explicitly calls out `__cxx_global_var_init` as being discarded.  

</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJx0k09v6zYQxD8NdVnEoFaybB10cJMaCFCglwfkaPDPWmJDkQaXipJvX1D2axug7yIJIjHD-e1QMbsxEA1i_5vYv1RqyVNMA2tTS1npaL-GNxJ4-CBgogCGUlYuALu8qOxiYFgnSgQuwB8__gS9OG8ZVsXzk7ewOu_BJMUT2CW5MILo5FtymZJoTqI5mUQq07Py_jnHxOclmKIqOgmajFqYIAaCeIU8FROX4frYUyzLz5ECpUx284_6LzIZrs4TCDwWncvFfH5eRh-18pcPlS5FZVeLTgrsi8gSLF1dIAsqWLCRGELMMFKGBx4L6r-2lj6LOMd7NOKiIjrJX_OTaH4fKf_M8Vr2lnNgf_fbCfki5On-fBV4mIFzgbTG9F74xACJ7GLKd0mX6JYiGMUEimGOib5J_Jgcl8nMDDnCpMqcstpwrC5PMOV844IazwLPiT4crbzz_mPexTQKPL_Uzb7Fg8BnWCdnJniFcSFmmNU7FenABOyCIciTymAmFUYC-rx5Z1z2X2CU9wxxyQXB_8IuU1AMmkoo69ioZMnuAO4ZKjs0tm96VdFQd8e6x6Y-ttU0dLQ_tu0B287Itsa-7g_Hjg666VAerxIrN6DERrZ1X3f7RrY7rWtl6dCYrj9c93spWkmzcv6fxJVjXmjoENum8kqT5636iN5bgSjwWSBqZd4pWNGc3kifmGnW_qus7l-qNBStJ72MLFrpHed_eVbZZU_Dz_bfi79OdL8bFJT2VFR_SWqrJdwSMYW8tQrxW-lZIIJe8tbQR22rJfnh-6BHl6dF70ycBZ7L6R6vp1uK5YIIPG8gWOB5Y_F3AAAA___lsVV0">