Skip to content

Commit ff7fa3a

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 1dadec1 commit ff7fa3a

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<
@@ -375,8 +378,11 @@ foreach FPTy = ["F32", "F64", "F128", "PPCF128"] in {
375378
// Memory
376379
def MEMCMP : RuntimeLibcall;
377380
def MEMCPY : RuntimeLibcall;
381+
def MEMCPY_CHK : RuntimeLibcall;
378382
def MEMMOVE : RuntimeLibcall;
383+
def MEMMOVE_CHK : RuntimeLibcall;
379384
def MEMSET : RuntimeLibcall;
385+
def MEMSET_CHK : RuntimeLibcall;
380386
def CALLOC : RuntimeLibcall;
381387
def BZERO : RuntimeLibcall;
382388
def STRLEN : RuntimeLibcall;
@@ -1092,6 +1098,10 @@ def memcpy : RuntimeLibcallImpl<MEMCPY>;
10921098
def memmove : RuntimeLibcallImpl<MEMMOVE>;
10931099
def memset : RuntimeLibcallImpl<MEMSET>;
10941100

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

@@ -2625,8 +2635,10 @@ defvar X86_F128_Libcalls = LibcallImpls<(add LibmF128Libcalls, LibmF128FiniteLib
26252635

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

2638+
defvar MemChkLibcalls = [__memcpy_chk, __memset_chk, __memmove_chk];
2639+
26282640
defvar X86CommonLibcalls =
2629-
(add (sub WinDefaultLibcallImpls, WindowsDivRemMulLibcallOverrides),
2641+
(add (sub WinDefaultLibcallImpls, WindowsDivRemMulLibcallOverrides, MemChkLibcalls),
26302642
DarwinSinCosStret, DarwinExp10,
26312643
X86_F128_Libcalls,
26322644
LibmHasSinCosF80, // FIXME: Depends on long double
@@ -2642,7 +2654,8 @@ defvar X86CommonLibcalls =
26422654
// FIXME: MSVCRT doesn't have powi. The f128 case is added as a
26432655
// hack for one test relying on it.
26442656
__powitf2_f128,
2645-
DefaultStackProtector
2657+
DefaultStackProtector,
2658+
LibcallImpls<(add MemChkLibcalls), isNotPS>
26462659
);
26472660

26482661
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)