[PATCH] tools/nolibc: avoid call to wcslen() in _start_c() inserted by clang

Thomas Weißschuh posted 1 patch 1 month, 4 weeks ago
tools/include/nolibc/crt.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
[PATCH] tools/nolibc: avoid call to wcslen() in _start_c() inserted by clang
Posted by Thomas Weißschuh 1 month, 4 weeks ago
Clang may convert the loop to find _auxv into a call to wcslen() which
is missing on nolibc. -fsanitize needs to be disabled for this to
happen.

Use the same pattern as in the nolibc strlen() implementation to avoid
the function call generation.

Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
---
 tools/include/nolibc/crt.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/include/nolibc/crt.h b/tools/include/nolibc/crt.h
index d8ce91fd2e3b..f38590a05adf 100644
--- a/tools/include/nolibc/crt.h
+++ b/tools/include/nolibc/crt.h
@@ -89,7 +89,7 @@ void _start_c(long *sp)
 
 	/* find _auxv */
 	for (auxv = (void *)envp; *auxv++;)
-		;
+		__asm__("");
 	_auxv = auxv;
 
 #ifndef NOLIBC_IGNORE_ERRNO

---
base-commit: b5ac9d2dc1330d0b16a141962ac202739b091efd
change-id: 20260418-nolibc-wcslen-5afac8eb318b

Best regards,
--  
Thomas Weißschuh <linux@weissschuh.net>

Re: [PATCH] tools/nolibc: avoid call to wcslen() in _start_c() inserted by clang
Posted by Willy Tarreau 1 month, 3 weeks ago
On Sat, Apr 18, 2026 at 12:31:54PM +0200, Thomas Weißschuh wrote:
> Clang may convert the loop to find _auxv into a call to wcslen() which
> is missing on nolibc. -fsanitize needs to be disabled for this to
> happen.
> 
> Use the same pattern as in the nolibc strlen() implementation to avoid
> the function call generation.
> 
> Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>

Compilers are always full of surprises!

Acked-by: Willy Tarreau <w@1wt.eu>
Willy