diff mbox series

[1/1] ACPI: Fix building with GCC 15

Message ID 20250121214219.1455896-1-brahmajit.xyz@gmail.com
State New
Headers show
Series [1/1] ACPI: Fix building with GCC 15 | expand

Commit Message

Brahmajit Jan. 21, 2025, 9:42 p.m. UTC
Building with GCC 15 results in the following build error:

...
  CC      drivers/acpi/tables.o
In file included from ./include/acpi/actbl.h:371,
                 from ./include/acpi/acpi.h:26,
                 from ./include/linux/acpi.h:26,
                 from drivers/acpi/tables.c:19:
./include/acpi/actbl1.h:30:33: error: initializer-string for array of ‘char’ is too long [-Werror=unterminated-string-initialization]
   30 | #define ACPI_SIG_BERT           "BERT"  /* Boot Error Record Table */
      |                                 ^~~~~~
drivers/acpi/tables.c:400:9: note: in expansion of macro ‘ACPI_SIG_BERT’
  400 |         ACPI_SIG_BERT, ACPI_SIG_BGRT, ACPI_SIG_CPEP, ACPI_SIG_ECDT,
      |         ^~~~~~~~~~~~~
./include/acpi/actbl1.h:31:33: error: initializer-string for array of ‘char’ is too long [-Werror=unterminated-string-initialization]
   31 | #define ACPI_SIG_BGRT           "BGRT"  /* Boot Graphics Resource Table */
      |                                 ^~~~~~
drivers/acpi/tables.c:400:24: note: in expansion of macro ‘ACPI_SIG_BGRT’
  400 |         ACPI_SIG_BERT, ACPI_SIG_BGRT, ACPI_SIG_CPEP, ACPI_SIG_ECDT,
      |                        ^~~~~~~~~~~~~
./include/acpi/actbl1.h:34:33: error: initializer-string for array of ‘char’ is too long [-Werror=unterminated-string-initialization]
   34 | #define ACPI_SIG_CPEP           "CPEP"  /* Corrected Platform Error Polling table */
...

This is due to GCC having enabled
-Werror=unterminated-string-initialization[0] by default. To work around
this build time error we're modifying the size of table_sigs from
table_sigs[][ACPI_NAMESEG_SIZE] to table_sigs[][ACPI_NAMESEG_SIZE + 1].
This ensures space for NUL, thus satisfying GCC.

[0]: https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html#index-Wno-unterminated-string-initialization

Signed-off-by: Brahmajit Das <brahmajit.xyz@gmail.com>
---
 drivers/acpi/tables.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Ard Biesheuvel Feb. 13, 2025, 3:46 p.m. UTC | #1
