libc: Avoid the compiler generate code call self(memcpy/memmove/memset/memcmp) recursively

please reference the similar change done by other libc implementation:
https://reviews.llvm.org/D68028?id=224286
https://github.com/bminor/glibc/commit/85c2e6110c9a01ec817c30f1b7e20549d7229987
https://github.com/bminor/musl/commit/4a1f55e92fa74ee382909baa96302231f566b5e1
https://github.com/bminor/newlib/commit/82dfae9ab0734b9946321590162dc6021057fec1

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
This commit is contained in:
Xiang Xiao
2022-04-04 03:19:30 +08:00
committed by Petro Karashchenko
parent 34e17ba0ce
commit ae6bfdc9b9
6 changed files with 20 additions and 1 deletions
+14
View File
@@ -381,6 +381,12 @@
# define UNUSED(a) ((void)(1 || (a))) # define UNUSED(a) ((void)(1 || (a)))
# if defined(__clang__)
# define no_builtin(n) __attribute__((no_builtin(n)))
# else
# define no_builtin(n) __attribute__((__optimize__("-fno-tree-loop-distribute-patterns")))
#endif
/* SDCC-specific definitions ************************************************/ /* SDCC-specific definitions ************************************************/
#elif defined(SDCC) || defined(__SDCC) #elif defined(SDCC) || defined(__SDCC)
@@ -537,6 +543,8 @@
# define offsetof(a, b) ((size_t)(&(((a *)(0))->b))) # define offsetof(a, b) ((size_t)(&(((a *)(0))->b)))
# define no_builtin(n)
/* Zilog-specific definitions ***********************************************/ /* Zilog-specific definitions ***********************************************/
#elif defined(__ZILOG__) #elif defined(__ZILOG__)
@@ -677,6 +685,8 @@
# define offsetof(a, b) ((size_t)(&(((a *)(0))->b))) # define offsetof(a, b) ((size_t)(&(((a *)(0))->b)))
# define no_builtin(n)
/* ICCARM-specific definitions **********************************************/ /* ICCARM-specific definitions **********************************************/
#elif defined(__ICCARM__) #elif defined(__ICCARM__)
@@ -746,6 +756,8 @@
# define offsetof(a, b) ((size_t)(&(((a *)(0))->b))) # define offsetof(a, b) ((size_t)(&(((a *)(0))->b)))
# define no_builtin(n)
/* Unknown compiler *********************************************************/ /* Unknown compiler *********************************************************/
#else #else
@@ -803,6 +815,8 @@
# define offsetof(a, b) ((size_t)(&(((a *)(0))->b))) # define offsetof(a, b) ((size_t)(&(((a *)(0))->b)))
# define no_builtin(n)
#endif #endif
/**************************************************************************** /****************************************************************************
+1
View File
@@ -32,6 +32,7 @@
#ifndef CONFIG_LIBC_ARCH_MEMCMP #ifndef CONFIG_LIBC_ARCH_MEMCMP
#undef memcmp /* See mm/README.txt */ #undef memcmp /* See mm/README.txt */
no_builtin("memcmp")
int memcmp(FAR const void *s1, FAR const void *s2, size_t n) int memcmp(FAR const void *s1, FAR const void *s2, size_t n)
{ {
unsigned char *p1 = (unsigned char *)s1; unsigned char *p1 = (unsigned char *)s1;
+1
View File
@@ -36,6 +36,7 @@
#ifndef CONFIG_LIBC_ARCH_MEMCPY #ifndef CONFIG_LIBC_ARCH_MEMCPY
#undef memcpy /* See mm/README.txt */ #undef memcpy /* See mm/README.txt */
no_builtin("memcpy")
FAR void *memcpy(FAR void *dest, FAR const void *src, size_t n) FAR void *memcpy(FAR void *dest, FAR const void *src, size_t n)
{ {
FAR unsigned char *pout = (FAR unsigned char *)dest; FAR unsigned char *pout = (FAR unsigned char *)dest;
+1
View File
@@ -32,6 +32,7 @@
#ifndef CONFIG_LIBC_ARCH_MEMMOVE #ifndef CONFIG_LIBC_ARCH_MEMMOVE
#undef memmove /* See mm/README.txt */ #undef memmove /* See mm/README.txt */
no_builtin("memmove")
FAR void *memmove(FAR void *dest, FAR const void *src, size_t count) FAR void *memmove(FAR void *dest, FAR const void *src, size_t count)
{ {
FAR char *tmp; FAR char *tmp;
+1
View File
@@ -48,6 +48,7 @@
#ifndef CONFIG_LIBC_ARCH_MEMSET #ifndef CONFIG_LIBC_ARCH_MEMSET
#undef memset /* See mm/README.txt */ #undef memset /* See mm/README.txt */
no_builtin("memset")
FAR void *memset(FAR void *s, int c, size_t n) FAR void *memset(FAR void *s, int c, size_t n)
{ {
#ifdef CONFIG_MEMSET_OPTSPEED #ifdef CONFIG_MEMSET_OPTSPEED
+1
View File
@@ -305,6 +305,7 @@ typedef uint32_t uintn;
* *
****************************************************************************/ ****************************************************************************/
no_builtin("memcpy")
FAR void *memcpy(FAR void *dest, FAR const void *src, size_t count) FAR void *memcpy(FAR void *dest, FAR const void *src, size_t count)
{ {
FAR uint8_t *dst8 = (FAR uint8_t *)dest; FAR uint8_t *dst8 = (FAR uint8_t *)dest;