Skip to content

Commit 6c5770d

Browse files
authored
RuntimeLibcalls: Avoid reporting __stack_chk_guard as available for msvc (#164133)
The predicate system is currently primitive and alternative call predicates should be mutually exclusive.
1 parent f5a2e6b commit 6c5770d

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

llvm/include/llvm/IR/RuntimeLibcalls.td

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,15 @@ def isWindowsMSVCEnvironment : RuntimeLibcallPredicate<
3232
def isNotOSLinuxAndNotOSOpenBSD : RuntimeLibcallPredicate<
3333
[{!TT.isOSLinux() && !TT.isOSOpenBSD()}]>;
3434

35+
def isNotOSAIXAndNotOSOpenBSD : RuntimeLibcallPredicate<
36+
[{!TT.isOSAIX() && !TT.isOSOpenBSD()}]>;
37+
38+
// OpenBSD uses __guard_local. AIX uses __ssp_canary_word, MSVC/Windows
39+
// Itanium uses __security_cookie
40+
def hasStackChkFail : RuntimeLibcallPredicate<
41+
[{ !TT.isOSOpenBSD() && !TT.isWindowsMSVCEnvironment() &&
42+
!TT.isWindowsItaniumEnvironment()}]>;
43+
3544
def isWindowsMSVCOrItaniumEnvironment : RuntimeLibcallPredicate<
3645
[{TT.isWindowsMSVCEnvironment() || TT.isWindowsItaniumEnvironment()}]>;
3746

@@ -1241,9 +1250,9 @@ defvar LibmHasLdexpF80 = LibcallImpls<(add ldexpl_f80), isNotOSWindowsOrIsCygwin
12411250
defvar LibmHasFrexpF128 = LibcallImpls<(add frexpl_f128), isNotOSWindowsOrIsCygwinMinGW>;
12421251
defvar LibmHasLdexpF128 = LibcallImpls<(add ldexpl_f128), isNotOSWindowsOrIsCygwinMinGW>;
12431252

1244-
defvar has__stack_chk_fail = LibcallImpls<(add __stack_chk_fail), isNotOSOpenBSD>;
1253+
defvar has__stack_chk_fail = LibcallImpls<(add __stack_chk_fail), hasStackChkFail>;
12451254
defvar has__stack_chk_guard =
1246-
LibcallImpls<(add __stack_chk_guard), isNotOSOpenBSD>;
1255+
LibcallImpls<(add __stack_chk_guard), hasStackChkFail>;
12471256
defvar has__stack_smash_handler = LibcallImpls<(add __stack_smash_handler), isOSOpenBSD>;
12481257
defvar has___guard_local = LibcallImpls<(add __guard_local), isOSOpenBSD>;
12491258

@@ -1396,8 +1405,8 @@ defvar ExceptionModelCallsArm64EC = (add
13961405
def WindowsARM64ECSystemLibrary
13971406
: SystemRuntimeLibrary<isWindowsArm64EC,
13981407
(add WinArm64ECDefaultRuntimeLibcallImpls,
1399-
arm64ec___stack_chk_fail,
1400-
__stack_chk_guard,
1408+
AvailableIf<arm64ec___stack_chk_fail, hasStackChkFail>,
1409+
AvailableIf<__stack_chk_guard, hasStackChkFail>,
14011410
LibcallImpls<(add __security_check_cookie_arm64ec,
14021411
__security_cookie),
14031412
isWindowsMSVCEnvironment>,
@@ -2318,11 +2327,11 @@ def PPCSystemLibrary
23182327
LibmHasSinCosPPCF128,
23192328
AvailableIf<memcpy, isNotAIX>,
23202329
LibcallImpls<(add Int128RTLibcalls), isPPC64>,
2321-
has__stack_chk_fail,
23222330
has__stack_smash_handler,
23232331
has___guard_local,
23242332
AvailableIf<__ssp_canary_word, isAIX>,
2325-
AvailableIf<__stack_chk_guard, isNotAIX>)>;
2333+
AvailableIf<__stack_chk_fail, isNotOSOpenBSD>,
2334+
AvailableIf<__stack_chk_guard, isNotOSAIXAndNotOSOpenBSD>)>;
23262335

23272336
//===----------------------------------------------------------------------===//
23282337
// RISCV Runtime Libcalls

0 commit comments

Comments
 (0)