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

    <tr>
        <th>Summary</th>
        <td>
            split-stack does not emit code for calls between split-stack and non-split-stack code
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

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

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

<pre>
    LLVM provides a command-line option (`-fsplit-stack`) to [emit hooks](https://llvm.org/docs/SegmentedStacks.html) for [the segmented stack mechanism provided by libgcc](https://gcc.gnu.org/wiki/SplitStacks), but its implementation is incomplete.

Currently, LLVM inserts a check on the stack pointer into the prologue of any function marked `split-stack` during `PrologEpilogInserter` ([here](https://github.com/llvm/llvm-project/blob/llvmorg-14.0.0-rc1/llvm/lib/CodeGen/PrologEpilogInserter.cpp#L1157) on 14.0.0-1). It should, but does not, also check for calls from functions marked `split-stack` to those not marked, and emit calls to `__morestack_non_split` (called `__morestack_nosplit` in the libgcc docs) at those call sites.

Why this is a problem: as currently implemented, functions within split-stack modules that are marked `no_split_stack` use a split stack, and just don't check the pointer! This is a recipe for segfaults, particularly if the non-split functions have a large frame size. I was able to cause such a segfault on clang 14.0.0-1/x86_64-pc-linux-gnu by writing a split-stack function which creates an ~31K array on the stack (to use up most but not all of the initial stacklet) and then calls a non-split-stack function which creates an 8K array on the stack. The segfault does not occur if the inner function is not marked `no_split_stack`.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyVVdmu2zgM_RrnRYhhO_uDH9rbdlDMHWCADqaPgSwxthpZMrTcNP36krKzFSkGAxheJIo8PDykGyvP9evrv3-xwdk3JcEzzoTte27kXCsDzA5BWcOyaputi_nBD1qFuQ9cHPE7q3YsWJat3kOvAuusPfps9QGNuxAGny3eZdUnvLR-63PrWnyVVnh8fIG2BxNAfiFXPu9Cr8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