[llvm-bugs] [Bug 44094] New: [AArch64] Cross-DSO CFI doesn't work with ShadowCallStack and mcount instrumentation

via llvm-bugs llvm-bugs at lists.llvm.org
Wed Nov 20 14:50:16 PST 2019


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

            Bug ID: 44094
           Summary: [AArch64] Cross-DSO CFI doesn't work with
                    ShadowCallStack and mcount instrumentation
           Product: new-bugs
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: new bugs
          Assignee: peter at pcc.me.uk
          Reporter: samitolvanen at google.com
                CC: htmldeveloper at gmail.com, llvm-bugs at lists.llvm.org,
                    ndesaulniers at google.com

Compiling any C file with cross-DSO CFI, ShadowCallStack, and mcount
instrumentation all enabled, and linking it into native code with LLD results
in "LLVM ERROR: Must reserve x18 to use shadow call stack", even though the
code was compiled with -ffixed-x18.

$ clang --version | grep version
clang version 10.0.0 (https://github.com/llvm/llvm-project.git
73429126c91c2065c6f6ef29b3eec1b7798502bb)

$ ld.lld --version
LLD 10.0.0 (https://github.com/llvm/llvm-project.git
73429126c91c2065c6f6ef29b3eec1b7798502bb) (compatible with GNU linkers)

$ cat build.sh 
#!/bin/bash
cat /dev/null > main.c
clang \
        -target aarch64-linux-gnu \
        -flto=thin \
        -fsanitize=cfi \
        -fvisibility=default \
        -fsanitize-cfi-cross-dso \
        -fsanitize=shadow-call-stack \
        -ffixed-x18 \
        -pg \
        -c main.c \
        -o main.o
ld.lld -r -o all.o main.o

$ ./build.sh 
LLVM ERROR: Must reserve x18 to use shadow call stack

Looking at the IR code in main.o, the interesting part is the __cfi_check_fail
function generated by the compiler:

define weak_odr hidden void @__cfi_check_fail(i8* %0, i8* %1) #0 {
  %3 = alloca i8*, align 8
  %4 = alloca i8*, align 8
  store i8* %0, i8** %3, align 8, !nosanitize !7
  store i8* %1, i8** %4, align 8, !nosanitize !7
  %5 = load i8*, i8** %3, align 8, !nosanitize !7
  %6 = load i8*, i8** %4, align 8, !nosanitize !7
  %7 = icmp ne i8* %5, null, !nosanitize !7
  br i1 %7, label %9, label %8, !nosanitize !7

...
attributes #0 = { shadowcallstack
"instrument-function-entry-inlined"="\01_mcount" "min-legal-vector-width"="0"
"no-jump-tables"="false" }

The function is generated with the shadowcallstack attribute, but it doesn't
have a target-features attribute with +reserve-x18.

The test case links again if I remove any of -fsanitize-cfi-cross-dso, -pg, or
fsanitize=shadow-call-stack from the compiler flags.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20191120/4f637f20/attachment-0001.html>


More information about the llvm-bugs mailing list