[llvm] 3250330 - [asan] Disable instrumentation for available_externally global with COFF (#81109)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Feb 27 12:52:09 PST 2024
Author: Wu Yingcong
Date: 2024-02-27T12:52:04-08:00
New Revision: 3250330997cf214293a20a1d532b617d72bafb09
URL: https://github.com/llvm/llvm-project/commit/3250330997cf214293a20a1d532b617d72bafb09
DIFF: https://github.com/llvm/llvm-project/commit/3250330997cf214293a20a1d532b617d72bafb09.diff
LOG: [asan] Disable instrumentation for available_externally global with COFF (#81109)
For COFF, available_externally global will be instrumented because of
the lack of filtering, and will trigger the Verifier pass assertion and
crash the compilation. This patch will filter out the
available_externally global for COFF.
For non-COFF, `!G->hasExactDefinition()` in line 1954 will filter out
the available_externally globals.
There is a related bug reported in
https://bugs.llvm.org/show_bug.cgi?id=47950 /
https://github.com/llvm/llvm-project/issues/47294. I tried the
reproducer posted on the page and this will fix the problem.
Reproducer:
```
#include <locale>
void grouping_impl() {
std::use_facet<std::numpunct<char>>(std::locale());
}
// clang -fsanitize=address -D_DLL -std=c++14 -c format.cc
```
Added:
llvm/test/Instrumentation/AddressSanitizer/do-not-instrument-globals-windows.ll
Modified:
llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp b/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
index 8a2864a0787312..5d5c4ea57ed56c 100644
--- a/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
+++ b/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
@@ -1957,6 +1957,10 @@ bool ModuleAddressSanitizer::shouldInstrumentGlobal(GlobalVariable *G) const {
// On COFF, don't instrument non-ODR linkages.
if (G->isInterposable())
return false;
+ // If the global has AvailableExternally linkage, then it is not in this
+ // module, which means it does not need to be instrumented.
+ if (G->hasAvailableExternallyLinkage())
+ return false;
}
// If a comdat is present, it must have a selection kind that implies ODR
diff --git a/llvm/test/Instrumentation/AddressSanitizer/do-not-instrument-globals-windows.ll b/llvm/test/Instrumentation/AddressSanitizer/do-not-instrument-globals-windows.ll
new file mode 100644
index 00000000000000..c143f69f126a85
--- /dev/null
+++ b/llvm/test/Instrumentation/AddressSanitizer/do-not-instrument-globals-windows.ll
@@ -0,0 +1,10 @@
+; This test checks that we are not instrumenting unnecessary globals
+; RUN: opt < %s -passes=asan -S | FileCheck %s
+
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-pc-windows-msvc"
+
+ at v_available_externally = available_externally global i32 zeroinitializer
+; CHECK-NOT: {{asan_gen.*v_available_externally}}
+
+; CHECK: @asan.module_ctor
More information about the llvm-commits
mailing list