]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
asan: adjust module name for global variables
authorMartin Liska <mliska@suse.cz>
Fri, 17 Feb 2023 14:11:02 +0000 (15:11 +0100)
committerMartin Liska <mliska@suse.cz>
Mon, 27 Feb 2023 08:30:32 +0000 (09:30 +0100)
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").

PR sanitizer/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.

(cherry picked from commit 94c9b1bb79f63d000ebb05efc155c149325e332d)

gcc/asan.cc
gcc/testsuite/c-c++-common/asan/global-overflow-1.c

index f0dca99507d7a83647416e2804b1670f2c882bd5..20e5ef9d378d4dfa3e13a7e6770c8169b4768dac 100644 (file)
@@ -3246,7 +3246,17 @@ 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);
+  if (!in_lto_p)
+    pp_string (&module_name_pp, main_input_filename);
+  else
+    {
+      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))
index ec412231be0d9cf390de2acf595329f2dd69419d..ad5dbfc649de05ccd8f373f26eebe54d564e36ae 100644 (file)
@@ -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 to the right of 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)" } */