<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 - -fsanitize-cfi-cross-dso causes .S functions to no longer recognize their defined function prototype"
   href="https://bugs.llvm.org/show_bug.cgi?id=41972">41972</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>-fsanitize-cfi-cross-dso causes .S functions to no longer recognize their defined function prototype
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </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>-New Bugs
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>keescook@chromium.org
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>htmldeveloper@gmail.com, llvm-bugs@lists.llvm.org, neeilans@live.com, richard-llvm@metafoo.co.uk
          </td>
        </tr></table>
      <p>
        <div>
        <pre>When building and linking .S files into a project (like, say, the Linux
kernel), having their function prototypes declared in headers works fine with
just "-fsanitize=cfi".

For example with return.S:

.globl do_nothing_asm
.align 4,0x90
do_nothing_asm:
 nop
 ret
.type do_nothing_asm, @function
.size do_nothing_asm, .-do_nothing_asm

and main.c:

#include <stdio.h>

extern void do_nothing_asm(void);

void do_nothing_C(void)
{
        return;
}

int main(void)
{
        void (*func)(void);

        printf("C ...\n");
        func = do_nothing_C;
        func();

        printf("asm ...\n");
        func = do_nothing_asm;
        func();

        return 0;
}

$ clang  -flto -fvisibility=hidden -fsanitize=cfi  -c -o main.o main.c
$ clang  -flto -fvisibility=hidden -fsanitize=cfi  -c -o return.o return.S
$ clang -flto -fvisibility=hidden -fsanitize=cfi -fuse-ld=lld -o test main.o
return.o
$ ./test
C ...
asm ...
$

But enabling cross-dso, this breaks:

$ clang  -flto -fvisibility=hidden -fsanitize=cfi -fsanitize-cfi-cross-dso  -c
-o main.o main.c
$ clang  -flto -fvisibility=hidden -fsanitize=cfi -fsanitize-cfi-cross-dso  -c
-o return.o return.S
$ clang -flto -fvisibility=hidden -fsanitize=cfi -fsanitize-cfi-cross-dso
-fuse-ld=lld -o test main.o return.o
$ ./test
C ...
asm ...
Illegal instruction (core dumped)
$

This is a rather bad problem for the Linux kernel, as implementing functions in
.S is rather common, and especially so for indirect function calls to them in
things like the crypto subsystem. We need some way to either fix this in the
cross-DSO CFI or to mark these. (The kernel already marks .S functions with its
own "asmlinkage" macro, which could gain, for example, a CFI-specific attribute
if needed.)</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>