Re: [PATCH] lib/clz_ctz.c: Fix __clzdi2() and __ctzdi2() for 32-bit kernels

From: Nick Desaulniers
Date: Mon Aug 28 2023 - 16:10:26 EST


On Mon, Aug 28, 2023 at 12:33 AM Geert Uytterhoeven
<geert@xxxxxxxxxxxxxx> wrote:
>
> Hi Linus,
>
> On Sat, Aug 26, 2023 at 3:08 AM Linus Torvalds
> <torvalds@xxxxxxxxxxxxxxxxxxxx> wrote:
> > On Fri, 25 Aug 2023 at 17:52, Nick Desaulniers <ndesaulniers@xxxxxxxxxx> wrote:
> > And quite often we simply use other names - but then we also do *not*
> > build with -freestanding, because -freestanding has at least
> > traditionally meant that the compiler won't optimize the simple and
> > obvious cases (typically things like "memcpy with a constant size").
>
> Several architectures (incl. x86, but excl. amd64) do build the kernel with
> -freestanding.
>
> IIRC, the issue was that without that, gcc was "optimizing" calls
> to standard functions (implemented as inline optimized assembler
> functions) by replacing them with calls to other standard functions
> (also implemented as inline optimized assembler functions). As the
> latter became external calls, this defeated the optimized assembler
> implementation, and could even cause build failures if no external
> implementation was available.

That's what the -fno-builtin-* flags are for, IMO, though those also
have toolchain portability issues IME.

--
Thanks,
~Nick Desaulniers