public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH][PR sanitizer/78887] Don't emit ODR indicators if -fsanitize=kernel-address is present.
       [not found] <CGME20170113081926eucas1p2182a7b44313074dab4efc7d75d2362e2@eucas1p2.samsung.com>
@ 2017-01-13  8:19 ` Maxim Ostapenko
  2017-01-13  8:24   ` Jakub Jelinek
  0 siblings, 1 reply; 4+ messages in thread
From: Maxim Ostapenko @ 2017-01-13  8:19 UTC (permalink / raw)
  To: GCC Patches

[-- Attachment #1: Type: text/plain, Size: 401 bytes --]

Hi,

as mentioned in PR, Linux kernel 4.9 fails to build with ASan due to 
wrong handling of emitted ODR indicator symbols. Although this might be 
a kernel bug (relying on specific pattern in symbol name sounds 
questionable), kernel doesn't need ODR indicators at all thus we can 
just disable them if -fsanitize=kernel-address is present.
Tested on x86_64-unknown-linux-gnu, OK for trunk?

-Maxim


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: pr78887.diff --]
[-- Type: text/x-diff; name="pr78887.diff", Size: 718 bytes --]

gcc/ChangeLog:

2017-01-13  Maxim Ostapenko  <m.ostapenko@samsung.com>

	PR sanitizer/78887
	* asan.c (asan_needs_odr_indicator_p): Don't emit ODR indicators
	if -fsanitize=kernel-address is present.

