]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
do not tailcall __sanitizer_cov_trace_pc [PR90746]
authorAlexander Monakov <amonakov@ispras.ru>
Thu, 19 Jan 2023 16:25:04 +0000 (19:25 +0300)
committerAlexander Monakov <amonakov@ispras.ru>
Wed, 3 May 2023 16:51:32 +0000 (19:51 +0300)
When instrumentation is requested via -fsanitize-coverage=trace-pc, GCC
emits calls of __sanitizer_cov_trace_pc callback in each basic block.
This callback is supposed to be implemented by the user, and should be
able to identify the containing basic block by inspecting its return
address. Tailcalling the callback prevents that, so disallow it.

gcc/ChangeLog:

PR sanitizer/90746
* calls.cc (can_implement_as_sibling_call_p): Reject calls
to __sanitizer_cov_trace_pc.

gcc/testsuite/ChangeLog:

PR sanitizer/90746
* gcc.dg/sancov/basic0.c: Verify absence of tailcall.

gcc/calls.cc
gcc/testsuite/gcc.dg/sancov/basic0.c

index 4d7f6c3d2912c9dcb150d8d219dce07d99ada0a6..1c9abccef6813a84d0a3ba3189dba5277f3651aa 100644 (file)
@@ -2541,6 +2541,16 @@ can_implement_as_sibling_call_p (tree exp,
       return false;
     }
 
+  /* __sanitizer_cov_trace_pc is supposed to inspect its return address
+     to identify the caller, and therefore should not be tailcalled.  */
+  if (fndecl && DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_NORMAL
+      && DECL_FUNCTION_CODE (fndecl) == BUILT_IN_SANITIZER_COV_TRACE_PC)
+    {
+      /* No need for maybe_complain_about_tail_call here:
+        the call is synthesized by the compiler.  */
+      return false;
+    }
+
   /* If the called function is nested in the current one, it might access
      some of the caller's arguments, but could clobber them beforehand if
      the argument areas are shared.  */
index af69b2d12ed264578e3de35f2d7ac9a6b7fa9abd..dfdaea848020fc3921928eff5f7d784f6c070ab7 100644 (file)
@@ -1,9 +1,11 @@
 /* Basic test on number of inserted callbacks.  */
 /* { dg-do compile } */
-/* { dg-options "-fsanitize-coverage=trace-pc -fdump-tree-optimized" } */
+/* { dg-options "-fsanitize-coverage=trace-pc -fdump-tree-optimized -fdump-rtl-expand" } */
 
 void foo(void)
 {
 }
 
 /* { dg-final { scan-tree-dump-times "__builtin___sanitizer_cov_trace_pc \\(\\)" 1 "optimized" } } */
+/* The built-in should not be tail-called: */
+/* { dg-final { scan-rtl-dump-not "call_insn/j" "expand" } } */