[compiler-rt] c6e83dd - [Sanitizers][CFG][arm64e] Fix test because -fsanitize-coverage=control-flow does not sign BB entry

Blue Gaston via llvm-commits llvm-commits at lists.llvm.org
Mon Dec 12 20:33:22 PST 2022


Author: Blue Gaston
Date: 2022-12-12T20:32:30-08:00
New Revision: c6e83ddb37aff90b3fff2deb8605bc0adc54b393

URL: https://github.com/llvm/llvm-project/commit/c6e83ddb37aff90b3fff2deb8605bc0adc54b393
DIFF: https://github.com/llvm/llvm-project/commit/c6e83ddb37aff90b3fff2deb8605bc0adc54b393.diff

LOG: [Sanitizers][CFG][arm64e] Fix test because -fsanitize-coverage=control-flow does not sign BB entry

-fsanitize-coverage=control-flow does not sign entries into basic blocks on arm64e. This test compares a local pointer to a function [signed] with the basic block pointer. Because the entry into the
basic block is unsigned the addresses being compared are signed and unsigned, causing the path never to be taken.
This is a "bandaid" to get this test passing. We strip the signed bits from the pointer to the local functions so that the comparisons pass.
Filed radar: rdar://103042879 to note the behavior.

context: https://github.com/llvm/llvm-project/blob/main/llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp#L1068
    // blockaddress can not be used on function's entry block.
    if (&BB == &F.getEntryBlock())
      CFs.push_back((Constant *)IRB.CreatePointerCast(&F, IntptrPtrTy));
    else
      CFs.push_back((Constant *)IRB.CreatePointerCast(BlockAddress::get(&BB),
                                                      IntptrPtrTy));
BlockAddress::get is responsible for signing the pointer.

Because of:
https://reviews.llvm.org/D133157

rdar://103042879

Differential Revision: https://reviews.llvm.org/D139661

Added: 
    

Modified: 
    compiler-rt/test/sanitizer_common/TestCases/sanitizer_coverage_control_flow.cpp

Removed: 
    


################################################################################
diff  --git a/compiler-rt/test/sanitizer_common/TestCases/sanitizer_coverage_control_flow.cpp b/compiler-rt/test/sanitizer_common/TestCases/sanitizer_coverage_control_flow.cpp
index 4e85395731179..5223af07f18ae 100644
--- a/compiler-rt/test/sanitizer_common/TestCases/sanitizer_coverage_control_flow.cpp
+++ b/compiler-rt/test/sanitizer_common/TestCases/sanitizer_coverage_control_flow.cpp
@@ -8,6 +8,11 @@
 
 #include <cstdint>
 #include <cstdio>
+#if __has_feature(ptrauth_calls)
+  #include <ptrauth.h>
+#else
+  #define ptrauth_strip(__value, __key) (__value)
+#endif
 
 uintptr_t *CFS_BEG, *CFS_END;
 
@@ -52,8 +57,8 @@ void check_cfs_section(uintptr_t main_ptr, uintptr_t foo_ptr) {
 }
 
 int main() {
-  auto main_ptr = &main;
-  auto foo_ptr = &foo;
+  auto main_ptr = ptrauth_strip(&main, ptrauth_key_function_pointer);
+  auto foo_ptr = ptrauth_strip(&foo, ptrauth_key_function_pointer);
   int x = 10;
 
   if (x > 0)


        


More information about the llvm-commits mailing list