1// RUN: %clang_cl_asan %LD %Od -DDLL %s %Fe%t.dll \
2// RUN: %if target={{.*-windows-gnu}} %{ -Wl,--out-implib,%t.lib %}
3// RUN: %clang_cl_asan %Od -DEXE %s %t.lib %Fe%te.exe
4// RUN: %env_asan_opts=report_globals=2 %run %te.exe 2>&1 | FileCheck %s
5
6// FIXME: Currently, the MT runtime build crashes on startup due to dbghelp.dll
7// initialization failure.
8// REQUIRES: asan-dynamic-runtime
9
10#include <windows.h>
11#include <stdio.h>
12
13#if defined(EXE)
14extern "C" __declspec(dllimport) int foo_from_dll();
15
16// CHECK: in DLL(reason=1)
17int main(int argc, char **argv) {
18 foo_from_dll();
19// CHECK: hello!
20 printf("hello!\n");
21 fflush(0);
22// CHECK: in DLL(reason=0)
23}
24#elif defined(DLL)
25extern "C" {
26// This global is registered at startup.
27int x[42];
28
29__declspec(dllexport) int foo_from_dll() {
30 return x[2];
31}
32
33BOOL WINAPI DllMain(HMODULE, DWORD reason, LPVOID) {
34 printf("in DLL(reason=%d)\n", (int)reason);
35 fflush(0);
36 return TRUE;
37}
38}
39#else
40# error oops!
41#endif
42

source code of compiler-rt/test/asan/TestCases/Windows/dll_report_globals_symbolization_at_startup.cpp