<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 - [AArch64] Cross-DSO CFI doesn't work with ShadowCallStack and mcount instrumentation"
   href="https://bugs.llvm.org/show_bug.cgi?id=44094">44094</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>[AArch64] Cross-DSO CFI doesn't work with ShadowCallStack and mcount instrumentation
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>new-bugs
          </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>peter@pcc.me.uk
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>samitolvanen@google.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>htmldeveloper@gmail.com, llvm-bugs@lists.llvm.org, ndesaulniers@google.com
          </td>
        </tr></table>
      <p>
        <div>
        <pre>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 (<a href="https://github.com/llvm/llvm-project.git">https://github.com/llvm/llvm-project.git</a>
73429126c91c2065c6f6ef29b3eec1b7798502bb)

$ ld.lld --version
LLD 10.0.0 (<a href="https://github.com/llvm/llvm-project.git">https://github.com/llvm/llvm-project.git</a>
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.</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>