Add fortified (__*_chk) library functions to TLI (NFC)

One of them (__memcpy_chk) was already there, the others were checked
by comparing function names.
Note that the fortified libfuncs are now part of TLI, but are always
available, because they aren't generated, only optimized into the
non-checking versions.

Differential Revision: http://reviews.llvm.org/D6179

llvm-svn: 221817
This commit is contained in:
Ahmed Bougacha 2014-11-12 21:23:34 +00:00
parent 38af8561f9
commit 55a333d89b
3 changed files with 32 additions and 19 deletions

View File

@ -73,6 +73,11 @@ namespace llvm {
dunder_isoc99_sscanf,
/// void *__memcpy_chk(void *s1, const void *s2, size_t n, size_t s1size);
memcpy_chk,
/// void *__memmove_chk(void *s1, const void *s2, size_t n,
/// size_t s1size);
memmove_chk,
/// void *__memset_chk(void *s, char v, size_t n, size_t s1size);
memset_chk,
/// double __sincospi_stret(double x);
sincospi_stret,
/// float __sincospif_stret(float x);
@ -87,8 +92,18 @@ namespace llvm {
sqrtf_finite,
/// long double __sqrt_finite(long double x);
sqrtl_finite,
/// char *__stpcpy_chk(char *s1, const char *s2, size_t s1size);
stpcpy_chk,
/// char *__stpncpy_chk(char *s1, const char *s2, size_t n,
/// size_t s1size);
stpncpy_chk,
/// char *__strcpy_chk(char *s1, const char *s2, size_t s1size);
strcpy_chk,
/// char * __strdup(const char *s);
dunder_strdup,
/// char *__strncpy_chk(char *s1, const char *s2, size_t n,
/// size_t s1size);
strncpy_chk,
/// char *__strndup(const char *s, size_t n);
dunder_strndup,
/// char * __strtok_r(char *s, const char *delim, char **save_ptr);

View File

@ -51,6 +51,8 @@ const char* TargetLibraryInfo::StandardNames[LibFunc::NumLibFuncs] =
"__isoc99_scanf",
"__isoc99_sscanf",
"__memcpy_chk",
"__memmove_chk",
"__memset_chk",
"__sincospi_stret",
"__sincospif_stret",
"__sinpi",
@ -58,7 +60,11 @@ const char* TargetLibraryInfo::StandardNames[LibFunc::NumLibFuncs] =
"__sqrt_finite",
"__sqrtf_finite",
"__sqrtl_finite",
"__stpcpy_chk",
"__stpncpy_chk",
"__strcpy_chk",
"__strdup",
"__strncpy_chk",
"__strndup",
"__strtok_r",
"abs",

View File

@ -2184,30 +2184,22 @@ Value *LibCallSimplifier::optimizeCall(CallInst *CI) {
return nullptr;
case LibFunc::memcpy_chk:
return optimizeMemCpyChk(CI, Builder);
case LibFunc::memmove_chk:
return optimizeMemMoveChk(CI, Builder);
case LibFunc::memset_chk:
return optimizeMemSetChk(CI, Builder);
case LibFunc::strcpy_chk:
return optimizeStrCpyChk(CI, Builder);
case LibFunc::stpcpy_chk:
return optimizeStpCpyChk(CI, Builder);
case LibFunc::stpncpy_chk:
case LibFunc::strncpy_chk:
return optimizeStrNCpyChk(CI, Builder);
default:
return nullptr;
}
}
if (!isCallingConvC)
return nullptr;
// Finally check for fortified library calls.
if (FuncName.endswith("_chk")) {
if (FuncName == "__memmove_chk")
return optimizeMemMoveChk(CI, Builder);
else if (FuncName == "__memset_chk")
return optimizeMemSetChk(CI, Builder);
else if (FuncName == "__strcpy_chk")
return optimizeStrCpyChk(CI, Builder);
else if (FuncName == "__stpcpy_chk")
return optimizeStpCpyChk(CI, Builder);
else if (FuncName == "__strncpy_chk")
return optimizeStrNCpyChk(CI, Builder);
else if (FuncName == "__stpncpy_chk")
return optimizeStrNCpyChk(CI, Builder);
}
return nullptr;
}