asan: support for globals in kernel
authorDmitry Vyukov <dvyukov@google.com>
Tue, 2 Dec 2014 18:58:59 +0000 (10:58 -0800)
committerDmitry Vyukov <dvyukov@gcc.gnu.org>
Tue, 2 Dec 2014 18:58:59 +0000 (10:58 -0800)
2014-12-02  Dmitry Vyukov  <dvyukov@google.com>
* asan.c: (asan_finish_file): Use default priority for constructors
in kernel mode.

From-SVN: r218281

gcc/ChangeLog
gcc/asan.c

index d85bb4eb5b5c94fb9f4c3225cdd16aebf0b64f78..b2eb9506485881ce35f3bf36f7f8ff85e45dbc36 100644 (file)
@@ -1,3 +1,8 @@
+2014-12-02  Dmitry Vyukov  <dvyukov@google.com>
+
+       * asan.c: (asan_finish_file): Use default priority for constructors
+       in kernel mode.
+
 2014-12-02  Ulrich Weigand  <Ulrich.Weigand@de.ibm.com>
 
        PR target/64115
index a8987b78206f859d13be3d8accd8a267649a2af0..e33cdc8d0c997bcc791161b3142e0b47b6250f2c 100644 (file)
@@ -1348,7 +1348,9 @@ asan_protect_global (tree decl)
         the var that is selected by the linker will have
         padding or not.  */
       || DECL_ONE_ONLY (decl)
-      /* Similarly for common vars.  People can use -fno-common.  */
+      /* Similarly for common vars.  People can use -fno-common.
+        Note: Linux kernel is built with -fno-common, so we do instrument
+        globals there even if it is C.  */
       || (DECL_COMMON (decl) && TREE_PUBLIC (decl))
       /* Don't protect if using user section, often vars placed
         into user section from multiple TUs are then assumed
@@ -2448,6 +2450,13 @@ asan_finish_file (void)
      nor after .LASAN* array.  */
   flag_sanitize &= ~SANITIZE_ADDRESS;
 
+  /* For user-space we want asan constructors to run first.
+     Linux kernel does not support priorities other than default, and the only
+     other user of constructors is coverage. So we run with the default
+     priority.  */
+  int priority = flag_sanitize & SANITIZE_USER_ADDRESS
+                 ? MAX_RESERVED_INIT_PRIORITY - 1 : DEFAULT_INIT_PRIORITY;
+
   if (flag_sanitize & SANITIZE_USER_ADDRESS)
     {
       tree fn = builtin_decl_implicit (BUILT_IN_ASAN_INIT);
@@ -2503,12 +2512,10 @@ asan_finish_file (void)
                                                 build_fold_addr_expr (var),
                                                 gcount_tree),
                                &dtor_statements);
-      cgraph_build_static_cdtor ('D', dtor_statements,
-                                MAX_RESERVED_INIT_PRIORITY - 1);
+      cgraph_build_static_cdtor ('D', dtor_statements, priority);
     }
   if (asan_ctor_statements)
-    cgraph_build_static_cdtor ('I', asan_ctor_statements,
-                              MAX_RESERVED_INIT_PRIORITY - 1);
+    cgraph_build_static_cdtor ('I', asan_ctor_statements, priority);
   flag_sanitize |= SANITIZE_ADDRESS;
 }