public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Allow inlining always_inline functions into no_sanitize_address ones with -fsanitize=address
@ 2019-01-31  0:11 Jakub Jelinek
  2019-01-31  8:59 ` Richard Biener
  0 siblings, 1 reply; 2+ messages in thread
From: Jakub Jelinek @ 2019-01-31  0:11 UTC (permalink / raw)
  To: Richard Biener, Yuri Gribov; +Cc: gcc-patches

Hi!

As mentioned in the PR, we refuse to inline with -fsanitize=address
no_sanitize_address functions into functions without that attribute,
which is good and has been requested in PR59600.
We also refuse to inline functions without that attribute into
no_sanitize_address functions, which is ok if it is optimization matter
only, we will just address sanitize the callee and not the caller.
But if such callee has always_inline attribute, this causes errors, and
e.g. means one can't use target intrinsics in functions with
no_sanitize_address attribute, as we refuse to inline any of those.

The following patch allows inlining always_inline functions in that
situation, the end result is that both the caller and callee which becomes
one function will not be sanitized (still errors if always_inline,
no_sanitize_address is being inlined into normal function, that is just user
error).

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

2019-01-30  Jakub Jelinek  <jakub@redhat.com>

	PR sanitizer/89124
	* ipa-inline.c (sanitize_attrs_match_for_inline_p): Allow inlining
	always_inline callees into no_sanitize_address callers.

	* c-c++-common/asan/pr89124.c: New test.

--- gcc/ipa-inline.c.jj	2019-01-10 11:43:08.956466913 +0100
+++ gcc/ipa-inline.c	2019-01-30 22:21:57.319026848 +0100
@@ -264,6 +264,12 @@ sanitize_attrs_match_for_inline_p (const
   if (!caller || !callee)
     return true;
 
+  /* Allow inlining always_inline functions into no_sanitize_address
+     functions.  */
+  if (!sanitize_flags_p (SANITIZE_ADDRESS, caller)
+      && lookup_attribute ("always_inline", DECL_ATTRIBUTES (callee)))
+    return true;
+
   return ((sanitize_flags_p (SANITIZE_ADDRESS, caller)
 	   == sanitize_flags_p (SANITIZE_ADDRESS, callee))
 	  && (sanitize_flags_p (SANITIZE_POINTER_COMPARE, caller)
--- gcc/testsuite/c-c++-common/asan/pr89124.c.jj	2019-01-30 22:23:27.018546142 +0100
+++ gcc/testsuite/c-c++-common/asan/pr89124.c	2019-01-30 22:23:05.568900221 +0100
@@ -0,0 +1,14 @@
+/* PR sanitizer/89124 */
+/* { dg-do compile } */
+
+static int inline __attribute__ ((always_inline))
+foo (int x)
+{
+  return x + 1;
+}
+
+__attribute__ ((no_sanitize_address)) int
+bar (int x)
+{
+  return foo (x);
+}

	Jakub

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] Allow inlining always_inline functions into no_sanitize_address ones with -fsanitize=address
  2019-01-31  0:11 [PATCH] Allow inlining always_inline functions into no_sanitize_address ones with -fsanitize=address Jakub Jelinek
@ 2019-01-31  8:59 ` Richard Biener
  0 siblings, 0 replies; 2+ messages in thread
From: Richard Biener @ 2019-01-31  8:59 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: Yuri Gribov, gcc-patches

On Thu, 31 Jan 2019, Jakub Jelinek wrote:

> Hi!
> 
> As mentioned in the PR, we refuse to inline with -fsanitize=address
> no_sanitize_address functions into functions without that attribute,
> which is good and has been requested in PR59600.
> We also refuse to inline functions without that attribute into
> no_sanitize_address functions, which is ok if it is optimization matter
> only, we will just address sanitize the callee and not the caller.
> But if such callee has always_inline attribute, this causes errors, and
> e.g. means one can't use target intrinsics in functions with
> no_sanitize_address attribute, as we refuse to inline any of those.
> 
> The following patch allows inlining always_inline functions in that
> situation, the end result is that both the caller and callee which becomes
> one function will not be sanitized (still errors if always_inline,
> no_sanitize_address is being inlined into normal function, that is just user
> error).
> 
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

OK.

Richard.

> 2019-01-30  Jakub Jelinek  <jakub@redhat.com>
> 
> 	PR sanitizer/89124
> 	* ipa-inline.c (sanitize_attrs_match_for_inline_p): Allow inlining
> 	always_inline callees into no_sanitize_address callers.
> 
> 	* c-c++-common/asan/pr89124.c: New test.
> 
> --- gcc/ipa-inline.c.jj	2019-01-10 11:43:08.956466913 +0100
> +++ gcc/ipa-inline.c	2019-01-30 22:21:57.319026848 +0100
> @@ -264,6 +264,12 @@ sanitize_attrs_match_for_inline_p (const
>    if (!caller || !callee)
>      return true;
>  
> +  /* Allow inlining always_inline functions into no_sanitize_address
> +     functions.  */
> +  if (!sanitize_flags_p (SANITIZE_ADDRESS, caller)
> +      && lookup_attribute ("always_inline", DECL_ATTRIBUTES (callee)))
> +    return true;
> +
>    return ((sanitize_flags_p (SANITIZE_ADDRESS, caller)
>  	   == sanitize_flags_p (SANITIZE_ADDRESS, callee))
>  	  && (sanitize_flags_p (SANITIZE_POINTER_COMPARE, caller)
> --- gcc/testsuite/c-c++-common/asan/pr89124.c.jj	2019-01-30 22:23:27.018546142 +0100
> +++ gcc/testsuite/c-c++-common/asan/pr89124.c	2019-01-30 22:23:05.568900221 +0100
> @@ -0,0 +1,14 @@
> +/* PR sanitizer/89124 */
> +/* { dg-do compile } */
> +
> +static int inline __attribute__ ((always_inline))
> +foo (int x)
> +{
> +  return x + 1;
> +}
> +
> +__attribute__ ((no_sanitize_address)) int
> +bar (int x)
> +{
> +  return foo (x);
> +}
> 
> 	Jakub
> 
> 

-- 
Richard Biener <rguenther@suse.de>
SUSE LINUX GmbH, GF: Felix Imendoerffer, Jane Smithard, Graham Norton, HRB 21284 (AG Nuernberg)

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-01-31  8:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-01-31  0:11 [PATCH] Allow inlining always_inline functions into no_sanitize_address ones with -fsanitize=address Jakub Jelinek
2019-01-31  8:59 ` Richard Biener

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).