[MemProf] Templatize CallStackRadixTreeBuilder (NFC) (#117014)
[llvm-project.git] / lld / test / COFF / guard-warnings.s
blob77448ee95c00957634f3a1708e2400820bb8b22d
1 # REQUIRES: x86
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
45 # NOWARN-NOT: warning
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
50 # CHECK: LoadConfig [
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)
62 # CHECK: ]
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
69 # CHECK: ]
70 # CHECK-NEXT: GuardFidTable [
71 # CHECK-NEXT: 0x14000{{([0-9A-F]{4})}}
72 # CHECK-NEXT: ]
73 # CHECK-NEXT: GuardIatTable [
74 # CHECK-NEXT: 0x14000{{([0-9A-F]{4})}}
75 # CHECK-NEXT: ]
76 # CHECK-NEXT: GuardLJmpTable [
77 # CHECK-NEXT: 0x14000{{([0-9A-F]{4})}}
78 # CHECK-NEXT: ]
79 # CHECK-NEXT: GuardEHContTable [
80 # CHECK-NEXT: 0x14000{{([0-9A-F]{4})}}
81 # CHECK-NEXT: ]
84 #--- main.s
86 # We need @feat.00 to have 0x4000 | 0x800 to indicate /guard:cf and /guard:ehcont.
87 .def @feat.00;
88 .scl 3;
89 .type 0;
90 .endef
91 .globl @feat.00
92 @feat.00 = 0x4800
93 .def main; .scl 2; .type 32; .endef
94 .globl main # -- Begin function main
95 .p2align 4, 0x90
96 main:
97 mov %eax, %eax
98 movq __imp_exportfn1(%rip), %rax
99 callq *%rax
101 # Fake setjmp target
102 $cfgsj_main0:
103 mov %ebx, %ebx
105 # Fake ehcont target
106 $ehgcr_0_1:
107 mov %ecx, %ecx
109 retq
110 # -- End function
111 .section .gfids$y,"dr"
112 .symidx main
113 .section .giats$y,"dr"
114 .symidx __imp_exportfn1
115 .section .gljmp$y,"dr"
116 .symidx $cfgsj_main0
117 .section .gehcont$y,"dr"
118 .symidx $ehgcr_0_1
119 .addrsig_sym main
120 .addrsig_sym __imp_exportfn1
121 .section .rdata,"dr"
123 #--- loadcfg-invalid.s
125 .globl _load_config_used
126 .p2align 3
127 _load_config_used:
128 .long 312
129 .fill 308, 1, 0
131 #--- loadcfg-small112.s
133 .globl _load_config_used
134 .p2align 3
135 _load_config_used:
136 .long 112
137 .fill 108, 1, 0
139 #--- loadcfg-small148.s
141 .globl _load_config_used
142 .p2align 3
143 _load_config_used:
144 .long 148
145 .fill 124, 1, 0
146 .quad __guard_fids_table
147 .quad __guard_fids_count
148 .long __guard_flags
150 #--- loadcfg-small244.s
152 .globl _load_config_used
153 .p2align 3
154 _load_config_used:
155 .long 244
156 .fill 124, 1, 0
157 .quad __guard_fids_table
158 .quad __guard_fids_count
159 .long __guard_flags
160 .fill 12, 1, 0
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
172 _load_config_used:
173 .long 312
174 .fill 124, 1, 0
175 .quad __guard_fids_table
176 .quad __guard_fids_count
177 .long __guard_flags
178 .fill 12, 1, 0
179 .quad __guard_iat_table
180 .quad __guard_iat_count
181 .quad __guard_longjmp_table
182 .quad __guard_longjmp_count
183 .fill 72, 1, 0
184 .quad __guard_eh_cont_table
185 .quad __guard_eh_cont_count
186 .fill 32, 1, 0
188 #--- loadcfg-misaligned2.s
190 .globl _load_config_used
191 .p2align 4 # align to 0x10
192 .fill 2, 1, 0 # then offset by 2
193 _load_config_used:
194 .long 312
195 .fill 124, 1, 0
196 .quad __guard_fids_table
197 .quad __guard_fids_count
198 .long __guard_flags
199 .fill 12, 1, 0
200 .quad __guard_iat_table
201 .quad __guard_iat_count
202 .quad __guard_longjmp_table
203 .quad __guard_longjmp_count
204 .fill 72, 1, 0
205 .quad __guard_eh_cont_table
206 .quad __guard_eh_cont_count
207 .fill 32, 1, 0
209 #--- loadcfg-full.s
211 .globl _load_config_used
212 .p2align 3
213 _load_config_used:
214 .long 312
215 .fill 124, 1, 0
216 .quad __guard_fids_table
217 .quad __guard_fids_count
218 .long __guard_flags
219 .fill 12, 1, 0
220 .quad __guard_iat_table
221 .quad __guard_iat_count
222 .quad __guard_longjmp_table
223 .quad __guard_longjmp_count
224 .fill 72, 1, 0
225 .quad __guard_eh_cont_table
226 .quad __guard_eh_cont_count
227 .fill 32, 1, 0