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
13extern "C" {
14#if defined(EXE)
15__declspec(dllimport) int foo_from_dll();
16
17// CHECK: in DLL(reason=1)
18int main(int argc, char **argv) {
19 foo_from_dll();
20// CHECK: hello!
21 printf("hello!\n");
22 fflush(0);
23// CHECK: in DLL(reason=0)
24}
25#elif defined(DLL)
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#else
39# error oops!
40#endif
41}
42

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