[Skiboot] [PATCH] fix: Fix compile errors with GCC 15

Aditya Gupta adityag at linux.ibm.com
Sat Mar 29 04:13:54 AEDT 2025


GCC 15 has introduced errors for "unterminated-string-initialization"
Which treat any character array initialised with a string with a larger
size such that the null-character is not getting included in the
character array, GCC 15 gives a warning (and warnings are treated as
errors in skiboot compile).

This causes following errors on compiling skiboot with GCC 15:

    core/init.c:79:27: error: initializer-string for array of ‘unsigned char’ truncates NUL terminator but destination lacks ‘nonstring’ attribute (9 chars into 8 available) [-Werror=unterminated
    -string-initialization]
       79 |         .eye_catcher    = "OPALdbug",
          |                           ^~~~~~~~~~
    cc1: all warnings being treated as errors
    ...

    In file included from hdata/hdata.h:8,
                     from hdata/spira.c:17:
    hdata/spira.c:35:32: error: initializer-string for array of ‘char’ truncates NUL terminator but destination lacks ‘nonstring’ attribute (7 chars into 6 available) [-Werror=unterminated-string
    -initialization]
       35 |         .hdr = HDIF_SIMPLE_HDR("PROCIN", 1, struct proc_init_data),
          |                                ^~~~~~~~
    hdata/hdif.h:45:68: note: in definition of macro ‘HDIF_ID’
       45 | #define HDIF_ID(_id)            .d1f0 = CPU_TO_BE16(0xd1f0), .id = _id
          |                                                                    ^~~
    hdata/spira.c:35:16: note: in expansion of macro ‘HDIF_SIMPLE_HDR’
       35 |         .hdr = HDIF_SIMPLE_HDR("PROCIN", 1, struct proc_init_data),
          |                ^~~~~~~~~~~~~~~
    ...
     (similar errors few more times with hdata)
    ...
    cc1: all warnings being treated as errors```

Fix the errors by marking character arrays which are not supposed to be
"null-terminated strings" with "nonstring" attribute, such as
eye-catchers in skiboot debug descriptor and hdif header

Signed-off-by: Aditya Gupta <adityag at linux.ibm.com>
---
 hdata/hdif.h               | 2 +-
 include/compiler.h         | 7 +++++++
 include/debug_descriptor.h | 2 +-
 3 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/hdata/hdif.h b/hdata/hdif.h
index 38df6c271b55..f31d91428274 100644
--- a/hdata/hdif.h
+++ b/hdata/hdif.h
@@ -10,7 +10,7 @@
 
 struct HDIF_common_hdr {
 	__be16	d1f0;		/* 0xd1f0 */
-	char	id[6];		/* eye catcher string */
+	char	id[6] __nonstring;	/* eye catcher string */
 	__be16	instnum;	/* instance number */
 	__be16	version;	/* version */
 	__be32	total_len;	/* total structure length */
diff --git a/include/compiler.h b/include/compiler.h
index 77821ec098e6..74ca80993cd9 100644
--- a/include/compiler.h
+++ b/include/compiler.h
@@ -20,6 +20,13 @@
 #define __warn_unused_result	__attribute__((warn_unused_result))
 #define __noinline		__attribute__((noinline))
 
+/*
+ * GCC 15 introduces errors for "unterminated-string-initialization", mark
+ * character arrays that are not intended to be null-terminated as
+ * 'nonstring', such as eye-catchers
+ */
+#define __nonstring		__attribute((nonstring))
+
 #if 0 /* Provided by gcc stddef.h */
 #define offsetof(type,m)	__builtin_offsetof(type,m)
 #endif
diff --git a/include/debug_descriptor.h b/include/debug_descriptor.h
index 3ac487b00187..99c7b0b5c47b 100644
--- a/include/debug_descriptor.h
+++ b/include/debug_descriptor.h
@@ -9,7 +9,7 @@
  * 0x80 in the sapphire binary
  */
 struct debug_descriptor {
-	u8	eye_catcher[8];	/* "OPALdbug" */
+	u8	eye_catcher[8] __nonstring;	/* "OPALdbug" */
 #define DEBUG_DESC_VERSION	1
 	__be32	version;
 	u8	console_log_levels;	/* high 4 bits in memory,
-- 
2.49.0



More information about the Skiboot mailing list