1// Make sure we can handle reloading the same DLL multiple times.
2// RUN: %clang_cl_asan %LD %Od -DDLL %s %Fe%t.dll
3// RUN: %clang_cl_asan %Od -DEXE %s %Fe%te.exe
4// RUN: %env_asan_opts=report_globals=1 %run %te.exe %t.dll 2>&1 | FileCheck %s
5
6#include <windows.h>
7#include <stdio.h>
8#include <string.h>
9
10extern "C" {
11#if defined(EXE)
12int main(int argc, char **argv) {
13 if (argc != 2) {
14 printf("Usage: %s [client].dll\n", argv[0]);
15 return 101;
16 }
17 const char *dll_name = argv[1];
18
19// CHECK: time to load DLL
20 printf("time to load DLL\n");
21 fflush(0);
22
23// CHECK: in DLL(reason=1)
24// CHECK: in DLL(reason=0)
25// CHECK: in DLL(reason=1)
26// CHECK: in DLL(reason=0)
27// CHECK: in DLL(reason=1)
28// CHECK: in DLL(reason=0)
29 for (int i = 0; i < 30; ++i) {
30 HMODULE dll = LoadLibrary(dll_name);
31 if (dll == NULL)
32 return 3;
33
34 if (!FreeLibrary(dll))
35 return 4;
36 }
37
38// CHECK: All OK!
39 printf("All OK!\n");
40 fflush(0);
41}
42#elif defined(DLL)
43BOOL WINAPI DllMain(HMODULE, DWORD reason, LPVOID) {
44 printf("in DLL(reason=%d)\n", (int)reason);
45 fflush(0);
46 return TRUE;
47}
48#else
49# error oops!
50#endif
51}
52

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