[PATCH 1/1] lib: define memmove(), memcmp() as aliases

Anup Patel anup at brainfault.org
Thu Dec 23 03:52:29 PST 2021


Hi Heinrich,

On Thu, Dec 23, 2021 at 4:39 PM Heinrich Schuchardt
<heinrich.schuchardt at canonical.com> wrote:
>
> According to the GCC documentation the freestanding environment must provide
> memcpy(), memmove(), memset(), and memcmp(). We already have defined
> memcpy() and memset() as weak aliases for sbi_memcpy() and sbi_memset() in
> commit d249d6544c3c ("lib: sbi: Fix compile errors using -Os option").
> Do the same for memmove() and memcmp().
>
> Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt at canonical.com>

We are moving memcpy() and memset() aliases to fw_base.S so that
it's not part of libsbi.a which in-turn helps external firmwares using
OpenSBI as a library. I am not fond of this solution but for the time
being it will work. After OpenSBI v1.0 release, we can figure-out
better way to do this within the firmware/ directory.

Are you okay if I add memmove() and memcmp() aliases in
fw_base.S as part of another patch ?

Regards,
Anup

> ---
>  lib/sbi/sbi_string.c | 6 ++++++
>  1 file changed, 6 insertions(+)
>
> diff --git a/lib/sbi/sbi_string.c b/lib/sbi/sbi_string.c
> index c67c02e..233be4e 100644
> --- a/lib/sbi/sbi_string.c
> +++ b/lib/sbi/sbi_string.c
> @@ -167,6 +167,9 @@ void *sbi_memmove(void *dest, const void *src, size_t count)
>         return dest;
>  }
>
> +void *memmove(void *dest, const void *src, size_t count) \
> +__attribute__((weak, alias("sbi_memmove")));
> +
>  int sbi_memcmp(const void *s1, const void *s2, size_t count)
>  {
>         const char *temp1 = s1;
> @@ -183,6 +186,9 @@ int sbi_memcmp(const void *s1, const void *s2, size_t count)
>                 return 0;
>  }
>
> +int memcmp(const void *s1, const void *s2, size_t count) \
> +__attribute__((weak, alias("sbi_memcmp")));
> +
>  void *sbi_memchr(const void *s, int c, size_t count)
>  {
>         const unsigned char *temp = s;
> --
> 2.33.1
>



More information about the opensbi mailing list