But I wonder why, the mem* functions are trivial to implement in plain
C so why does one need to provide them?
I took ali to be asking to build without any libraries at all, including
libgcc, which is what you get when you use -nostdlib. That can't work.
I think you are talking about the case where we do use libgcc, but don't
use libc. In other words: why don't we provide memcpy, etc., in libgcc,
or, rather, just call libgcc-specific routines? The answer is that we
expect the library provider to have a highly optimized version of those
functions. That is certainly the case when using glibc on GNU/Linux.
Since the library provider should already have a highly optimized
version, gcc doesn't bother providing one itself.
Of course we could still arrange to provide simple versions in some
additional library which is only linked after libc. I would not be
opposed to that. Real C programs, though, almost always call memcpy and
friends themselves, and real C programs always require some level of
supporting code. The current situation doesn't really bother me.