Skip to content

Commit 3250330

Browse files
authored
[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 / #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 ```
1 parent b0bae44 commit 3250330

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1957,6 +1957,10 @@ bool ModuleAddressSanitizer::shouldInstrumentGlobal(GlobalVariable *G) const {
19571957
// On COFF, don't instrument non-ODR linkages.
19581958
if (G->isInterposable())
19591959
return false;
1960+
// If the global has AvailableExternally linkage, then it is not in this
1961+
// module, which means it does not need to be instrumented.
1962+
if (G->hasAvailableExternallyLinkage())
1963+
return false;
19601964
}
19611965

19621966
// If a comdat is present, it must have a selection kind that implies ODR
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
; This test checks that we are not instrumenting unnecessary globals
2+
; RUN: opt < %s -passes=asan -S | FileCheck %s
3+
4+
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
5+
target triple = "x86_64-pc-windows-msvc"
6+
7+
@v_available_externally = available_externally global i32 zeroinitializer
8+
; CHECK-NOT: {{asan_gen.*v_available_externally}}
9+
10+
; CHECK: @asan.module_ctor

0 commit comments

Comments
 (0)