1 ; RUN: llc < %s -mtriple=x86_64-pc-windows-msvc | FileCheck %s
2 ; Control Flow Guard is currently only available on Windows
4 declare dllimport i32 @target_func1()
5 declare dllimport i32 @target_func2()
6 declare dllimport i32 @target_func3()
7 @ptrs = dso_local local_unnamed_addr global [2 x void ()*] [void ()* bitcast (i32 ()* @target_func2 to void ()*), void ()* bitcast (i32 ()* @target_func3 to void ()*)], align 16
9 ; Test address-taken functions from imported DLLs are correctly added to the
10 ; Guard Address-Taken IAT Entry (.giats) and Guard Function ID (.gfids) sections.
11 define i32 @func_cf_giats1() {
13 ; Since it is a dllimport, target_func1 will be represented as "__imp_target_func1" when it is
14 ; stored in the function pointer. Therefore, the .giats section must contain "__imp_target_func1".
15 ; Unlike MSVC, we also have "target_func1" in the .gfids section, since this is not a security risk.
16 %func_ptr = alloca i32 ()*, align 8
17 store i32 ()* @target_func1, i32 ()** %func_ptr, align 8
18 %0 = load i32 ()*, i32 ()** %func_ptr, align 8
20 ; target_func2 is called directly from a global array, so should only appear in the .gfids section.
21 %2 = load i32 ()*, i32 ()** bitcast ([2 x void ()*]* @ptrs to i32 ()**), align 8
23 ; target_func3 is called both via a stored function pointer (as with target_func1) and via a gloabl
24 ; array (as with target_func2), so "target_func3" must appear in .gfids and "__imp_target_func3" in .giats.
25 store i32 ()* @target_func3, i32 ()** %func_ptr, align 8
26 %4 = load i32 ()*, i32 ()** %func_ptr, align 8
28 %6 = load i32 ()*, i32 ()** bitcast (void ()** getelementptr inbounds ([2 x void ()*], [2 x void ()*]* @ptrs, i64 0, i64 1) to i32 ()**), align 8
33 ; CHECK-LABEL: .section .gfids$y,"dr"
34 ; CHECK-NEXT: .symidx target_func1
35 ; CHECK-NEXT: .symidx target_func2
36 ; CHECK-NEXT: .symidx target_func3
38 ; CHECK-LABEL: .section .giats$y,"dr"
39 ; CHECK-NEXT: .symidx __imp_target_func1
40 ; CHECK-NEXT: .symidx __imp_target_func3
43 !llvm.module.flags = !{!0}
44 !0 = !{i32 2, !"cfguard", i32 2}