public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] asan: adjust module name for global variables
@ 2023-02-24  9:00 Martin Liška
  2023-02-24  9:07 ` Jakub Jelinek
  0 siblings, 1 reply; 3+ messages in thread
From: Martin Liška @ 2023-02-24  9:00 UTC (permalink / raw)
  To: gcc-patches; +Cc: Jakub Jelinek

As mentioned in the PR, when we use LTO, we wrongly use ltrans output
file name as a module name of a global variable. That leads to a
non-reproducible output.

After the suggested change, we emit context name of normal global
variables. And for artificial variables (like .Lubsan_data3), we use
aux_base_name (e.g. "./a.ltrans0.ltrans").

Patch can bootstrap on x86_64-linux-gnu and survives regression tests.

Ready to be installed?
Thanks,
Martin

	PR asan/108834

gcc/ChangeLog:

	* asan.cc (asan_add_global): Use proper TU name for normal
	  global variables (and aux_base_name for the artificial one).

gcc/testsuite/ChangeLog:

	* c-c++-common/asan/global-overflow-1.c: Test line and column
	info for a global variable.
---
 gcc/asan.cc                                         | 7 ++++++-
 gcc/testsuite/c-c++-common/asan/global-overflow-1.c | 2 +-
 2 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/gcc/asan.cc b/gcc/asan.cc
index f56d084bc7a..245abb14388 100644
--- a/gcc/asan.cc
+++ b/gcc/asan.cc
@@ -3287,7 +3287,12 @@ asan_add_global (tree decl, tree type, vec<constructor_elt, va_gc> *v)
     pp_string (&asan_pp, "<unknown>");
   str_cst = asan_pp_string (&asan_pp);
 
-  pp_string (&module_name_pp, main_input_filename);
+  const_tree tu = get_ultimate_context ((const_tree)decl);
+  if (tu != NULL_TREE)
+    pp_string (&module_name_pp, IDENTIFIER_POINTER (DECL_NAME (tu)));
+  else
+    pp_string (&module_name_pp, aux_base_name);
+
   module_name_cst = asan_pp_string (&module_name_pp);
 
   if (asan_needs_local_alias (decl))
diff --git a/gcc/testsuite/c-c++-common/asan/global-overflow-1.c b/gcc/testsuite/c-c++-common/asan/global-overflow-1.c
index b97801da2b7..7e167cee67a 100644
--- a/gcc/testsuite/c-c++-common/asan/global-overflow-1.c
+++ b/gcc/testsuite/c-c++-common/asan/global-overflow-1.c
@@ -26,4 +26,4 @@ int main() {
 /* { dg-output "READ of size 1 at 0x\[0-9a-f\]+ thread T0.*(\n|\r\n|\r)" } */
 /* { dg-output "    #0 0x\[0-9a-f\]+ +(in _*main (\[^\n\r]*global-overflow-1.c:20|\[^\n\r]*:0|\[^\n\r]*\\+0x\[0-9a-z\]*)|\[(\])\[^\n\r]*(\n|\r\n|\r).*" } */
 /* { dg-output "0x\[0-9a-f\]+ is located 0 bytes after global variable" } */
-/* { dg-output ".*YYY\[^\n\r]* of size 10\[^\n\r]*(\n|\r\n|\r)" } */
+/* { dg-output ".*YYY\[^\n\r]*asan/global-overflow-1.c:15:15'\[^\n\r]*of size 10\[^\n\r]*(\n|\r\n|\r)" } */
-- 
2.39.2


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

* Re: [PATCH] asan: adjust module name for global variables
  2023-02-24  9:00 [PATCH] asan: adjust module name for global variables Martin Liška
@ 2023-02-24  9:07 ` Jakub Jelinek
  2023-02-24 15:22   ` Martin Liška
  0 siblings, 1 reply; 3+ messages in thread
From: Jakub Jelinek @ 2023-02-24  9:07 UTC (permalink / raw)
  To: Martin Liška; +Cc: gcc-patches

On Fri, Feb 24, 2023 at 10:00:01AM +0100, Martin Liška wrote:
> As mentioned in the PR, when we use LTO, we wrongly use ltrans output
> file name as a module name of a global variable. That leads to a
> non-reproducible output.
> 
> After the suggested change, we emit context name of normal global
> variables. And for artificial variables (like .Lubsan_data3), we use
> aux_base_name (e.g. "./a.ltrans0.ltrans").
> 
> Patch can bootstrap on x86_64-linux-gnu and survives regression tests.
> 
> Ready to be installed?
> Thanks,
> Martin
> 
> 	PR asan/108834
> 
> gcc/ChangeLog:
> 
> 	* asan.cc (asan_add_global): Use proper TU name for normal
> 	  global variables (and aux_base_name for the artificial one).
> 
> gcc/testsuite/ChangeLog:
> 
> 	* c-c++-common/asan/global-overflow-1.c: Test line and column
> 	info for a global variable.
> ---
>  gcc/asan.cc                                         | 7 ++++++-
>  gcc/testsuite/c-c++-common/asan/global-overflow-1.c | 2 +-
>  2 files changed, 7 insertions(+), 2 deletions(-)
> 
> diff --git a/gcc/asan.cc b/gcc/asan.cc
> index f56d084bc7a..245abb14388 100644
> --- a/gcc/asan.cc
> +++ b/gcc/asan.cc
> @@ -3287,7 +3287,12 @@ asan_add_global (tree decl, tree type, vec<constructor_elt, va_gc> *v)
>      pp_string (&asan_pp, "<unknown>");
>    str_cst = asan_pp_string (&asan_pp);
>  
> -  pp_string (&module_name_pp, main_input_filename);
> +  const_tree tu = get_ultimate_context ((const_tree)decl);
> +  if (tu != NULL_TREE)
> +    pp_string (&module_name_pp, IDENTIFIER_POINTER (DECL_NAME (tu)));
> +  else
> +    pp_string (&module_name_pp, aux_base_name);

I think for !in_lto_p we don't need to bother with get_ultimate_context
and should just use main_input_filename as before.

Otherwise LGTM.

	Jakub


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

* Re: [PATCH] asan: adjust module name for global variables
  2023-02-24  9:07 ` Jakub Jelinek
