https://bugs.llvm.org/show_bug.cgi?id=41972

            Bug ID: 41972
           Summary: -fsanitize-cfi-cross-dso causes .S functions to no
                    longer recognize their defined function prototype
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: -New Bugs
          Assignee: unassignedclangb...@nondot.org
          Reporter: keesc...@chromium.org
                CC: htmldevelo...@gmail.com, llvm-bugs@lists.llvm.org,
                    neeil...@live.com, richard-l...@metafoo.co.uk

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.)

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to