summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnup Patel <anup.patel@wdc.com>2021-12-02 14:22:16 +0300
committerAnup Patel <anup@brainfault.org>2021-12-11 15:07:29 +0300
commitd249d6544c3cbf6a817e2fac40b4be0e006ba965 (patch)
treec2923c89439daf4f3ddbde8a308ed857d036b499
parent69d7e536138ae71a24028ca849d401a4d64d564b (diff)
downloadopensbi-d249d6544c3cbf6a817e2fac40b4be0e006ba965.tar.xz
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>
-rw-r--r--lib/sbi/sbi_string.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/lib/sbi/sbi_string.c b/lib/sbi/sbi_string.c
index c87bce9..c67c02e 100644
--- a/lib/sbi/sbi_string.c
+++ b/lib/sbi/sbi_string.c
@@ -122,6 +122,9 @@ void *sbi_memset(void *s, int c, size_t count)
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)
{
char *temp1 = dest;
@@ -135,6 +138,9 @@ void *sbi_memcpy(void *dest, const void *src, size_t count)
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)
{
char *temp1 = (char *)dest;