nolibc: Do not define `memset()` function in liburing

liburing has its own memset() in nolibc.c. liburing nolibc can be
linked to apps that use libc. libc has an optimized version of memset()
function.

Alviro reports that he found the memset() from liburing replaces the
optimized memset() from libc when he compiled liburing statically.

A simple reproducer:

  #include <stdio.h>
  #include <stdlib.h>
  #include <string.h>

  int main(void)
  {
          static const size_t len = 1024ul  1024ul  1024ul * 4ul;
          char *p;

          p = malloc(len);
          __asm__ volatile ("":"+m"(p));
          memset(p, 0, len);
          __asm__ volatile ("":"+m"(p));
          return 0;
  }

Compile liburing with:

  # Build liburing nolibc.
  ./configure --nolibc;
  make -j8;

  # Without liburing, memset() comes from libc (good)
  gcc x.c -o x;
  objdump -d x;

  # With liburing.a, memset() comes from liburing (bad)
  gcc x.c -o x src/liburing.a;
  objdump -d x;

When we statically link liburing, the linker will choose the statically
linked memset() over the dynamically linked memset() that the libc
provides.

Change the function name to __uring_memset() and define a macro
memset() as:

   #define memset(PTR, C, LEN) __uring_memset(PTR, C, LEN)

when CONFIG_NOLIBC is enabled so we don't have to touch the callers.

Fixes: f48ee3168cdc325233825603269f304d348d323c ("Add nolibc build support")
Reported-by: Alviro Iskandar Setiawan <alviro.iskandar@gnuweeb.org>
Signed-off-by: Ammar Faizi <ammarfaizi2@gnuweeb.org>
Link: https://lore.kernel.org/r/20221124054345.3752171-2-ammar.faizi@intel.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2 files changed