Re: [GIT PULL] string fixes for v6.15-rc1

From: Linus Torvalds
Date: Sun Apr 06 2025 - 22:04:58 EST


On Sun, 6 Apr 2025 at 18:33, Kees Cook <kees@xxxxxxxxxx> wrote:
>
> I should have said "libcall optimizations". It's not just blindly constructing calls.

But it's *WRONG*.

It's stupid. It's not an optimization, it makes things worse.

> This is the same kind of thing that has been heavily discussed before for bcmp() and stpcpy()

And it makes a bit more sense at least for stpcpy(), because the
implementation there is basically "strlen+memcpy". Both of which we
want the compiler to work on - even if we're not interested in it ever
using stpcpy().

IOF, for stpcpy, there's at least a *reason* for the compiler to do it.

For something like wcslen() the answer is "DON'T DO THIS". Because
there is absolutely zero upside to trying to recognize this pattern,
and there is real downside.

See?

Don't work around the compiler doing stupid things. Fix the compiler
options to tell the compiler to "Don'tDoThatThen(tm)".

Linus