Re: [PATCH 0/1] tools/nolibc/string: export strlen()

From: Willy Tarreau
Date: Sat Jan 27 2024 - 16:27:43 EST


On Sat, Jan 27, 2024 at 09:23:01PM +0000, David Laight wrote:
> ..
> > Yes, once we have the proof that the compiler may produce such a call, it
> > can also happen in whatever user code so we need to export the function,
> > there's no other solution.
>
> Does that mean that it you try to implement strlen() in C
> gcc will generate a recursive call?

Yes, that's exactly what happened the first time with strlen() itself!

> I guess an 'asm volatile("");' in the loop fix it.

That's how we fixed it for strlen(). The problem I'm having with
addressing it this way is that as long as the compiler will decide
to emit calls to strlen() which was not explicitly referenced in
the code, it will still be missing and will continue to fail. Thus
the safest solution is to make sure strlen() remains accessible in
case the compiler decides to make use of it.

Willy