Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 1 | // RUN: %clang_cl_asan -LD -O0 -DDLL %s -Fe%t.dll |
| 2 | // RUN: %clang_cl_asan -O0 -DEXE %s -Fe%te.exe |
Pirama Arumuga Nainar | cdce50b | 2015-07-01 12:26:56 -0700 | [diff] [blame] | 3 | // RUN: env ASAN_OPTIONS=%ASAN_OPTIONS%:report_globals=2 %run %te.exe %t.dll 2>&1 | FileCheck %s |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 4 | |
| 5 | #include <windows.h> |
| 6 | #include <stdio.h> |
| 7 | #include <string.h> |
| 8 | |
| 9 | extern "C" { |
| 10 | #if defined(EXE) |
| 11 | int main(int argc, char **argv) { |
| 12 | if (argc != 2) { |
| 13 | printf("Usage: %s [client].dll\n", argv[0]); |
| 14 | return 101; |
| 15 | } |
| 16 | const char *dll_name = argv[1]; |
| 17 | |
| 18 | // CHECK: time to load DLL |
| 19 | printf("time to load DLL\n"); |
| 20 | fflush(0); |
| 21 | |
| 22 | // On DLL load, the "in DLL\n" string is registered: |
| 23 | // CHECK: Added Global{{.*}} size=19 |
| 24 | // CHECK: in DLL(reason=1) |
| 25 | HMODULE dll = LoadLibrary(dll_name); |
| 26 | if (dll == NULL) |
| 27 | return 3; |
| 28 | |
| 29 | // CHECK: in DLL(reason=0) |
| 30 | // CHECK-NEXT: Removed Global{{.*}} size=19 |
| 31 | if (!FreeLibrary(dll)) |
| 32 | return 4; |
| 33 | |
| 34 | // CHECK: bye! |
| 35 | printf("bye!\n"); |
| 36 | fflush(0); |
| 37 | } |
| 38 | #elif defined(DLL) |
| 39 | BOOL WINAPI DllMain(HMODULE, DWORD reason, LPVOID) { |
| 40 | printf("in DLL(reason=%d)\n", (int)reason); |
| 41 | fflush(0); |
| 42 | return TRUE; |
| 43 | } |
| 44 | #else |
| 45 | # error oops! |
| 46 | #endif |
| 47 | } |