On Tue, 21 Jan 2025 at 22:42, Brahmajit Das <brahmajit.xyz@gmail.com> wrote:
>
> Building with GCC 15 results in the following build error:
>
> ...
>   CC      drivers/acpi/tables.o
> In file included from ./include/acpi/actbl.h:371,
>                  from ./include/acpi/acpi.h:26,
>                  from ./include/linux/acpi.h:26,
>                  from drivers/acpi/tables.c:19:
> ./include/acpi/actbl1.h:30:33: error: initializer-string for array of ‘char’ is too long [-Werror=unterminated-string-initialization]
>    30 | #define ACPI_SIG_BERT           "BERT"  /* Boot Error Record Table */
>       |                                 ^~~~~~
> drivers/acpi/tables.c:400:9: note: in expansion of macro ‘ACPI_SIG_BERT’
>   400 |         ACPI_SIG_BERT, ACPI_SIG_BGRT, ACPI_SIG_CPEP, ACPI_SIG_ECDT,
>       |         ^~~~~~~~~~~~~
> ./include/acpi/actbl1.h:31:33: error: initializer-string for array of ‘char’ is too long [-Werror=unterminated-string-initialization]
>    31 | #define ACPI_SIG_BGRT           "BGRT"  /* Boot Graphics Resource Table */
>       |                                 ^~~~~~
> drivers/acpi/tables.c:400:24: note: in expansion of macro ‘ACPI_SIG_BGRT’
>   400 |         ACPI_SIG_BERT, ACPI_SIG_BGRT, ACPI_SIG_CPEP, ACPI_SIG_ECDT,
>       |                        ^~~~~~~~~~~~~
> ./include/acpi/actbl1.h:34:33: error: initializer-string for array of ‘char’ is too long [-Werror=unterminated-string-initialization]
>    34 | #define ACPI_SIG_CPEP           "CPEP"  /* Corrected Platform Error Polling table */
> ...
>
> This is due to GCC having enabled
> -Werror=unterminated-string-initialization[0] by default. To work around
> this build time error we're modifying the size of table_sigs from
> table_sigs[][ACPI_NAMESEG_SIZE] to table_sigs[][ACPI_NAMESEG_SIZE + 1].
> This ensures space for NUL, thus satisfying GCC.
>
> [0]: https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html#index-Wno-unterminated-string-initialization
>
> Signed-off-by: Brahmajit Das <brahmajit.xyz@gmail.com>
> ---
>  drivers/acpi/tables.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/acpi/tables.c b/drivers/acpi/tables.c
> index 9e1b01c35070..5a6524eb79d8 100644
> --- a/drivers/acpi/tables.c
> +++ b/drivers/acpi/tables.c
> @@ -396,7 +396,7 @@ static u8 __init acpi_table_checksum(u8 *buffer, u32 length)
>  }
>
>  /* All but ACPI_SIG_RSDP and ACPI_SIG_FACS: */
> -static const char table_sigs[][ACPI_NAMESEG_SIZE] __initconst = {
> +static const char table_sigs[][ACPI_NAMESEG_SIZE + 1] __initconst = {
>         ACPI_SIG_BERT, ACPI_SIG_BGRT, ACPI_SIG_CPEP, ACPI_SIG_ECDT,
>         ACPI_SIG_EINJ, ACPI_SIG_ERST, ACPI_SIG_HEST, ACPI_SIG_MADT,
>         ACPI_SIG_MSCT, ACPI_SIG_SBST, ACPI_SIG_SLIT, ACPI_SIG_SRAT,

Please add the __nonstring attribute instead.
David Laight Feb. 13, 2025, 8:06 p.m. UTC | #2
On Thu, 13 Feb 2025 16:46:56 +0100
Ard Biesheuvel <ardb@kernel.org> wrote:

> On Tue, 21 Jan 2025 at 22:42, Brahmajit Das <brahmajit.xyz@gmail.com> wrote:
> >
> > Building with GCC 15 results in the following build error:
> >
> > ...
> >   CC      drivers/acpi/tables.o
> > In file included from ./include/acpi/actbl.h:371,
> >                  from ./include/acpi/acpi.h:26,
> >                  from ./include/linux/acpi.h:26,
> >                  from drivers/acpi/tables.c:19:
> > ./include/acpi/actbl1.h:30:33: error: initializer-string for array of ‘char’ is too long [-Werror=unterminated-string-initialization]
> >    30 | #define ACPI_SIG_BERT           "BERT"  /* Boot Error Record Table */
> >       |                                 ^~~~~~
> > drivers/acpi/tables.c:400:9: note: in expansion of macro ‘ACPI_SIG_BERT’
> >   400 |         ACPI_SIG_BERT, ACPI_SIG_BGRT, ACPI_SIG_CPEP, ACPI_SIG_ECDT,
> >       |         ^~~~~~~~~~~~~
> > ./include/acpi/actbl1.h:31:33: error: initializer-string for array of ‘char’ is too long [-Werror=unterminated-string-initialization]
> >    31 | #define ACPI_SIG_BGRT           "BGRT"  /* Boot Graphics Resource Table */
> >       |                                 ^~~~~~
> > drivers/acpi/tables.c:400:24: note: in expansion of macro ‘ACPI_SIG_BGRT’
> >   400 |         ACPI_SIG_BERT, ACPI_SIG_BGRT, ACPI_SIG_CPEP, ACPI_SIG_ECDT,
> >       |                        ^~~~~~~~~~~~~
> > ./include/acpi/actbl1.h:34:33: error: initializer-string for array of ‘char’ is too long [-Werror=unterminated-string-initialization]
> >    34 | #define ACPI_SIG_CPEP           "CPEP"  /* Corrected Platform Error Polling table */
> > ...
> >
> > This is due to GCC having enabled
> > -Werror=unterminated-string-initialization[0] by default. To work around
> > this build time error we're modifying the size of table_sigs from
> > table_sigs[][ACPI_NAMESEG_SIZE] to table_sigs[][ACPI_NAMESEG_SIZE + 1].
> > This ensures space for NUL, thus satisfying GCC.
> >
> > [0]: https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html#index-Wno-unterminated-string-initialization
> >
> > Signed-off-by: Brahmajit Das <brahmajit.xyz@gmail.com>
> > ---
> >  drivers/acpi/tables.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/drivers/acpi/tables.c b/drivers/acpi/tables.c
> > index 9e1b01c35070..5a6524eb79d8 100644
> > --- a/drivers/acpi/tables.c
> > +++ b/drivers/acpi/tables.c
> > @@ -396,7 +396,7 @@ static u8 __init acpi_table_checksum(u8 *buffer, u32 length)
> >  }
> >
> >  /* All but ACPI_SIG_RSDP and ACPI_SIG_FACS: */
> > -static const char table_sigs[][ACPI_NAMESEG_SIZE] __initconst = {
> > +static const char table_sigs[][ACPI_NAMESEG_SIZE + 1] __initconst = {
> >         ACPI_SIG_BERT, ACPI_SIG_BGRT, ACPI_SIG_CPEP, ACPI_SIG_ECDT,
> >         ACPI_SIG_EINJ, ACPI_SIG_ERST, ACPI_SIG_HEST, ACPI_SIG_MADT,
> >         ACPI_SIG_MSCT, ACPI_SIG_SBST, ACPI_SIG_SLIT, ACPI_SIG_SRAT,  
> 
> Please add the __nonstring attribute instead.

That doesn't fix initialisers.
There is a gcc bug about it (and a patch)...

	David
Brahmajit Feb. 14, 2025, 7:27 p.m. UTC | #3
GCC bug
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117178,
and patch
https://gcc.gnu.org/pipermail/gcc-patches/2024-December/671714.html
diff mbox series

Patch

diff --git a/drivers/acpi/tables.c b/drivers/acpi/tables.c
index 9e1b01c35070..5a6524eb79d8 100644
--- a/drivers/acpi/tables.c
+++ b/drivers/acpi/tables.c
@@ -396,7 +396,7 @@  static u8 __init acpi_table_checksum(u8 *buffer, u32 length)
 }
 
 /* All but ACPI_SIG_RSDP and ACPI_SIG_FACS: */
-static const char table_sigs[][ACPI_NAMESEG_SIZE] __initconst = {
+static const char table_sigs[][ACPI_NAMESEG_SIZE + 1] __initconst = {
 	ACPI_SIG_BERT, ACPI_SIG_BGRT, ACPI_SIG_CPEP, ACPI_SIG_ECDT,
 	ACPI_SIG_EINJ, ACPI_SIG_ERST, ACPI_SIG_HEST, ACPI_SIG_MADT,
 	ACPI_SIG_MSCT, ACPI_SIG_SBST, ACPI_SIG_SLIT, ACPI_SIG_SRAT,