diff --git a/gcc/asan.c b/gcc/asan.c
index bc7ebc8..157d468 100644
--- a/gcc/asan.c
+++ b/gcc/asan.c
@@ -2360,7 +2360,8 @@ create_odr_indicator (tree decl, tree type)
 static bool
 asan_needs_odr_indicator_p (tree decl)
 {
-  return !DECL_ARTIFICIAL (decl) && !DECL_WEAK (decl) && TREE_PUBLIC (decl);
+  return !(flag_sanitize & SANITIZE_KERNEL_ADDRESS) && !DECL_ARTIFICIAL (decl)
+	 && !DECL_WEAK (decl) && TREE_PUBLIC (decl);
 }
 
 /* Append description of a single global DECL into vector V.

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

* Re: [PATCH][PR sanitizer/78887] Don't emit ODR indicators if -fsanitize=kernel-address is present.
  2017-01-13  8:19 ` [PATCH][PR sanitizer/78887] Don't emit ODR indicators if -fsanitize=kernel-address is present Maxim Ostapenko
@ 2017-01-13  8:24   ` Jakub Jelinek
  2017-01-13  9:02     ` Maxim Ostapenko
  0 siblings, 1 reply; 4+ messages in thread
From: Jakub Jelinek @ 2017-01-13  8:24 UTC (permalink / raw)
  To: Maxim Ostapenko; +Cc: GCC Patches

On Fri, Jan 13, 2017 at 11:19:19AM +0300, Maxim Ostapenko wrote:
> as mentioned in PR, Linux kernel 4.9 fails to build with ASan due to wrong
> handling of emitted ODR indicator symbols. Although this might be a kernel
> bug (relying on specific pattern in symbol name sounds questionable), kernel
> doesn't need ODR indicators at all thus we can just disable them if
> -fsanitize=kernel-address is present.
> Tested on x86_64-unknown-linux-gnu, OK for trunk?

> gcc/ChangeLog:
> 
> 2017-01-13  Maxim Ostapenko  <m.ostapenko@samsung.com>
> 
> 	PR sanitizer/78887
> 	* asan.c (asan_needs_odr_indicator_p): Don't emit ODR indicators
> 	if -fsanitize=kernel-address is present.
> 
> diff --git a/gcc/asan.c b/gcc/asan.c
> index bc7ebc8..157d468 100644
> --- a/gcc/asan.c
> +++ b/gcc/asan.c
> @@ -2360,7 +2360,8 @@ create_odr_indicator (tree decl, tree type)
>  static bool
>  asan_needs_odr_indicator_p (tree decl)
>  {
> -  return !DECL_ARTIFICIAL (decl) && !DECL_WEAK (decl) && TREE_PUBLIC (decl);
> +  return !(flag_sanitize & SANITIZE_KERNEL_ADDRESS) && !DECL_ARTIFICIAL (decl)
> +	 && !DECL_WEAK (decl) && TREE_PUBLIC (decl);

As the condition is longer than a line, please use
  return (!(flag_sanitize & SANITIZE_KERNEL_ADDRESS)
	  && !DECL_ARTIFICIAL (decl)
	  && !DECL_WEAK (decl)
	  && TREE_PUBLIC (decl));
instead (i.e. one sub-condition per line, and ()s around the whole
condition.  Perhaps a short comment why we don't emit those for
-fsanitize=kernel-address would be useful too.

Ok for trunk with those changes.

	Jakub

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

* Re: [PATCH][PR sanitizer/78887] Don't emit ODR indicators if -fsanitize=kernel-address is present.
  2017-01-13  8:24   ` Jakub Jelinek
@ 2017-01-13  9:02     ` Maxim Ostapenko
  2017-01-13  9:03       ` Jakub Jelinek
  0 siblings, 1 reply; 4+ messages in thread
From: Maxim Ostapenko @ 2017-01-13  9:02 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: GCC Patches

[-- Attachment #1: Type: text/plain, Size: 1685 bytes --]

On 13/01/17 11:24, Jakub Jelinek wrote:
> On Fri, Jan 13, 2017 at 11:19:19AM +0300, Maxim Ostapenko wrote:
>> as mentioned in PR, Linux kernel 4.9 fails to build with ASan due to wrong
>> handling of emitted ODR indicator symbols. Although this might be a kernel
>> bug (relying on specific pattern in symbol name sounds questionable), kernel
>> doesn't need ODR indicators at all thus we can just disable them if
>> -fsanitize=kernel-address is present.
>> Tested on x86_64-unknown-linux-gnu, OK for trunk?
>> gcc/ChangeLog:
>>
>> 2017-01-13  Maxim Ostapenko  <m.ostapenko@samsung.com>
>>
>> 	PR sanitizer/78887
>> 	* asan.c (asan_needs_odr_indicator_p): Don't emit ODR indicators
>> 	if -fsanitize=kernel-address is present.
>>
>> diff --git a/gcc/asan.c b/gcc/asan.c
>> index bc7ebc8..157d468 100644
>> --- a/gcc/asan.c
>> +++ b/gcc/asan.c
>> @@ -2360,7 +2360,8 @@ create_odr_indicator (tree decl, tree type)
>>   static bool
>>   asan_needs_odr_indicator_p (tree decl)
>>   {
>> -  return !DECL_ARTIFICIAL (decl) && !DECL_WEAK (decl) && TREE_PUBLIC (decl);
>> +  return !(flag_sanitize & SANITIZE_KERNEL_ADDRESS) && !DECL_ARTIFICIAL (decl)
>> +	 && !DECL_WEAK (decl) && TREE_PUBLIC (decl);
> As the condition is longer than a line, please use
>    return (!(flag_sanitize & SANITIZE_KERNEL_ADDRESS)
> 	  && !DECL_ARTIFICIAL (decl)
> 	  && !DECL_WEAK (decl)
> 	  && TREE_PUBLIC (decl));
> instead (i.e. one sub-condition per line, and ()s around the whole
> condition.  Perhaps a short comment why we don't emit those for
> -fsanitize=kernel-address would be useful too.
>
> Ok for trunk with those changes.

OK, thanks, I'm going to apply following patch.

-Maxim

>
> 	Jakub
>
>


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: pr78887-2.diff --]
[-- Type: text/x-diff; name="pr78887-2.diff", Size: 1133 bytes --]

gcc/ChangeLog:

2017-01-13  Maxim Ostapenko  <m.ostapenko@samsung.com>

	PR sanitizer/78887
	* asan.c (asan_needs_odr_indicator_p): Don't emit ODR indicators
	if -fsanitize=kernel-address is present.

diff --git a/gcc/asan.c b/gcc/asan.c
index bc7ebc8..e3bf16d 100644
--- a/gcc/asan.c
+++ b/gcc/asan.c
@@ -2360,7 +2360,16 @@ create_odr_indicator (tree decl, tree type)
 static bool
 asan_needs_odr_indicator_p (tree decl)
 {
-  return !DECL_ARTIFICIAL (decl) && !DECL_WEAK (decl) && TREE_PUBLIC (decl);
+  /* Don't emit ODR indicators for kernel because:
+     a) Kernel is written in C thus doesn't need ODR indicators.
+     b) Some kernel code may have assumptions about symbols containing specific
+        patterns in their names.  Since ODR indicators contain original names
+        of symbols they are emmitted for, these assumptions would be broken for
+        ODR indicator symbols.  */
+  return (!(flag_sanitize & SANITIZE_KERNEL_ADDRESS)
+	  && !DECL_ARTIFICIAL (decl)
+	  && !DECL_WEAK (decl)
+	  && TREE_PUBLIC (decl));
 }
 
 /* Append description of a single global DECL into vector V.

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

* Re: [PATCH][PR sanitizer/78887] Don't emit ODR indicators if -fsanitize=kernel-address is present.
  2017-01-13  9:02     ` Maxim Ostapenko
@ 2017-01-13  9:03       ` Jakub Jelinek
  0 siblings, 0 replies; 4+ messages in thread
From: Jakub Jelinek @ 2017-01-13  9:03 UTC (permalink / raw)
  To: Maxim Ostapenko; +Cc: GCC Patches

On Fri, Jan 13, 2017 at 12:01:54PM +0300, Maxim Ostapenko wrote:
> +        of symbols they are emmitted for, these assumptions would be broken for

emitted rather than emmitted.

> +        ODR indicator symbols.  */
> +  return (!(flag_sanitize & SANITIZE_KERNEL_ADDRESS)
> +	  && !DECL_ARTIFICIAL (decl)
> +	  && !DECL_WEAK (decl)
> +	  && TREE_PUBLIC (decl));
>  }
>  
>  /* Append description of a single global DECL into vector V.


	Jakub

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

end of thread, other threads:[~2017-01-13  9:03 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <CGME20170113081926eucas1p2182a7b44313074dab4efc7d75d2362e2@eucas1p2.samsung.com>
2017-01-13  8:19 ` [PATCH][PR sanitizer/78887] Don't emit ODR indicators if -fsanitize=kernel-address is present Maxim Ostapenko
2017-01-13  8:24   ` Jakub Jelinek
2017-01-13  9:02     ` Maxim Ostapenko
2017-01-13  9:03       ` Jakub Jelinek

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).