@ 2023-02-24 15:22   ` Martin Liška
  0 siblings, 0 replies; 3+ messages in thread
From: Martin Liška @ 2023-02-24 15:22 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: gcc-patches

On 2/24/23 10:07, Jakub Jelinek wrote:
> On Fri, Feb 24, 2023 at 10:00:01AM +0100, Martin Liška wrote:
>> As mentioned in the PR, when we use LTO, we wrongly use ltrans output
>> file name as a module name of a global variable. That leads to a
>> non-reproducible output.
>>
>> After the suggested change, we emit context name of normal global
>> variables. And for artificial variables (like .Lubsan_data3), we use
>> aux_base_name (e.g. "./a.ltrans0.ltrans").
>>
>> Patch can bootstrap on x86_64-linux-gnu and survives regression tests.
>>
>> Ready to be installed?
>> Thanks,
>> Martin
>>
>> 	PR asan/108834
>>
>> gcc/ChangeLog:
>>
>> 	* asan.cc (asan_add_global): Use proper TU name for normal
>> 	  global variables (and aux_base_name for the artificial one).
>>
>> gcc/testsuite/ChangeLog:
>>
>> 	* c-c++-common/asan/global-overflow-1.c: Test line and column
>> 	info for a global variable.
>> ---
>>  gcc/asan.cc                                         | 7 ++++++-
>>  gcc/testsuite/c-c++-common/asan/global-overflow-1.c | 2 +-
>>  2 files changed, 7 insertions(+), 2 deletions(-)
>>
>> diff --git a/gcc/asan.cc b/gcc/asan.cc
>> index f56d084bc7a..245abb14388 100644
>> --- a/gcc/asan.cc
>> +++ b/gcc/asan.cc
>> @@ -3287,7 +3287,12 @@ asan_add_global (tree decl, tree type, vec<constructor_elt, va_gc> *v)
>>      pp_string (&asan_pp, "<unknown>");
>>    str_cst = asan_pp_string (&asan_pp);
>>  
>> -  pp_string (&module_name_pp, main_input_filename);
>> +  const_tree tu = get_ultimate_context ((const_tree)decl);
>> +  if (tu != NULL_TREE)
>> +    pp_string (&module_name_pp, IDENTIFIER_POINTER (DECL_NAME (tu)));
>> +  else
>> +    pp_string (&module_name_pp, aux_base_name);
> 
> I think for !in_lto_p we don't need to bother with get_ultimate_context
> and should just use main_input_filename as before.

All right, pushed with that change.

Thanks,
Martin

> 
> Otherwise LGTM.
> 
> 	Jakub
> 


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

end of thread, other threads:[~2023-02-24 15:22 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-24  9:00 [PATCH] asan: adjust module name for global variables Martin Liška
2023-02-24  9:07 ` Jakub Jelinek
2023-02-24 15:22   ` Martin Liška

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