xref: /llvm-project/llvm/test/Instrumentation/AddressSanitizer/global_metadata_windows.ll (revision 855fe35064674c4601ea9c659a015cacdcec9f63)
1; Test that global metadata is placed in a separate section on Windows, and that
2; it is in the same comdat group as the instrumented global. This ensures that
3; linker dead stripping (/OPT:REF) works as intended.
4
5; FIXME: Later we can use this to instrument linkonce odr string literals.
6
7; RUN: opt < %s -passes=asan -asan-globals-live-support=1 -S | FileCheck %s
8
9target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128"
10target triple = "x86_64-pc-windows-msvc19.0.24215"
11
12$mystr = comdat any
13
14; CHECK: $dead_global = comdat nodeduplicate
15; CHECK: $private_str = comdat nodeduplicate
16
17; CHECK: @dead_global = global { i32, [28 x i8] } { i32 42, [28 x i8] zeroinitializer }, comdat, align 32
18; CHECK: @private_str = internal constant { [8 x i8], [24 x i8] } { [8 x i8] c"private\00", [24 x i8] zeroinitializer }, comdat, align 32
19
20; CHECK: @__asan_global_dead_global = private global { {{.*}} }, section ".ASAN$GL", comdat($dead_global), align 64, !associated
21; CHECK: @__asan_global_private_str = private global { {{.*}} }, section ".ASAN$GL", comdat($private_str), align 64, !associated
22
23; CHECK: @llvm.compiler.used = appending global [6 x ptr] [ptr @dead_global, ptr @mystr, ptr @private_str, ptr @__asan_global_dead_global, ptr @__asan_global_mystr, ptr @__asan_global_private_str], section "llvm.metadata"
24
25@dead_global = local_unnamed_addr global i32 42, align 4
26@mystr = linkonce_odr unnamed_addr constant [5 x i8] c"main\00", comdat, align 1
27
28; Private globals will get upgraded to internal linkage.
29@private_str = private unnamed_addr constant [8 x i8] c"private\00", align 1
30
31; Function Attrs: nounwind uwtable
32define i32 @main() local_unnamed_addr #0 {
33entry:
34  %call = tail call i32 @puts(ptr @mystr)
35  %call2 = tail call i32 @puts(ptr @private_str)
36  ret i32 0
37}
38
39; Function Attrs: nounwind
40declare i32 @puts(ptr nocapture readonly) local_unnamed_addr #1
41
42attributes #0 = { nounwind uwtable "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "frame-pointer"="none" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" }
43attributes #1 = { nounwind "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "frame-pointer"="none" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" }
44
45!llvm.module.flags = !{!0}
46!llvm.ident = !{!1}
47
48!0 = !{i32 1, !"PIC Level", i32 2}
49!1 = !{!"clang version 4.0.0 "}
50