1; RUN: llc < %s -mtriple=x86_64-pc-windows-msvc | FileCheck %s 2; Control Flow Guard is currently only available on Windows 3 4declare dllimport i32 @target_func1() 5declare dllimport i32 @target_func2() 6declare 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 8 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. 11define i32 @func_cf_giats1() { 12entry: 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 19 %1 = call i32 %0() 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 22 %3 = call i32 %2() 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 27 %5 = call i32 %4() 28 %6 = load i32 ()*, i32 ()** bitcast (void ()** getelementptr inbounds ([2 x void ()*], [2 x void ()*]* @ptrs, i64 0, i64 1) to i32 ()**), align 8 29 %7 = call i32 %6() 30 ret i32 %5 31} 32 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 37; CHECK-NOT: .symidx 38; CHECK-LABEL: .section .giats$y,"dr" 39; CHECK-NEXT: .symidx __imp_target_func1 40; CHECK-NEXT: .symidx __imp_target_func3 41; CHECK-NOT: .symidx 42 43!llvm.module.flags = !{!0} 44!0 = !{i32 2, !"cfguard", i32 2} 45