2 # Make a DLL that exports exportfn1.
3 # RUN: yaml2obj %p/Inputs/export.yaml -o %basename_t-exp.obj
4 # RUN: lld-link /out:%basename_t-exp.dll /dll %basename_t-exp.obj /export:exportfn1 /implib:%basename_t-exp.lib
5 # RUN: split-file %s %t
6 # RUN: llvm-mc -triple x86_64-windows-msvc %t/main.s -filetype=obj -o %t/main.obj
8 # RUN: lld-link %t/main.obj -guard:cf,longjmp,ehcont -out:%t-missing.exe -entry:main %basename_t-exp.lib 2>&1 | FileCheck %s --check-prefix=WARN_MISSING
9 # WARN_MISSING: warning: Control Flow Guard is enabled but '_load_config_used' is missing
11 # RUN: llvm-mc -triple x86_64-windows-msvc %t/loadcfg-invalid.s -filetype=obj -o %t/loadcfg-invalid.obj
12 # RUN: lld-link %t/main.obj %t/loadcfg-invalid.obj -guard:cf,longjmp,ehcont -out:%t-invalid.exe -entry:main %basename_t-exp.lib 2>&1 | FileCheck %s --check-prefix=WARN_INVALID
13 # WARN_INVALID: warning: GuardCFFunctionTable not set correctly in '_load_config_used'
14 # WARN_INVALID-NEXT: warning: GuardCFFunctionCount not set correctly in '_load_config_used'
15 # WARN_INVALID-NEXT: warning: GuardFlags not set correctly in '_load_config_used'
16 # WARN_INVALID-NEXT: warning: GuardAddressTakenIatEntryTable not set correctly in '_load_config_used'
17 # WARN_INVALID-NEXT: warning: GuardAddressTakenIatEntryCount not set correctly in '_load_config_used'
18 # WARN_INVALID-NEXT: warning: GuardLongJumpTargetTable not set correctly in '_load_config_used'
19 # WARN_INVALID-NEXT: warning: GuardLongJumpTargetCount not set correctly in '_load_config_used'
20 # WARN_INVALID-NEXT: warning: GuardEHContinuationTable not set correctly in '_load_config_used'
21 # WARN_INVALID-NEXT: warning: GuardEHContinuationCount not set correctly in '_load_config_used'
23 # RUN: llvm-mc -triple x86_64-windows-msvc %t/loadcfg-small112.s -filetype=obj -o %t/loadcfg-small112.obj
24 # RUN: lld-link %t/main.obj %t/loadcfg-small112.obj -guard:cf,longjmp -out:%t-small112.exe -entry:main %basename_t-exp.lib 2>&1 | FileCheck %s --check-prefix=WARN_SMALL_112
25 # WARN_SMALL_112: warning: '_load_config_used' structure too small to include GuardFlags
27 # RUN: llvm-mc -triple x86_64-windows-msvc %t/loadcfg-small148.s -filetype=obj -o %t/loadcfg-small148.obj
28 # RUN: lld-link %t/main.obj %t/loadcfg-small148.obj -guard:cf,longjmp -out:%t-small148.exe -entry:main %basename_t-exp.lib 2>&1 | FileCheck %s --check-prefix=WARN_SMALL_148
29 # WARN_SMALL_148: warning: '_load_config_used' structure too small to include GuardLongJumpTargetCount
31 # RUN: llvm-mc -triple x86_64-windows-msvc %t/loadcfg-small244.s -filetype=obj -o %t/loadcfg-small244.obj
32 # RUN: lld-link %t/main.obj %t/loadcfg-small244.obj -guard:cf,longjmp,ehcont -out:%t-small244.exe -entry:main %basename_t-exp.lib 2>&1 | FileCheck %s --check-prefix=WARN_SMALL_244
33 # WARN_SMALL_244: warning: '_load_config_used' structure too small to include GuardEHContinuationCount
35 # RUN: llvm-mc -triple x86_64-windows-msvc %t/loadcfg-misaligned1.s -filetype=obj -o %t/loadcfg-misaligned1.obj
36 # RUN: lld-link %t/main.obj %t/loadcfg-misaligned1.obj -guard:cf,longjmp,ehcont -out:%t-misaligned1.exe -entry:main %basename_t-exp.lib 2>&1 | FileCheck %s --check-prefix=WARN_ALIGN1
37 # WARN_ALIGN1: warning: '_load_config_used' is misaligned (expected alignment to be 8 bytes, got 4 instead)
39 # RUN: llvm-mc -triple x86_64-windows-msvc %t/loadcfg-misaligned2.s -filetype=obj -o %t/loadcfg-misaligned2.obj
40 # RUN: lld-link %t/main.obj %t/loadcfg-misaligned2.obj -guard:cf,longjmp,ehcont -out:%t-misaligned2.exe -entry:main %basename_t-exp.lib 2>&1 | FileCheck %s --check-prefix=WARN_ALIGN2
41 # WARN_ALIGN2: warning: '_load_config_used' is misaligned (RVA is 0x{{[0-9A-F]*}}2 not aligned to 8 bytes)
43 # RUN: llvm-mc -triple x86_64-windows-msvc %t/loadcfg-full.s -filetype=obj -o %t/loadcfg-full.obj
44 # RUN: lld-link %t/main.obj %t/loadcfg-full.obj -guard:cf,longjmp,ehcont -out:%t.exe -entry:main %basename_t-exp.lib 2>&1 | FileCheck %s --check-prefix=NOWARN --allow-empty
47 # Sanity check to make sure the no-warn version has the expected data.
48 # RUN: llvm-readobj --file-headers --coff-load-config %t.exe | FileCheck --check-prefix=CHECK %s
49 # CHECK: ImageBase: 0x140000000
51 # CHECK: SEHandlerTable: 0x0
52 # CHECK: SEHandlerCount: 0
53 # CHECK: GuardCFCheckFunction: 0x0
54 # CHECK: GuardCFCheckDispatch: 0x0
55 # CHECK: GuardCFFunctionTable: 0x14000{{([0-9A-F]{4})}}
56 # CHECK: GuardCFFunctionCount: 1
57 # CHECK: GuardFlags [ (0x410500)
58 # CHECK: CF_FUNCTION_TABLE_PRESENT (0x400)
59 # CHECK: CF_INSTRUMENTED (0x100)
60 # CHECK: CF_LONGJUMP_TABLE_PRESENT (0x10000)
61 # CHECK: EH_CONTINUATION_TABLE_PRESENT (0x400000)
63 # CHECK: GuardAddressTakenIatEntryTable: 0x14000{{([0-9A-F]{4})}}
64 # CHECK: GuardAddressTakenIatEntryCount: 1
65 # CHECK: GuardLongJumpTargetTable: 0x14000{{([0-9A-F]{4})}}
66 # CHECK: GuardLongJumpTargetCount: 1
67 # CHECK: GuardEHContinuationTable: 0x14000{{([0-9A-F]{4})}}
68 # CHECK: GuardEHContinuationCount: 1
70 # CHECK-NEXT: GuardFidTable [
71 # CHECK-NEXT: 0x14000{{([0-9A-F]{4})}}
73 # CHECK-NEXT: GuardIatTable [
74 # CHECK-NEXT: 0x14000{{([0-9A-F]{4})}}
76 # CHECK-NEXT: GuardLJmpTable [
77 # CHECK-NEXT: 0x14000{{([0-9A-F]{4})}}
79 # CHECK-NEXT: GuardEHContTable [
80 # CHECK-NEXT: 0x14000{{([0-9A-F]{4})}}
86 # We need @feat.00 to have 0x4000 | 0x800 to indicate /guard:cf and /guard:ehcont.
93 .def main; .scl 2; .type 32; .endef
94 .globl main # -- Begin function main
98 movq __imp_exportfn1
(%rip
), %rax
111 .section .gfids$y,"dr"
113 .section .giats$y,"dr"
114 .symidx __imp_exportfn1
115 .section .gljmp$y,"dr"
117 .section .gehcont$y,"dr"
120 .addrsig_sym __imp_exportfn1
123 #--- loadcfg-invalid.s
125 .globl _load_config_used
131 #--- loadcfg-small112.s
133 .globl _load_config_used
139 #--- loadcfg-small148.s
141 .globl _load_config_used
146 .quad __guard_fids_table
147 .quad __guard_fids_count
150 #--- loadcfg-small244.s
152 .globl _load_config_used
157 .quad __guard_fids_table
158 .quad __guard_fids_count
161 .quad __guard_iat_table
162 .quad __guard_iat_count
163 .quad __guard_longjmp_table
164 .quad __guard_longjmp_count
165 .fill 52, 1, 0 # Up to HotPatchTableOffset
167 #--- loadcfg-misaligned1.s
169 .globl _load_config_used
170 .fill 2, 1, 0 # offset by 2
171 .p2align 2 # then align to 0x04
175 .quad __guard_fids_table
176 .quad __guard_fids_count
179 .quad __guard_iat_table
180 .quad __guard_iat_count
181 .quad __guard_longjmp_table
182 .quad __guard_longjmp_count
184 .quad __guard_eh_cont_table
185 .quad __guard_eh_cont_count
188 #--- loadcfg-misaligned2.s
190 .globl _load_config_used
191 .p2align 4 # align to 0x10
192 .fill 2, 1, 0 # then offset by 2
196 .quad __guard_fids_table
197 .quad __guard_fids_count
200 .quad __guard_iat_table
201 .quad __guard_iat_count
202 .quad __guard_longjmp_table
203 .quad __guard_longjmp_count
205 .quad __guard_eh_cont_table
206 .quad __guard_eh_cont_count
211 .globl _load_config_used
216 .quad __guard_fids_table
217 .quad __guard_fids_count
220 .quad __guard_iat_table
221 .quad __guard_iat_count
222 .quad __guard_longjmp_table
223 .quad __guard_longjmp_count
225 .quad __guard_eh_cont_table
226 .quad __guard_eh_cont_count