llvm.org GIT mirror llvm / ff8f891
Merging r328039: ------------------------------------------------------------------------ r328039 | mstorsjo | 2018-03-20 13:37:51 -0700 (Tue, 20 Mar 2018) | 8 lines [X86] Don't use the MSVC stack protector names on mingw Mingw uses the same stack protector functions as GCC provides on other platforms as well. Patch by Valentin Churavy! Differential Revision: https://reviews.llvm.org/D27296 ------------------------------------------------------------------------ git-svn-id: https://llvm.org/svn/llvm-project/llvm/branches/release_60@332001 91177308-0d34-0410-b5e6-96231b3b80d8 Tom Stellard 2 years ago
3 changed file(s) with 208 addition(s) and 4 deletion(s). Raw diff Collapse all Expand all
20642064
20652065 void X86TargetLowering::insertSSPDeclarations(Module &M) const {
20662066 // MSVC CRT provides functionalities for stack protection.
2067 if (Subtarget.getTargetTriple().isOSMSVCRT()) {
2067 if (Subtarget.getTargetTriple().isWindowsMSVCEnvironment() ||
2068 Subtarget.getTargetTriple().isWindowsItaniumEnvironment()) {
20682069 // MSVC CRT has a global variable holding security cookie.
20692070 M.getOrInsertGlobal("__security_cookie",
20702071 Type::getInt8PtrTy(M.getContext()));
20862087
20872088 Value *X86TargetLowering::getSDagStackGuard(const Module &M) const {
20882089 // MSVC CRT has a global variable holding security cookie.
2089 if (Subtarget.getTargetTriple().isOSMSVCRT())
2090 if (Subtarget.getTargetTriple().isWindowsMSVCEnvironment() ||
2091 Subtarget.getTargetTriple().isWindowsItaniumEnvironment()) {
20902092 return M.getGlobalVariable("__security_cookie");
2093 }
20912094 return TargetLowering::getSDagStackGuard(M);
20922095 }
20932096
20942097 Value *X86TargetLowering::getSSPStackGuardCheck(const Module &M) const {
20952098 // MSVC CRT has a function to validate security cookie.
2096 if (Subtarget.getTargetTriple().isOSMSVCRT())
2099 if (Subtarget.getTargetTriple().isWindowsMSVCEnvironment() ||
2100 Subtarget.getTargetTriple().isWindowsItaniumEnvironment()) {
20972101 return M.getFunction("__security_check_cookie");
2102 }
20982103 return TargetLowering::getSSPStackGuardCheck(M);
20992104 }
21002105
33 ; RUN: llc -mtriple=x86_64-apple-darwin < %s -o - | FileCheck --check-prefix=DARWIN-X64 %s
44 ; RUN: llc -mtriple=amd64-pc-openbsd < %s -o - | FileCheck --check-prefix=OPENBSD-AMD64 %s
55 ; RUN: llc -mtriple=i386-pc-windows-msvc < %s -o - | FileCheck -check-prefix=MSVC-I386 %s
6 ; RUN: llc -mtriple=x86_64-w64-mingw32 < %s -o - | FileCheck --check-prefix=MINGW-X64 %s
67
78 %struct.foo = type { [16 x i8] }
89 %struct.foo.0 = type { [4 x i8] }
4445 ; MSVC-I386-LABEL: test1a:
4546 ; MSVC-I386-NOT: calll @__security_check_cookie@4
4647 ; MSVC-I386: retl
48
49 ; MINGW-X64-LABEL: test1a:
50 ; MINGW-X64-NOT: callq __stack_chk_fail
51 ; MINGW-X64: .seh_endproc
52
4753 %a.addr = alloca i8*, align 8
4854 %buf = alloca [16 x i8], align 16
4955 store i8* %a, i8** %a.addr, align 8
8490 ; MSVC-I386-LABEL: test1b:
8591 ; MSVC-I386: movl ___security_cookie,
8692 ; MSVC-I386: calll @__security_check_cookie@4
93
94 ; MINGW-X64-LABEL: test1b:
95 ; MINGW-X64: mov{{l|q}} __stack_chk_guard
96 ; MINGW-X64: callq __stack_chk_fail
97
8798 %a.addr = alloca i8*, align 8
8899 %buf = alloca [16 x i8], align 16
89100 store i8* %a, i8** %a.addr, align 8
120131 ; MSVC-I386-LABEL: test1c:
121132 ; MSVC-I386: movl ___security_cookie,
122133 ; MSVC-I386: calll @__security_check_cookie@4
134
135 ; MINGW-X64-LABEL: test1c:
136 ; MINGW-X64: mov{{l|q}} __stack_chk_guard
137 ; MINGW-X64: callq __stack_chk_fail
138
123139 %a.addr = alloca i8*, align 8
124140 %buf = alloca [16 x i8], align 16
125141 store i8* %a, i8** %a.addr, align 8
156172 ; MSVC-I386-LABEL: test1d:
157173 ; MSVC-I386: movl ___security_cookie,
158174 ; MSVC-I386: calll @__security_check_cookie@4
175
176 ; MINGW-X64-LABEL: test1d:
177 ; MINGW-X64: mov{{l|q}} __stack_chk_guard
178 ; MINGW-X64: callq __stack_chk_fail
179
159180 %a.addr = alloca i8*, align 8
160181 %buf = alloca [16 x i8], align 16
161182 store i8* %a, i8** %a.addr, align 8
191212 ; MSVC-I386-LABEL: test2a:
192213 ; MSVC-I386-NOT: calll @__security_check_cookie@4
193214 ; MSVC-I386: retl
215
216 ; MINGW-X64-LABEL: test2a:
217 ; MINGW-X64-NOT: callq __stack_chk_fail
218 ; MINGW-X64: .seh_endproc
219
194220 %a.addr = alloca i8*, align 8
195221 %b = alloca %struct.foo, align 1
196222 store i8* %a, i8** %a.addr, align 8
225251 ; DARWIN-X64-LABEL: test2b:
226252 ; DARWIN-X64: mov{{l|q}} ___stack_chk_guard
227253 ; DARWIN-X64: callq ___stack_chk_fail
254
255 ; MINGW-X64-LABEL: test2b:
256 ; MINGW-X64: mov{{l|q}} __stack_chk_guard
257 ; MINGW-X64: callq __stack_chk_fail
258
228259 %a.addr = alloca i8*, align 8
229260 %b = alloca %struct.foo, align 1
230261 store i8* %a, i8** %a.addr, align 8
263294 ; MSVC-I386-LABEL: test2c:
264295 ; MSVC-I386: movl ___security_cookie,
265296 ; MSVC-I386: calll @__security_check_cookie@4
297
298 ; MINGW-X64-LABEL: test2c:
299 ; MINGW-X64: mov{{l|q}} __stack_chk_guard
300 ; MINGW-X64: callq __stack_chk_fail
301
266302 %a.addr = alloca i8*, align 8
267303 %b = alloca %struct.foo, align 1
268304 store i8* %a, i8** %a.addr, align 8
301337 ; MSVC-I386-LABEL: test2d:
302338 ; MSVC-I386: movl ___security_cookie,
303339 ; MSVC-I386: calll @__security_check_cookie@4
340
341 ; MINGW-X64-LABEL: test2d:
342 ; MINGW-X64: mov{{l|q}} __stack_chk_guard
343 ; MINGW-X64: callq __stack_chk_fail
344
304345 %a.addr = alloca i8*, align 8
305346 %b = alloca %struct.foo, align 1
306347 store i8* %a, i8** %a.addr, align 8
338379 ; MSVC-I386-LABEL: test3a:
339380 ; MSVC-I386-NOT: calll @__security_check_cookie@4
340381 ; MSVC-I386: retl
382
383 ; MINGW-X64-LABEL: test3a:
384 ; MINGW-X64-NOT: callq __stack_chk_fail
385 ; MINGW-X64: .seh_endproc
386
341387 %a.addr = alloca i8*, align 8
342388 %buf = alloca [4 x i8], align 1
343389 store i8* %a, i8** %a.addr, align 8
374420 ; MSVC-I386-LABEL: test3b:
375421 ; MSVC-I386-NOT: calll @__security_check_cookie@4
376422 ; MSVC-I386: retl
423
424 ; MINGW-X64-LABEL: test3b:
425 ; MINGW-X64-NOT: callq __stack_chk_fail
426 ; MINGW-X64: .seh_endproc
427
377428 %a.addr = alloca i8*, align 8
378429 %buf = alloca [4 x i8], align 1
379430 store i8* %a, i8** %a.addr, align 8
410461 ; MSVC-I386-LABEL: test3c:
411462 ; MSVC-I386: movl ___security_cookie,
412463 ; MSVC-I386: calll @__security_check_cookie@4
464
465 ; MINGW-X64-LABEL: test3c:
466 ; MINGW-X64: mov{{l|q}} __stack_chk_guard
467 ; MINGW-X64: callq __stack_chk_fail
468
413469 %a.addr = alloca i8*, align 8
414470 %buf = alloca [4 x i8], align 1
415471 store i8* %a, i8** %a.addr, align 8
446502 ; MSVC-I386-LABEL: test3d:
447503 ; MSVC-I386: movl ___security_cookie,
448504 ; MSVC-I386: calll @__security_check_cookie@4
505
506 ; MINGW-X64-LABEL: test3d:
507 ; MINGW-X64: mov{{l|q}} __stack_chk_guard
508 ; MINGW-X64: callq __stack_chk_fail
509
449510 %a.addr = alloca i8*, align 8
450511 %buf = alloca [4 x i8], align 1
451512 store i8* %a, i8** %a.addr, align 8
481542 ; MSVC-I386-LABEL: test4a:
482543 ; MSVC-I386-NOT: calll @__security_check_cookie@4
483544 ; MSVC-I386: retl
545
546 ; MINGW-X64-LABEL: test4a:
547 ; MINGW-X64-NOT: callq __stack_chk_fail
548 ; MINGW-X64: .seh_endproc
549
484550 %a.addr = alloca i8*, align 8
485551 %b = alloca %struct.foo.0, align 1
486552 store i8* %a, i8** %a.addr, align 8
519585 ; MSVC-I386-LABEL: test4b:
520586 ; MSVC-I386-NOT: calll @__security_check_cookie@4
521587 ; MSVC-I386: retl
588
589 ; MINGW-X64-LABEL: test4b:
590 ; MINGW-X64-NOT: callq __stack_chk_fail
591 ; MINGW-X64: .seh_endproc
592
522593 %a.addr = alloca i8*, align 8
523594 %b = alloca %struct.foo.0, align 1
524595 store i8* %a, i8** %a.addr, align 8
557628 ; MSVC-I386-LABEL: test4c:
558629 ; MSVC-I386: movl ___security_cookie,
559630 ; MSVC-I386: calll @__security_check_cookie@4
631
632 ; MINGW-X64-LABEL: test4c:
633 ; MINGW-X64: mov{{l|q}} __stack_chk_guard
634 ; MINGW-X64: callq __stack_chk_fail
635
560636 %a.addr = alloca i8*, align 8
561637 %b = alloca %struct.foo.0, align 1
562638 store i8* %a, i8** %a.addr, align 8
595671 ; MSVC-I386-LABEL: test4d:
596672 ; MSVC-I386: movl ___security_cookie,
597673 ; MSVC-I386: calll @__security_check_cookie@4
674
675 ; MINGW-X64-LABEL: test4d:
676 ; MINGW-X64: mov{{l|q}} __stack_chk_guard
677 ; MINGW-X64: callq __stack_chk_fail
678
598679 %a.addr = alloca i8*, align 8
599680 %b = alloca %struct.foo.0, align 1
600681 store i8* %a, i8** %a.addr, align 8
632713 ; MSVC-I386-LABEL: test5a:
633714 ; MSVC-I386-NOT: calll @__security_check_cookie@4
634715 ; MSVC-I386: retl
716
717 ; MINGW-X64-LABEL: test5a:
718 ; MINGW-X64-NOT: callq __stack_chk_fail
719 ; MINGW-X64: .seh_endproc
720
635721 %a.addr = alloca i8*, align 8
636722 store i8* %a, i8** %a.addr, align 8
637723 %0 = load i8*, i8** %a.addr, align 8
664750 ; MSVC-I386-LABEL: test5b:
665751 ; MSVC-I386-NOT: calll @__security_check_cookie@4
666752 ; MSVC-I386: retl
753
754 ; MINGW-X64-LABEL: test5b:
755 ; MINGW-X64-NOT: callq __stack_chk_fail
756 ; MINGW-X64: .seh_endproc
757
667758 %a.addr = alloca i8*, align 8
668759 store i8* %a, i8** %a.addr, align 8
669760 %0 = load i8*, i8** %a.addr, align 8
696787 ; MSVC-I386-LABEL: test5c:
697788 ; MSVC-I386-NOT: calll @__security_check_cookie@4
698789 ; MSVC-I386: retl
790
791 ; MINGW-X64-LABEL: test5c:
792 ; MINGW-X64-NOT: callq __stack_chk_fail
793 ; MINGW-X64: .seh_endproc
794
699795 %a.addr = alloca i8*, align 8
700796 store i8* %a, i8** %a.addr, align 8
701797 %0 = load i8*, i8** %a.addr, align 8
728824 ; MSVC-I386-LABEL: test5d:
729825 ; MSVC-I386: movl ___security_cookie,
730826 ; MSVC-I386: calll @__security_check_cookie@4
827
828 ; MINGW-X64-LABEL: test5d:
829 ; MINGW-X64: mov{{l|q}} __stack_chk_guard
830 ; MINGW-X64: callq __stack_chk_fail
831
731832 %a.addr = alloca i8*, align 8
732833 store i8* %a, i8** %a.addr, align 8
733834 %0 = load i8*, i8** %a.addr, align 8
759860 ; MSVC-I386-LABEL: test6a:
760861 ; MSVC-I386-NOT: calll @__security_check_cookie@4
761862 ; MSVC-I386: retl
863
864 ; MINGW-X64-LABEL: test6a:
865 ; MINGW-X64-NOT: callq __stack_chk_fail
866 ; MINGW-X64: .seh_endproc
867
762868 %retval = alloca i32, align 4
763869 %a = alloca i32, align 4
764870 %j = alloca i32*, align 8
792898 ; DARWIN-X64-NOT: callq ___stack_chk_fail
793899 ; DARWIN-X64: .cfi_endproc
794900
795
796901 ; MSVC-I386-LABEL: test6b:
797902 ; MSVC-I386-NOT: calll @__security_check_cookie@4
798903 ; MSVC-I386: retl
904
905 ; MINGW-X64-LABEL: test6b:
906 ; MINGW-X64-NOT: callq __stack_chk_fail
907 ; MINGW-X64: .seh_endproc
908
799909 %retval = alloca i32, align 4
800910 %a = alloca i32, align 4
801911 %j = alloca i32*, align 8
832942 ; MSVC-I386-LABEL: test6c:
833943 ; MSVC-I386: movl ___security_cookie,
834944 ; MSVC-I386: calll @__security_check_cookie@4
945
946 ; MINGW-X64-LABEL: test6c:
947 ; MINGW-X64: mov{{l|q}} __stack_chk_guard
948 ; MINGW-X64: callq __stack_chk_fail
949
835950 %retval = alloca i32, align 4
836951 %a = alloca i32, align 4
837952 %j = alloca i32*, align 8
868983 ; MSVC-I386-LABEL: test6d:
869984 ; MSVC-I386: movl ___security_cookie,
870985 ; MSVC-I386: calll @__security_check_cookie@4
986
987 ; MINGW-X64-LABEL: test6d:
988 ; MINGW-X64: mov{{l|q}} __stack_chk_guard
989 ; MINGW-X64: callq __stack_chk_fail
990
871991 %retval = alloca i32, align 4
872992 %a = alloca i32, align 4
873993 %j = alloca i32*, align 8
9031023 ; MSVC-I386-LABEL: test7a:
9041024 ; MSVC-I386-NOT: calll @__security_check_cookie@4
9051025 ; MSVC-I386: retl
1026
1027 ; MINGW-X64-LABEL: test7a:
1028 ; MINGW-X64-NOT: callq __stack_chk_fail
1029 ; MINGW-X64: .seh_endproc
1030
9061031 %a = alloca i32, align 4
9071032 %0 = ptrtoint i32* %a to i64
9081033 %call = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i32 0, i32 0), i64 %0)
9341059 ; MSVC-I386-LABEL: test7b:
9351060 ; MSVC-I386-NOT: calll @__security_check_cookie@4
9361061 ; MSVC-I386: retl
1062
1063 ; MINGW-X64-LABEL: test7b:
1064 ; MINGW-X64-NOT: callq __stack_chk_fail
1065 ; MINGW-X64: .seh_endproc
1066
9371067 %a = alloca i32, align 4
9381068 %0 = ptrtoint i32* %a to i64
9391069 %call = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i32 0, i32 0), i64 %0)
9651095 ; MSVC-I386-LABEL: test7c:
9661096 ; MSVC-I386: movl ___security_cookie,
9671097 ; MSVC-I386: calll @__security_check_cookie@4
1098
1099 ; MINGW-X64-LABEL: test7c:
1100 ; MINGW-X64: mov{{l|q}} __stack_chk_guard
1101 ; MINGW-X64: .seh_endproc
1102
9681103 %a = alloca i32, align 4
9691104 %0 = ptrtoint i32* %a to i64
9701105 %call = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i32 0, i32 0), i64 %0)
9961131 ; MSVC-I386-LABEL: test7d:
9971132 ; MSVC-I386: movl ___security_cookie,
9981133 ; MSVC-I386: calll @__security_check_cookie@4
1134
1135 ; MINGW-X64-LABEL: test7d:
1136 ; MINGW-X64: mov{{l|q}} __stack_chk_guard
1137 ; MINGW-X64: callq __stack_chk_fail
1138
9991139 %a = alloca i32, align 4
10001140 %0 = ptrtoint i32* %a to i64
10011141 %call = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i32 0, i32 0), i64 %0)
10261166 ; MSVC-I386-LABEL: test8a:
10271167 ; MSVC-I386-NOT: calll @__security_check_cookie@4
10281168 ; MSVC-I386: retl
1169
1170 ; MINGW-X64-LABEL: test8a:
1171 ; MINGW-X64-NOT: callq __stack_chk_fail
1172 ; MINGW-X64: .seh_endproc
1173
10291174 %b = alloca i32, align 4
10301175 call void @funcall(i32* %b)
10311176 ret void
10561201 ; MSVC-I386-LABEL: test8b:
10571202 ; MSVC-I386-NOT: calll @__security_check_cookie@4
10581203 ; MSVC-I386: retl
1204
1205 ; MINGW-X64-LABEL: test8b:
1206 ; MINGW-X64-NOT: callq __stack_chk_fail
1207 ; MINGW-X64: .seh_endproc
1208
10591209 %b = alloca i32, align 4
10601210 call void @funcall(i32* %b)
10611211 ret void
10861236 ; MSVC-I386-LABEL: test8c:
10871237 ; MSVC-I386: movl ___security_cookie,
10881238 ; MSVC-I386: calll @__security_check_cookie@4
1239
1240 ; MINGW-X64-LABEL: test8c:
1241 ; MINGW-X64: mov{{l|q}} __stack_chk_guard
1242 ; MINGW-X64: callq __stack_chk_fail
1243
10891244 %b = alloca i32, align 4
10901245 call void @funcall(i32* %b)
10911246 ret void
11161271 ; MSVC-I386-LABEL: test8d:
11171272 ; MSVC-I386: movl ___security_cookie,
11181273 ; MSVC-I386: calll @__security_check_cookie@4
1274
1275 ; MINGW-X64-LABEL: test8d:
1276 ; MINGW-X64: mov{{l|q}} __stack_chk_guard
1277 ; MINGW-X64: callq __stack_chk_fail
1278
11191279 %b = alloca i32, align 4
11201280 call void @funcall(i32* %b)
11211281 ret void
26862846 ; MSVC-I386-LABEL: test19d:
26872847 ; MSVC-I386: movl ___security_cookie,
26882848 ; MSVC-I386: calll @__security_check_cookie@4
2849
2850 ; MINGW-X64-LABEL: test19d:
2851 ; MINGW-X64: mov{{l|q}} __stack_chk_guard
2852 ; MINGW-X64: callq __stack_chk_fail
2853
26892854 %c = alloca %struct.pair, align 4
26902855 %exn.slot = alloca i8*
26912856 %ehselector.slot = alloca i32
34543619 ; MSVC-I386-LABEL: test25b:
34553620 ; MSVC-I386-NOT: calll @__security_check_cookie@4
34563621 ; MSVC-I386: retl
3622
3623 ; MINGW-X64-LABEL: test25b:
3624 ; MINGW-X64-NOT: callq __stack_chk_fail
3625 ; MINGW-X64: .seh_endproc
3626
34573627 %a = alloca [4 x i32], align 16
34583628 %arrayidx = getelementptr inbounds [4 x i32], [4 x i32]* %a, i32 0, i64 0
34593629 %0 = load i32, i32* %arrayidx, align 4
0 ; RUN: llc -mtriple=x86_64-w64-mingw32 < %s -o - | FileCheck --check-prefix=MINGW %s
1 ; RUN: llc -mtriple=x86_64-pc-windows-itanium < %s -o - | FileCheck --check-prefix=MSVC %s
2 ; RUN: llc -mtriple=x86_64-pc-windows-msvc < %s -o - | FileCheck --check-prefix=MSVC %s
3
4 declare void @llvm.lifetime.start.p0i8(i64, i8* nocapture)
5 declare dso_local void @other(i8*)
6 declare void @llvm.lifetime.end.p0i8(i64, i8* nocapture)
7
8 define dso_local void @func() sspstrong {
9 entry:
10 ; MINGW-LABEL: func:
11 ; MINGW: mov{{l|q}} __stack_chk_guard
12 ; MINGW: callq other
13 ; MINGW: mov{{l|q}} __stack_chk_guard
14 ; MINGW: callq __stack_chk_fail
15 ; MINGW: .seh_endproc
16
17 ; MSVC-LABEL: func:
18 ; MSVC: mov{{l|q}} __security_cookie
19 ; MSVC: callq other
20 ; MSVC: callq __security_check_cookie
21 ; MSVC: .seh_endproc
22
23 %c = alloca i8, align 1
24 call void @llvm.lifetime.start.p0i8(i64 1, i8* nonnull %c)
25 call void @other(i8* nonnull %c)
26 call void @llvm.lifetime.end.p0i8(i64 1, i8* nonnull %c)
27 ret void
28 }