sanitizer: do not inline no-sanitize into sanitizer fn
gcc/ChangeLog: * cif-code.def (ATTRIBUTE_MISMATCH): Rename to... (SANITIZE_ATTRIBUTE_MISMATCH): ...this. * ipa-inline.c (sanitize_attrs_match_for_inline_p): Handle all sanitizer options. (can_inline_edge_p): Use renamed CIF_* enum value. gcc/testsuite/ChangeLog: * c-c++-common/asan/inline.c: New test. * c-c++-common/asan/inline-kernel.c: New test. * c-c++-common/tsan/inline.c: New test. * c-c++-common/ubsan/inline.c: New test.
This commit is contained in:
parent
bb3ab62a8b
commit
4089df8ef4
6 changed files with 103 additions and 14 deletions
|
@ -128,9 +128,10 @@ DEFCIFCODE(OPTIMIZATION_MISMATCH, CIF_FINAL_ERROR,
|
||||||
DEFCIFCODE(USES_COMDAT_LOCAL, CIF_FINAL_ERROR,
|
DEFCIFCODE(USES_COMDAT_LOCAL, CIF_FINAL_ERROR,
|
||||||
N_("callee refers to comdat-local symbols"))
|
N_("callee refers to comdat-local symbols"))
|
||||||
|
|
||||||
/* We can't inline because of mismatched caller/callee attributes. */
|
/* We can't inline because of mismatched caller/callee
|
||||||
DEFCIFCODE(ATTRIBUTE_MISMATCH, CIF_FINAL_ERROR,
|
sanitizer attributes. */
|
||||||
N_("function attribute mismatch"))
|
DEFCIFCODE(SANITIZE_ATTRIBUTE_MISMATCH, CIF_FINAL_ERROR,
|
||||||
|
N_("sanitizer function attribute mismatch"))
|
||||||
|
|
||||||
/* We can't inline because the user requests only static functions
|
/* We can't inline because the user requests only static functions
|
||||||
but the function has external linkage for live patching purpose. */
|
but the function has external linkage for live patching purpose. */
|
||||||
|
|
|
@ -264,18 +264,26 @@ sanitize_attrs_match_for_inline_p (const_tree caller, const_tree callee)
|
||||||
if (!caller || !callee)
|
if (!caller || !callee)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
/* Allow inlining always_inline functions into no_sanitize_address
|
/* Follow clang and allow inlining for always_inline functions. */
|
||||||
functions. */
|
if (lookup_attribute ("always_inline", DECL_ATTRIBUTES (callee)))
|
||||||
if (!sanitize_flags_p (SANITIZE_ADDRESS, caller)
|
|
||||||
&& lookup_attribute ("always_inline", DECL_ATTRIBUTES (callee)))
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
return ((sanitize_flags_p (SANITIZE_ADDRESS, caller)
|
const sanitize_code codes[] =
|
||||||
== sanitize_flags_p (SANITIZE_ADDRESS, callee))
|
{
|
||||||
&& (sanitize_flags_p (SANITIZE_POINTER_COMPARE, caller)
|
SANITIZE_ADDRESS,
|
||||||
== sanitize_flags_p (SANITIZE_POINTER_COMPARE, callee))
|
SANITIZE_THREAD,
|
||||||
&& (sanitize_flags_p (SANITIZE_POINTER_SUBTRACT, caller)
|
SANITIZE_UNDEFINED,
|
||||||
== sanitize_flags_p (SANITIZE_POINTER_SUBTRACT, callee)));
|
SANITIZE_UNDEFINED_NONDEFAULT,
|
||||||
|
SANITIZE_POINTER_COMPARE,
|
||||||
|
SANITIZE_POINTER_SUBTRACT
|
||||||
|
};
|
||||||
|
|
||||||
|
for (unsigned i = 0; i < sizeof (codes) / sizeof (codes[0]); i++)
|
||||||
|
if (sanitize_flags_p (codes[i], caller)
|
||||||
|
!= sanitize_flags_p (codes[i], callee))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Used for flags where it is safe to inline when caller's value is
|
/* Used for flags where it is safe to inline when caller's value is
|
||||||
|
@ -382,7 +390,7 @@ can_inline_edge_p (struct cgraph_edge *e, bool report,
|
||||||
/* Don't inline a function with mismatched sanitization attributes. */
|
/* Don't inline a function with mismatched sanitization attributes. */
|
||||||
else if (!sanitize_attrs_match_for_inline_p (caller->decl, callee->decl))
|
else if (!sanitize_attrs_match_for_inline_p (caller->decl, callee->decl))
|
||||||
{
|
{
|
||||||
e->inline_failed = CIF_ATTRIBUTE_MISMATCH;
|
e->inline_failed = CIF_SANITIZE_ATTRIBUTE_MISMATCH;
|
||||||
inlinable = false;
|
inlinable = false;
|
||||||
}
|
}
|
||||||
if (!inlinable && report)
|
if (!inlinable && report)
|
||||||
|
|
20
gcc/testsuite/c-c++-common/asan/inline-kernel.c
Normal file
20
gcc/testsuite/c-c++-common/asan/inline-kernel.c
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
/* { dg-do compile } */
|
||||||
|
/* { dg-options "-fsanitize=kernel-address -c -O3 -fdump-tree-optimized" } */
|
||||||
|
|
||||||
|
int x;
|
||||||
|
|
||||||
|
static inline
|
||||||
|
__attribute__((no_sanitize("kernel-address")))
|
||||||
|
void do_not_sanitize(void)
|
||||||
|
{
|
||||||
|
x++;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
sanitize_this(void)
|
||||||
|
{
|
||||||
|
x++;
|
||||||
|
do_not_sanitize();
|
||||||
|
}
|
||||||
|
|
||||||
|
/* { dg-final { scan-tree-dump-times "Function do_not_sanitize" 1 "optimized" } } */
|
20
gcc/testsuite/c-c++-common/asan/inline.c
Normal file
20
gcc/testsuite/c-c++-common/asan/inline.c
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
/* { dg-do compile } */
|
||||||
|
/* { dg-options "-fsanitize=address -c -O3 -fdump-tree-optimized" } */
|
||||||
|
|
||||||
|
int x;
|
||||||
|
|
||||||
|
static inline
|
||||||
|
__attribute__((no_sanitize("address")))
|
||||||
|
void do_not_sanitize(void)
|
||||||
|
{
|
||||||
|
x++;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
sanitize_this(void)
|
||||||
|
{
|
||||||
|
x++;
|
||||||
|
do_not_sanitize();
|
||||||
|
}
|
||||||
|
|
||||||
|
/* { dg-final { scan-tree-dump-times "Function do_not_sanitize" 1 "optimized" } } */
|
20
gcc/testsuite/c-c++-common/tsan/inline.c
Normal file
20
gcc/testsuite/c-c++-common/tsan/inline.c
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
/* { dg-do compile } */
|
||||||
|
/* { dg-options "-fsanitize=thread -c -O3 -fdump-tree-optimized" } */
|
||||||
|
|
||||||
|
int x;
|
||||||
|
|
||||||
|
static inline
|
||||||
|
__attribute__((no_sanitize("thread")))
|
||||||
|
void do_not_sanitize(void)
|
||||||
|
{
|
||||||
|
x++;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
sanitize_this(void)
|
||||||
|
{
|
||||||
|
x++;
|
||||||
|
do_not_sanitize();
|
||||||
|
}
|
||||||
|
|
||||||
|
/* { dg-final { scan-tree-dump-times "Function do_not_sanitize" 1 "optimized" } } */
|
20
gcc/testsuite/c-c++-common/ubsan/inline.c
Normal file
20
gcc/testsuite/c-c++-common/ubsan/inline.c
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
/* { dg-do compile } */
|
||||||
|
/* { dg-options "-fsanitize=vla-bound -c -O3 -fdump-tree-optimized" } */
|
||||||
|
|
||||||
|
int x;
|
||||||
|
|
||||||
|
static inline
|
||||||
|
__attribute__((no_sanitize("undefined")))
|
||||||
|
void do_not_sanitize(void)
|
||||||
|
{
|
||||||
|
x++;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
sanitize_this(void)
|
||||||
|
{
|
||||||
|
x++;
|
||||||
|
do_not_sanitize();
|
||||||
|
}
|
||||||
|
|
||||||
|
/* { dg-final { scan-tree-dump-times "Function do_not_sanitize" 1 "optimized" } } */
|
Loading…
Add table
Reference in a new issue