Skip to content

Commit 31b8490

Browse files
committed
RuntimeLibcalls: Add __memcpy_chk, __memmove_chk, __memset_chk
These were in TargetLibraryInfo, but missing from RuntimeLibcalls. This only adds the cases that already have the non-chk variants already. Copies the enabled-by-default logic from TargetLibraryInfo, which is probably overly permissive. Only isPS opts-out.
1 parent 8ddc3c6 commit 31b8490

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

llvm/include/llvm/IR/RuntimeLibcalls.td

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ def isNotOSLinuxAndNotOSOpenBSD : RuntimeLibcallPredicate<
3535
def isNotOSAIXAndNotOSOpenBSD : RuntimeLibcallPredicate<
3636
[{!TT.isOSAIX() && !TT.isOSOpenBSD()}]>;
3737

38+
def isNotPS : RuntimeLibcallPredicate<
39+
[{!TT.isPS()}]>;
40+
3841
// OpenBSD uses __guard_local. AIX uses __ssp_canary_word, MSVC/Windows
3942
// Itanium uses __security_cookie
4043
def hasStackChkFail : RuntimeLibcallPredicate<
@@ -374,8 +377,11 @@ foreach FPTy = ["F32", "F64", "F128", "PPCF128"] in {
374377
// Memory
375378
def MEMCMP : RuntimeLibcall;
376379
def MEMCPY : RuntimeLibcall;
380+
def MEMCPY_CHK : RuntimeLibcall;
377381
def MEMMOVE : RuntimeLibcall;
382+
def MEMMOVE_CHK : RuntimeLibcall;
378383
def MEMSET : RuntimeLibcall;
384+
def MEMSET_CHK : RuntimeLibcall;
379385
def CALLOC : RuntimeLibcall;
380386
def BZERO : RuntimeLibcall;
381387
def STRLEN : RuntimeLibcall;
@@ -1091,6 +1097,10 @@ def memcpy : RuntimeLibcallImpl<MEMCPY>;
10911097
def memmove : RuntimeLibcallImpl<MEMMOVE>;
10921098
def memset : RuntimeLibcallImpl<MEMSET>;
10931099

1100+
def __memcpy_chk : RuntimeLibcallImpl<MEMCPY_CHK>;
1101+
def __memmove_chk : RuntimeLibcallImpl<MEMMOVE_CHK>;
1102+
def __memset_chk : RuntimeLibcallImpl<MEMSET_CHK>;
1103+
10941104
// DSEPass can emit calloc if it finds a pair of malloc/memset
10951105
def calloc : RuntimeLibcallImpl<CALLOC>;
10961106

@@ -2624,8 +2634,10 @@ defvar X86_F128_Libcalls = LibcallImpls<(add LibmF128Libcalls, LibmF128FiniteLib
26242634

26252635
defvar SinCosF32F64Libcalls = LibcallImpls<(add sincosf, sincos), hasSinCos_f32_f64>;
26262636

2637+
defvar MemChkLibcalls = [__memcpy_chk, __memset_chk, __memmove_chk];
2638+
26272639
defvar X86CommonLibcalls =
2628-
(add (sub WinDefaultLibcallImpls, WindowsDivRemMulLibcallOverrides),
2640+
(add (sub WinDefaultLibcallImpls, WindowsDivRemMulLibcallOverrides, MemChkLibcalls),
26292641
DarwinSinCosStret, DarwinExp10,
26302642
X86_F128_Libcalls,
26312643
LibmHasSinCosF80, // FIXME: Depends on long double
@@ -2641,7 +2653,8 @@ defvar X86CommonLibcalls =
26412653
// FIXME: MSVCRT doesn't have powi. The f128 case is added as a
26422654
// hack for one test relying on it.
26432655
__powitf2_f128,
2644-
DefaultStackProtector
2656+
DefaultStackProtector,
2657+
LibcallImpls<(add MemChkLibcalls), isNotPS>
26452658
);
26462659

26472660
defvar Windows32DivRemMulCalls =

llvm/test/Transforms/Util/DeclareRuntimeLibcalls/basic.ll

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ define float @sinf(float %x) {
1212

1313
; CHECK: declare void @_Unwind_Resume(...)
1414

15+
; CHECK: declare void @__memcpy_chk(...)
16+
; CHECK: declare void @__memmove_chk(...)
17+
; CHECK: declare void @__memset_chk(...)
18+
1519
; CHECK: declare void @__umodti3(...)
1620

1721
; CHECK: declare void @acosf(...)
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
; RUN: opt -S -passes=declare-runtime-libcalls -mtriple=x86_64-scei-ps4 < %s | FileCheck %s
2+
; RUN: opt -S -passes=declare-runtime-libcalls -mtriple=x86_64-scei-ps5 < %s | FileCheck %s
3+
4+
; CHECK-NOT: __memcpy_chk
5+
; CHECK-NOT: __memset_chk
6+
; CHECK-NOT: __memmove_chk

0 commit comments

Comments
 (0)