]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libsanitizer: cherry-pick commit 8f5962b1ccb5fcd4d4544121d43efb860ac3cc6d from upstream
authorMartin Liska <mliska@suse.cz>
Fri, 24 Feb 2023 08:14:40 +0000 (09:14 +0100)
committerMartin Liska <mliska@suse.cz>
Fri, 24 Feb 2023 08:14:40 +0000 (09:14 +0100)
ASAN: keep support for Global::location

We as GCC still emit __asan_global_source_location for global variables
and we would like to use it in the future. On other hand, we don't
support llvm-symbolizer and the default libbacktraace symbolizer
does not support location info.

libsanitizer/asan/asan_globals.cpp
libsanitizer/asan/asan_interface_internal.h

index 8f3491f01991b10f50e1d11bc938688d876fa768..01a243927cacd8e422fbec4b720289eebac6b7c1 100644 (file)
@@ -92,6 +92,10 @@ static void ReportGlobal(const Global &g, const char *prefix) {
   if (info.line != 0) {
     Report("  location: name=%s, %d\n", info.file, static_cast<int>(info.line));
   }
+  else if (g.gcc_location != 0) {
+    // Fallback to Global::gcc_location
+    Report("  location: name=%s, %d\n", g.gcc_location->filename, g.gcc_location->line_no);
+  }
 }
 
 static u32 FindRegistrationSite(const Global *g) {
@@ -283,6 +287,11 @@ void PrintGlobalLocation(InternalScopedString *str, const __asan_global &g) {
 
   if (info.line != 0) {
     str->append("%s:%d", info.file, static_cast<int>(info.line));
+  } else if (g.gcc_location != 0) {
+    // Fallback to Global::gcc_location
+    str->append("%s", g.gcc_location->filename ? g.gcc_location->filename : g.module_name);
+    if (g.gcc_location->line_no) str->append(":%d", g.gcc_location->line_no);
+    if (g.gcc_location->column_no) str->append(":%d", g.gcc_location->column_no);
   } else {
     str->append("%s", g.module_name);
   }
index 987f855c0f9cefcc7aba01d2ebdf0b19ed46c5c4..a998263780221734598c103a2cb00ff56b4ae491 100644 (file)
@@ -53,9 +53,10 @@ extern "C" {
     const char *module_name; // Module name as a C string. This pointer is a
                              // unique identifier of a module.
     uptr has_dynamic_init;   // Non-zero if the global has dynamic initializer.
-    uptr windows_padding;    // TODO: Figure out how to remove this padding
-                             // that's simply here to make the MSVC incremental
-                             // linker happy...
+    __asan_global_source_location *gcc_location;  // Source location of a global,
+                                                  // used by GCC compiler. LLVM uses
+                                                  // llvm-symbolizer that relies
+                                                  // on DWARF debugging info.
     uptr odr_indicator;      // The address of the ODR indicator symbol.
   };