Skip to contentSkip to conversation

kbuild: Re-enable -Wunterminated-string-initialization

PATCH Superseded Kees Cook 2 participants 5 messages Aug 2, 2025 Kbuild

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Kees Cook

author
#0 lore raw

PATCH 1/1 kbuild: Re-enable -Wunterminated-string-initialization

With the few remaining fixes now landed, we can re-enable the option -Wunterminated-string-initialization for GCC. (Clang does not yet fully understand the "nonstring" attribute.)

---
Cc: Masahiro Yamada <[email protected]>
Cc: Nathan Chancellor <[email protected]>
Cc: Nicolas Schier <[email protected]>
Cc: <[email protected]>

---
 scripts/Makefile.extrawarn | 2 ++
 1 file changed, 2 insertions(+)
scripts/Makefile.extrawarn +2 -0
index dca175fffcab..7ab8549485a4 100644
@@ -78,8 +78,10 @@ KBUILD_CFLAGS += $(call cc-option, -Wcast-function-type)
 KBUILD_CFLAGS-$(CONFIG_CC_NO_STRINGOP_OVERFLOW) += $(call cc-option, -Wno-stringop-overflow)
 KBUILD_CFLAGS-$(CONFIG_CC_STRINGOP_OVERFLOW) += $(call cc-option, -Wstringop-overflow)
 
+ifdef CONFIG_CC_IS_CLANG
 # Currently, disable -Wunterminated-string-initialization as broken
 KBUILD_CFLAGS += $(call cc-option, -Wno-unterminated-string-initialization)
+endif
 
 # The allocators already balk at large sizes, so silence the compiler
 # warnings for bounds checks involving those possible values. While
Signature · 1 line
2.34.1
#1 lore raw
Quoted 5 lines · Kees Cook

With the few remaining fixes now landed, we can re-enable the option -Wunterminated-string-initialization for GCC. (Clang does not yet fully understand the "nonstring" attribute.)

What else does Clang need? Are bugs filed? I had requested support for multidimensional arrays, which Aaron implemented pretty quickly (and the tests seem pretty expansive):

https://github.com/llvm/llvm-project/commit/e8ae77947154e10dbc05cbb95ec9e10d3b0be13e

Quoted 27 lines

---
Cc: Masahiro Yamada <[email protected]>
Cc: Nathan Chancellor <[email protected]>
Cc: Nicolas Schier <[email protected]>
Cc: <[email protected]>

---
 scripts/Makefile.extrawarn | 2 ++
 1 file changed, 2 insertions(+)
scripts/Makefile.extrawarn +2 -0
index dca175fffcab..7ab8549485a4 100644
@@ -78,8 +78,10 @@ KBUILD_CFLAGS += $(call cc-option, -Wcast-function-type)
 KBUILD_CFLAGS-$(CONFIG_CC_NO_STRINGOP_OVERFLOW) += $(call cc-option, -Wno-stringop-overflow)
 KBUILD_CFLAGS-$(CONFIG_CC_STRINGOP_OVERFLOW) += $(call cc-option, -Wstringop-overflow)
 
+ifdef CONFIG_CC_IS_CLANG
 # Currently, disable -Wunterminated-string-initialization as broken
 KBUILD_CFLAGS += $(call cc-option, -Wno-unterminated-string-initialization)
+endif
 
 # The allocators already balk at large sizes, so silence the compiler
 # warnings for bounds checks involving those possible values. While
Signature · 1 line
2.34.1
author
#2 lore raw
Quoted 5 lines · Nathan Chancellor
Quoted 4 lines · Kees Cook

With the few remaining fixes now landed, we can re-enable the option -Wunterminated-string-initialization for GCC. (Clang does not yet fully understand the "nonstring" attribute.)

Quoted 7 lines
Quoted 1 line

What else does Clang need? Are bugs filed? I had requested support for multidimensional arrays, which Aaron implemented pretty quickly (and the tests seem pretty expansive):

https://github.com/llvm/llvm-project/commit/e8ae77947154e10dbc05cbb95ec9e10d3b0be13e

Oh! I missed that commit. Did that end up in Clang 21? Let me try some test builds with a more recent Clang...

Signature · 1 line
Kees Cook
#3 lore raw
Quoted 8 lines · Kees Cook
Quoted 7 lines · Nathan Chancellor
Quoted 5 lines · Kees Cook

With the few remaining fixes now landed, we can re-enable the option -Wunterminated-string-initialization for GCC. (Clang does not yet fully understand the "nonstring" attribute.)

Quoted 8 lines
Quoted 5 lines

What else does Clang need? Are bugs filed? I had requested support for multidimensional arrays, which Aaron implemented pretty quickly (and the tests seem pretty expansive):

https://github.com/llvm/llvm-project/commit/e8ae77947154e10dbc05cbb95ec9e10d3b0be13e

Oh! I missed that commit. Did that end up in Clang 21? Let me try some test builds with a more recent Clang...

Whoops, linked the wrong change (although that one is still good):

https://github.com/llvm/llvm-project/commit/3d4f979e271d2a1fe0906f4d1b16db108838f98f

But yes, both those changes are in 21.1.0-rc1. I uploaded -rc2 to kernel.org a couple of days ago: https://kernel.org/pub/tools/llvm/

Cheers,
Nathan

author
#4 lore raw
Quoted 18 lines · Nathan Chancellor
Quoted 8 lines · Kees Cook
Quoted 7 lines · Nathan Chancellor
Quoted 5 lines · Kees Cook

With the few remaining fixes now landed, we can re-enable the option -Wunterminated-string-initialization for GCC. (Clang does not yet fully understand the "nonstring" attribute.)

Quoted 8 lines
Quoted 5 lines

What else does Clang need? Are bugs filed? I had requested support for multidimensional arrays, which Aaron implemented pretty quickly (and the tests seem pretty expansive):

https://github.com/llvm/llvm-project/commit/e8ae77947154e10dbc05cbb95ec9e10d3b0be13e

Oh! I missed that commit. Did that end up in Clang 21? Let me try some test builds with a more recent Clang...

Quoted 6 lines

Whoops, linked the wrong change (although that one is still good):

https://github.com/llvm/llvm-project/commit/3d4f979e271d2a1fe0906f4d1b16db108838f98f

But yes, both those changes are in 21.1.0-rc1. I uploaded -rc2 to kernel.org a couple of days ago: https://kernel.org/pub/tools/llvm/

Ah yeah! Let me get this retested with the 21.1 release. I think we don't need any special handling.

Signature · 1 line
Kees Cook