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