This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Fix -fsanitize=undefined with PCH, part #2 (PR sanitizer/66343)


Hi!

When writing test for this PR, I've noticed ICE if the header is compiled
without -fsanitize=undefined, but source is compiled with it.

We had various issues like this in the past, and we handle it by calling
initialize_sanitizer_builtins, which does nothing if the sanitizer bultins
are already created, but after loading PCH (which can kill them) can fix stuff
up again.  I found various spots where the call has been missing in the
ubsan instrumentation, but common feature of all those spots is first
calling ubsan_create_data and only then using builtin_decl_explicit
for the ubsan builtins.  So, this patch puts the initialization call into
that routine, which fixes all uses, and removes the two calls that are now
unnecessary because of that.

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

2016-10-05  Jakub Jelinek  <jakub@redhat.com>

	PR sanitizer/66343
	* ubsan.c (ubsan_create_data): Call initialize_sanitizer_builtins here.
	(ubsan_instrument_float_cast): And not here.

	* c-ubsan.c (ubsan_instrument_return): Don't call
	initialize_sanitizer_builtins here.

	* gcc.dg/pch/pr66343-3.c: New test.
	* gcc.dg/pch/pr66343-3.hs: New file.

--- gcc/ubsan.c.jj	2016-10-05 11:59:04.000000000 +0200
+++ gcc/ubsan.c	2016-10-05 12:52:32.099353026 +0200
@@ -511,6 +511,10 @@ ubsan_create_data (const char *name, int
   size_t i = 0;
   int j;
 
+  /* It is possible that PCH zapped table with definitions of sanitizer
+     builtins.  Reinitialize them if needed.  */
+  initialize_sanitizer_builtins ();
+
   /* Firstly, create a pointer to type descriptor type.  */
   tree td_type = ubsan_get_type_descriptor_type ();
   td_type = build_pointer_type (td_type);
@@ -1589,7 +1593,6 @@ ubsan_instrument_float_cast (location_t
     {
       location_t *loc_ptr = NULL;
       unsigned num_locations = 0;
-      initialize_sanitizer_builtins ();
       /* Figure out if we can propagate location to ubsan_data and use new
          style handlers in libubsan.  */
       if (ubsan_use_new_style_p (loc))
--- gcc/c-family/c-ubsan.c.jj	2016-10-03 16:21:26.000000000 +0200
+++ gcc/c-family/c-ubsan.c	2016-10-05 12:52:54.623066115 +0200
@@ -233,9 +233,6 @@ ubsan_instrument_return (location_t loc)
 {
   if (flag_sanitize_undefined_trap_on_error)
     return build_call_expr_loc (loc, builtin_decl_explicit (BUILT_IN_TRAP), 0);
-  /* It is possible that PCH zapped table with definitions of sanitizer
-     builtins.  Reinitialize them if needed.  */
-  initialize_sanitizer_builtins ();
 
   tree data = ubsan_create_data ("__ubsan_missing_return_data", 1, &loc,
 				 NULL_TREE, NULL_TREE);
--- gcc/testsuite/gcc.dg/pch/pr66343-3.c.jj	2016-10-05 12:58:35.885719045 +0200
+++ gcc/testsuite/gcc.dg/pch/pr66343-3.c	2016-10-05 12:57:17.600716255 +0200
@@ -0,0 +1,15 @@
+/* PR sanitizer/66343 */
+/* { dg-do assemble } */
+/* { dg-options "-fsanitize=undefined" } */
+
+#include "pr66343-3.h"
+
+void
+bar (int a, int b)
+{
+  a / b;
+}
+
+/* Hack to turn off PCH assembly comparison, as it is incompatible
+   with dg-do assemble.  The target condition will be always false.  */
+/* { dg-error "" "" { target { lp64 && { ! lp64 } } } } */
--- gcc/testsuite/gcc.dg/pch/pr66343-3.hs.jj	2016-10-05 12:45:24.654797897 +0200
+++ gcc/testsuite/gcc.dg/pch/pr66343-3.hs	2016-10-05 12:56:10.017577142 +0200
@@ -0,0 +1,4 @@
+/* PR sanitizer/66343 */
+/* { dg-options "-fno-sanitize=undefined" } */
+
+/* Empty.  */

	Jakub


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]