summaryrefslogtreecommitdiff
path: root/gcc/asan.c
diff options
context:
space:
mode:
authordvyukov <dvyukov@138bc75d-0d04-0410-961f-82ee72b054a4>2014-12-02 18:58:59 +0000
committerdvyukov <dvyukov@138bc75d-0d04-0410-961f-82ee72b054a4>2014-12-02 18:58:59 +0000
commitaa1dfc5fd51fd15e32173a7e499f5f1acaeb0a73 (patch)
treec75e433f807c9b3256cd6e445f2d957bc8afe1e1 /gcc/asan.c
parent269b76fe2eb5a3b5e8c49809edad7e42dc6ab4a8 (diff)
downloadgcc-aa1dfc5fd51fd15e32173a7e499f5f1acaeb0a73.tar.gz
asan: support for globals in kernel
2014-12-02 Dmitry Vyukov <dvyukov@google.com> * asan.c: (asan_finish_file): Use default priority for constructors in kernel mode. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@218281 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/asan.c')
-rw-r--r--gcc/asan.c17
1 files changed, 12 insertions, 5 deletions
diff --git a/gcc/asan.c b/gcc/asan.c
index a8987b78206..e33cdc8d0c9 100644
--- a/gcc/asan.c
+++ b/gcc/asan.c
@@ -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;
}