Re: tools/nolibc: fix missing strlen() definition and infinite loop with gcc-12

From: Alexey Dobriyan
Date: Sun Oct 09 2022 - 11:46:10 EST

Willy Tarreau wrote:
> +#if defined(__GNUC__) && (__GNUC__ >= 12)
> +__attribute__((optimize("no-tree-loop-distribute-patterns")))
> +#endif
> static __attribute__((unused))
> -size_t nolibc_strlen(const char *str

I'd suggest to use asm("") in the loop body. It worked in the past
to prevent folding division loop back into division instruction.

Or switch to

size_t f(const char *s)
const char *s0 = s;
while (*s++)
return s - s0 - 1;

which compiles to 1 branch, not 2.

But of course they could recognise this pattern too.