Skip to content

Commit d249d65

Browse files
committed
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>
1 parent 69d7e53 commit d249d65

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

lib/sbi/sbi_string.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,9 @@ void *sbi_memset(void *s, int c, size_t count)
122122
return s;
123123
}
124124

125+
void *memset(void *s, int c, size_t count) \
126+
__attribute__((weak, alias("sbi_memset")));
127+
125128
void *sbi_memcpy(void *dest, const void *src, size_t count)
126129
{
127130
char *temp1 = dest;
@@ -135,6 +138,9 @@ void *sbi_memcpy(void *dest, const void *src, size_t count)
135138
return dest;
136139
}
137140

141+
void *memcpy(void *dest, const void *src, size_t count) \
142+
__attribute__((weak, alias("sbi_memcpy")));
143+
138144
void *sbi_memmove(void *dest, const void *src, size_t count)
139145
{
140146
char *temp1 = (char *)dest;

0 commit comments

Comments
 (0)