Skip to content

Commit 1382fe9

Browse files
Th3Fanbuscrawfxrd
authored andcommitted
treewide: Work around GCC 15 Werror=unterminated-string-initialization
GCC 15 added a new `unterminated-string-initialization` warning. Even though crossgcc is still using GCC 14, some Linux distributions (e.g. Arch Linux) already started shipping GCC 15. Given that coreboot uses `-Werror` (warnings are errors), this new warning causes build errors for things built using the host toolchain, such as utilities. In this case, cbfstool is affected, which prevents building coreboot images. The nonstring attribute is used to tell the compiler whether or not a string is intentionally not null terminated. Since the attribute is only included in GCC 15 for multidimensional character arrays (and even later for clang) we need to check the GCC version before using the attribute. On GCC version prior to GCC 15 the nonstring attribute will not be used, but that is not a problem since the unterminated-string-initialization warning only exists since GCC 15. So you can still build on all GCC versions as before. This way it also works if your host toolchain is GCC 15 (which builds commonlib code for cbfstool) and your coreboot cross toolchain is GCC 14 (which builds commonlib code for coreboot). Clang is a diffent matter. According to the documentation, the nonstring attribute only exists in version 21 which is not yet released by LLVM. TEST=Build qemu/Q35 successfully Change-Id: I919d71cb2811e91869ba1ff493a0719ddcc86c36 Signed-off-by: Angel Pons <[email protected]> Reviewed-on: https://review.coreboot.org/c/coreboot/+/87825 Reviewed-by: Benjamin Doron <[email protected]> Reviewed-by: Nicholas Chin <[email protected]> Reviewed-by: Matt DeVillier <[email protected]> Tested-by: build bot (Jenkins) <[email protected]>
1 parent 5fe613b commit 1382fe9

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

src/commonlib/bsd/include/commonlib/bsd/compiler.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,13 @@
6666
#define __printf(a, b) __attribute__((format(printf, a, b)))
6767
#endif
6868

69+
// This checks the support for the nonstring attribute on multidimensional character arrays.
70+
#if (defined(__GNUC__) && __GNUC__ >= 15) || (defined(__clang__) && __clang_major__ >= 21)
71+
#define __nonstring __attribute__((__nonstring__))
72+
#else
73+
#define __nonstring
74+
#endif
75+
6976
/*
7077
* This evaluates to the type of the first expression, unless that is constant
7178
* in which case it evaluates to the type of the second. This is useful when

src/commonlib/include/commonlib/loglevel.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@
165165
*/
166166
#define BIOS_LOG_PREFIX_PATTERN "[%.5s] "
167167
#define BIOS_LOG_PREFIX_MAX_LEVEL BIOS_SPEW
168-
static const char bios_log_prefix[BIOS_LOG_PREFIX_MAX_LEVEL + 1][5] = {
168+
static const char __nonstring bios_log_prefix[BIOS_LOG_PREFIX_MAX_LEVEL + 1][5] = {
169169
/* Note: These strings are *not* null-terminated to save space. */
170170
[BIOS_EMERG] = "EMERG",
171171
[BIOS_ALERT] = "ALERT",

util/cbfstool/common.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ uint64_t intfiletype(const char *name)
192192

193193
char *bintohex(uint8_t *data, size_t len)
194194
{
195-
static const char translate[16] = "0123456789abcdef";
195+
static const char __nonstring translate[16] = "0123456789abcdef";
196196

197197
char *result = malloc(len * 2 + 1);
198198
if (result == NULL)

0 commit comments

Comments
 (0)