1// RUN: %clang_cl_asan %Od %p/dll_host.cpp %Fe%t
2//
3// RUN: %clang_cl_nocxx_asan %Gw %LD %Od %s %Fe%t.dll
4// RUN: %env_asan_opts=report_globals=2 %run %t %t.dll 2>&1 | FileCheck %s --check-prefix=NOSTRIP
5// RUN: %clang_cl_nocxx_asan %Gw %LD -O2 %s %Fe%t.dll \
6// RUN: %if target={{.*-windows-gnu}} %{ -Wl,--gc-sections %} \
7// RUN: %else %{ -link -opt:ref %}
8// RUN: %env_asan_opts=report_globals=2 %run %t %t.dll 2>&1 | FileCheck %s --check-prefix=STRIP
9
10#include <stdio.h>
11
12int dead_global = 42;
13int live_global = 0;
14
15__declspec(dllexport)
16int test_function() {
17 puts(s: "main");
18 return live_global;
19}
20
21// Check that our global registration scheme works with MSVC's linker dead
22// stripping (/OPT:REF).
23
24// NOSTRIP: Added Global{{.*}}name=dead_global
25// NOSTRIP: Added Global{{.*}}name=live_global
26// NOSTRIP: main
27
28// STRIP-NOT: Added Global{{.*}}name=dead_global
29// STRIP: Added Global{{.*}}name=live_global
30// STRIP: main
31

source code of compiler-rt/test/asan/TestCases/Windows/dll_global_dead_strip.c