diff mbox series

kbuild: Add '-fno-builtin-wcslen'

Message ID 20250407-fno-builtin-wcslen-v1-1-6775ce759b15@kernel.org (mailing list archive)
State New
Headers show
Series kbuild: Add '-fno-builtin-wcslen' | expand

Commit Message

Nathan Chancellor April 7, 2025, 11:22 p.m. UTC
A recent optimization change in LLVM [1] aims to transform certain loop
idioms into calls to strlen() or wcslen(). This change transforms the
first while loop in UniStrcat() into a call to wcslen(), breaking the
build when UniStrcat() gets inlined into alloc_path_with_tree_prefix():

  ld.lld: error: undefined symbol: wcslen
  >>> referenced by nls_ucs2_utils.h:54 (fs/smb/client/../../nls/nls_ucs2_utils.h:54)
  >>>               vmlinux.o:(alloc_path_with_tree_prefix)
  >>> referenced by nls_ucs2_utils.h:54 (fs/smb/client/../../nls/nls_ucs2_utils.h:54)
  >>>               vmlinux.o:(alloc_path_with_tree_prefix)

Disable this optimization with '-fno-builtin-wcslen', which prevents the
compiler from assuming that wcslen() is available in the kernel's C
library

Cc: stable@vger.kernel.org
Link: https://github.com/llvm/llvm-project/commit/9694844d7e36fd5e01011ab56b64f27b867aa72d [1]
Signed-off-by: Nathan Chancellor <nathan@kernel.org>
---
 Makefile | 3 +++
 1 file changed, 3 insertions(+)


---
base-commit: 0af2f6be1b4281385b618cb86ad946eded089ac8
change-id: 20250407-fno-builtin-wcslen-90a858ae7d54

Best regards,

Comments

Kees Cook April 8, 2025, 11:33 p.m. UTC | #1
On Mon, Apr 07, 2025 at 04:22:12PM -0700, Nathan Chancellor wrote:
> A recent optimization change in LLVM [1] aims to transform certain loop
> idioms into calls to strlen() or wcslen(). This change transforms the
> first while loop in UniStrcat() into a call to wcslen(), breaking the
> build when UniStrcat() gets inlined into alloc_path_with_tree_prefix():
> 
>   ld.lld: error: undefined symbol: wcslen
>   >>> referenced by nls_ucs2_utils.h:54 (fs/smb/client/../../nls/nls_ucs2_utils.h:54)
>   >>>               vmlinux.o:(alloc_path_with_tree_prefix)
>   >>> referenced by nls_ucs2_utils.h:54 (fs/smb/client/../../nls/nls_ucs2_utils.h:54)
>   >>>               vmlinux.o:(alloc_path_with_tree_prefix)
> 
> Disable this optimization with '-fno-builtin-wcslen', which prevents the
> compiler from assuming that wcslen() is available in the kernel's C
> library
> 
> Cc: stable@vger.kernel.org
> Link: https://github.com/llvm/llvm-project/commit/9694844d7e36fd5e01011ab56b64f27b867aa72d [1]
> Signed-off-by: Nathan Chancellor <nathan@kernel.org>

Thanks for chasing this down. :)

Reviewed-by: Kees Cook <kees@kernel.org>

Since I have stuff queued for -rc2, do you want me to snag this too?
Linus Torvalds April 9, 2025, 12:14 a.m. UTC | #2
On Tue, 8 Apr 2025 at 16:33, Kees Cook <kees@kernel.org> wrote:
> Since I have stuff queued for -rc2, do you want me to snag this too?

Well, since I felt so strongly about this one, I already took it...

           Linus
diff mbox series

Patch

diff --git a/Makefile b/Makefile
index 38689a0c3605..f42418556507 100644
--- a/Makefile
+++ b/Makefile
@@ -1068,6 +1068,9 @@  ifdef CONFIG_CC_IS_GCC
 KBUILD_CFLAGS   += -fconserve-stack
 endif
 
+# Ensure compilers do not transform certain loops into calls to wcslen()
+KBUILD_CFLAGS += -fno-builtin-wcslen
+
 # change __FILE__ to the relative path to the source directory
 ifdef building_out_of_srctree
 KBUILD_CPPFLAGS += $(call cc-option,-ffile-prefix-map=$(srcroot)/=)