Re: [PATCH] fortify: turn strlen() into an inline function using __builtin_constant_p()
From: David Laight
Date: Sat Jan 11 2025 - 11:58:56 EST
On Sat, 11 Jan 2025 23:40:41 +0900
Vincent Mailhol <mailhol.vincent@xxxxxxxxxx> wrote:
> On Thu. 9 Jan 2025 at 16:52, Vincent Mailhol <mailhol.vincent@xxxxxxxxxx> wrote:
...
> Actually, I did more investigation and it is working for some strange
> reasons. Whenever the argument of a function named strlen() is a
> compile time constant, the compiler (both GCC and clang) will replace
> it with the string length on the argument, even if strlen() is
> programmed to return something else:
>
> https://godbolt.org/z/nK4b3fnM7
>
> So it is only working because the compiler uses its builtin strlen()
> instead of the function we provided.
It depends on whether -ffreestanding is set.
If not set gcc/clang assume a lot of the basic libc functions have their expected
behaviour.
David