lib: sbi: Fix compile errors using -Os option

When compiling with -Os option along with -ffreestanding, both GCC
and clang will add implicit calls to memcpy() and memset() for stack
variables initialized in declaration.

The C standard as per Clause 4, the compiler cannot necessarily
assume that anything beyond:

 * float.h
 * iso646.h
 * limits.h
 * stdalign.h
 * stdarg.h
 * stdbool.h
 * stddef.h
 * stdint.h
 * stdnoreturn.h
 * fenv.h
 * math.h
 * and the numeric conversion functions of stdlib.h.

This patch maps memcpy() and memset() as weak-alias of sbi_memcpy()
and sbi_memset() respectively so that implicit calls to memcpy()
and memset() will compile properly.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Dong Du <Dd_nirvana@sjtu.edu.cn>
Reviewed-by: Xiang W <wxjstz@126.com>
This commit is contained in:
Anup Patel
2021-12-02 16:52:16 +05:30
committed by Anup Patel
parent 69d7e53613
commit d249d6544c

View File

@@ -122,6 +122,9 @@ void *sbi_memset(void *s, int c, size_t count)
return s; return s;
} }
void *memset(void *s, int c, size_t count) \
__attribute__((weak, alias("sbi_memset")));
void *sbi_memcpy(void *dest, const void *src, size_t count) void *sbi_memcpy(void *dest, const void *src, size_t count)
{ {
char *temp1 = dest; char *temp1 = dest;
@@ -135,6 +138,9 @@ void *sbi_memcpy(void *dest, const void *src, size_t count)
return dest; return dest;
} }
void *memcpy(void *dest, const void *src, size_t count) \
__attribute__((weak, alias("sbi_memcpy")));
void *sbi_memmove(void *dest, const void *src, size_t count) void *sbi_memmove(void *dest, const void *src, size_t count)
{ {
char *temp1 = (char *)dest; char *temp1 = (char *)dest;