<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 - -fsplit-stack problems with split -> nosplit call"
   href="https://bugs.llvm.org/show_bug.cgi?id=37807">37807</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>-fsplit-stack problems with split -> nosplit call
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>libraries
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </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>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>Backend: X86
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>thanm@google.com
          </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=20429" name="attach_20429" title="tar file containing files to reproduce">attachment 20429</a> <a href="attachment.cgi?id=20429&action=edit" title="tar file containing files to reproduce">[details]</a></span>
tar file containing files to reproduce

Filing this bug on behalf of Cherry Zhang, who gets credit for discovering it.

This is a problem with -fsplit-stack support in LLVM, specifically in how calls
from split-stack code to non-split-stack code are handled. Let's say you have
sources a.c (containing function foo) and b.c (containing function bar), where

  - a.c is compiled with -fsplit-stack, and
  - b.c is compiled without -fsplit-stack, and
  - foo calls bar
  - a.o and b.o and linked together into the same load module

What is supposed to happen in this instance (as described in
<a href="https://gcc.gnu.org/wiki/SplitStacks">https://gcc.gnu.org/wiki/SplitStacks</a>) is that the linker picks up on the fact
that there is a "split to nonsplit" call from foo to bar, and during linking,
it fixes up the "check for more stack" sequence in foo to bump up the amount of
space (since 'bar' may use a lot of space).

What we're seeing with LLVM is that if "foo" has no stack frame at all, the
morestack check is omitted from the routine. This results in a linker assert
when linking a.o and b.o together. 

I'm attaching a reproducer; unpack the tar file and do "make run" (uses clang
from $PATH):

$ make clean ; make run 
rm -f *.o *.so main asm.txt
clang -c -O -fPIC -o main.o main.c
clang -c -fsplit-stack -O -fPIC -o m1.o m1.c
clang -c -O -fPIC -o m2.o m2.c
clang -O -fuse-ld=gold -fPIC -shared m1.o m2.o -o m1.so
/usr/bin/ld.gold: error: m1.o: failed to match split-stack sequence at section
2 offset 0
clang-7: error: linker command failed with exit code 1 (use -v to see
invocation)
makefile:19: recipe for target 'm1.so' failed
make: *** [m1.so] Error 1

Note that the linker error will not be triggered for older versions of clang
(prior to fix for <a class="bz_bug_link 
          bz_status_RESOLVED  bz_closed"
   title="RESOLVED FIXED - -fsplit-stack omits .note.GNU-split-stack section marker"
   href="show_bug.cgi?id=34670">https://bugs.llvm.org/show_bug.cgi?id=34670</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>