4 ms·
strlen from https://elixir.bootlin.com/linux/v6.2-rc4/source/tools/include/nolibc/string.h https://elixir.bootlin.com/linux/v6.2-rc4/source/tools/inclu...
by 1vuio0pswjnm7 4y ago
strlen from https://elixir.bootlin.com/linux/v6.2-rc4/source/tools/include/nolibc/string.h https://elixir.bootlin.com/linux/v6.2-rc4/source/tools/inclu...
/* this function is only used with arguments that are not constants or when
* it's not known because optimizations are disabled. Note that gcc 12
* recognizes an strlen() pattern and replaces it with a jump to strlen(),
* thus itself, hence the asm() statement below that's meant to disable this
* confusing practice.
*/
static __attribute__((unused))
size_t strlen(const char *str)
{
size_t len;
for (len = 0; str[len]; len++)
asm("");
return len;
}
/* do not trust __builtin_constant_p() at -O0, as clang will emit a test and
* the two branches, then will rely on an external definition of strlen().
*/
#if defined(__OPTIMIZE__)
#define nolibc_strlen(x) strlen(x)
#define strlen(str) ({ \
__builtin_constant_p((str)) ? \
__builtin_strlen((str)) : \
nolibc_strlen((str)); \
})
#endif
- deleted 4y ago[deleted]