diff mbox series

pc-bios/s390-ccw: Silence GCC 11 stringop-overflow warning

Message ID 20210422145911.2513980-1-philmd@redhat.com
State New
Headers show
Series pc-bios/s390-ccw: Silence GCC 11 stringop-overflow warning | expand

Commit Message

Philippe Mathieu-Daudé April 22, 2021, 2:59 p.m. UTC
When building on Fedora 34 (gcc version 11.0.0 20210210) we get:

  In file included from pc-bios/s390-ccw/main.c:11:
  In function ‘memset’,
      inlined from ‘boot_setup’ at pc-bios/s390-ccw/main.c:185:5,
      inlined from ‘main’ at pc-bios/s390-ccw/main.c:288:5:
  pc-bios/s390-ccw/libc.h:28:14: warning: writing 1 byte into a region of size 0 [-Wstringop-overflow=]
     28 |         p[i] = c;
        |         ~~~~~^~~

The offending code is:

  memset((char *)S390EP, 0, 6);

where S390EP is a const address:

  #define S390EP 0x10008

The compiler doesn't now how big that pointed area is, so assume its
length is zero. This has been reported as BZ#99578 to GCC:
"gcc-11 -Warray-bounds or -Wstringop-overread warning when accessing a
pointer from integer literal"
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99578

As this warning does us more harm than good in the BIOS code (where
lot of direct accesses to low memory are done), silence this warning
for all BIOS objects.

Re-introduce the cc-c-option macro (see commit 036999e93e4) to check
whether the compiler supports this warning or not.

Suggested-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
 pc-bios/s390-ccw/Makefile | 3 +++
 1 file changed, 3 insertions(+)

Comments

Christian Borntraeger April 22, 2021, 3:02 p.m. UTC | #1
On 22.04.21 16:59, Philippe Mathieu-Daudé wrote:
> When building on Fedora 34 (gcc version 11.0.0 20210210) we get:
> 
>    In file included from pc-bios/s390-ccw/main.c:11:
>    In function ‘memset’,
>        inlined from ‘boot_setup’ at pc-bios/s390-ccw/main.c:185:5,
>        inlined from ‘main’ at pc-bios/s390-ccw/main.c:288:5:
>    pc-bios/s390-ccw/libc.h:28:14: warning: writing 1 byte into a region of size 0 [-Wstringop-overflow=]
>       28 |         p[i] = c;
>          |         ~~~~~^~~
> 
> The offending code is:
> 
>    memset((char *)S390EP, 0, 6);
> 
> where S390EP is a const address:
> 
>    #define S390EP 0x10008
> 
> The compiler doesn't now how big that pointed area is, so assume its
> length is zero. This has been reported as BZ#99578 to GCC:
> "gcc-11 -Warray-bounds or -Wstringop-overread warning when accessing a
> pointer from integer literal"
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99578
> 
> As this warning does us more harm than good in the BIOS code (where
> lot of direct accesses to low memory are done), silence this warning
> for all BIOS objects.
> 
> Re-introduce the cc-c-option macro (see commit 036999e93e4) to check
> whether the compiler supports this warning or not.
> 
> Suggested-by: Thomas Huth <thuth@redhat.com>
> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>

untested, but
Acked-by: Christian Borntraeger <borntraeger@de.ibm.com>

> ---
>   pc-bios/s390-ccw/Makefile | 3 +++
>   1 file changed, 3 insertions(+)
> 
> diff --git a/pc-bios/s390-ccw/Makefile b/pc-bios/s390-ccw/Makefile
> index 29fd9019b83..21581d1258d 100644
> --- a/pc-bios/s390-ccw/Makefile
> +++ b/pc-bios/s390-ccw/Makefile
> @@ -8,6 +8,8 @@ CFLAGS = -O2 -g
>   quiet-command = $(if $(V),$1,$(if $(2),@printf "  %-7s %s\n" $2 $3 && $1, @$1))
>   cc-option = $(if $(shell $(CC) $1 -S -o /dev/null -xc /dev/null > /dev/null \
>   	      2>&1 && echo OK), $1, $2)
> +cc-c-option = $(if $(shell $(CC) $1 $2 -c -o /dev/null -xc /dev/null \
> +	      >/dev/null 2>&1 && echo OK), $2, $3)
>   
>   VPATH_SUFFIXES = %.c %.h %.S %.m %.mak %.sh %.rc Kconfig% %.json.in
>   set-vpath = $(if $1,$(foreach PATTERN,$(VPATH_SUFFIXES),$(eval vpath $(PATTERN) $1)))
> @@ -30,6 +32,7 @@ OBJECTS = start.o main.o bootmap.o jump2ipl.o sclp.o menu.o \
>   	  virtio.o virtio-scsi.o virtio-blkdev.o libc.o cio.o dasd-ipl.o
>   
>   QEMU_CFLAGS := -Wall $(filter -W%, $(QEMU_CFLAGS))
> +QEMU_CFLAGS += $(call cc-c-option, $(QEMU_CFLAGS), -Wno-stringop-overflow)
>   QEMU_CFLAGS += -ffreestanding -fno-delete-null-pointer-checks -fno-common -fPIE
>   QEMU_CFLAGS += -fwrapv -fno-strict-aliasing -fno-asynchronous-unwind-tables
>   QEMU_CFLAGS += $(call cc-option, $(QEMU_CFLAGS), -fno-stack-protector)
>
Thomas Huth May 2, 2021, 10:39 a.m. UTC | #2
On 22/04/2021 16.59, Philippe Mathieu-Daudé wrote:
> When building on Fedora 34 (gcc version 11.0.0 20210210) we get:
> 
>    In file included from pc-bios/s390-ccw/main.c:11:
>    In function ‘memset’,
>        inlined from ‘boot_setup’ at pc-bios/s390-ccw/main.c:185:5,
>        inlined from ‘main’ at pc-bios/s390-ccw/main.c:288:5:
>    pc-bios/s390-ccw/libc.h:28:14: warning: writing 1 byte into a region of size 0 [-Wstringop-overflow=]
>       28 |         p[i] = c;
>          |         ~~~~~^~~
> 
> The offending code is:
> 
>    memset((char *)S390EP, 0, 6);
> 
> where S390EP is a const address:
> 
>    #define S390EP 0x10008
> 
> The compiler doesn't now how big that pointed area is, so assume its
> length is zero. This has been reported as BZ#99578 to GCC:
> "gcc-11 -Warray-bounds or -Wstringop-overread warning when accessing a
> pointer from integer literal"
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99578
> 
> As this warning does us more harm than good in the BIOS code (where
> lot of direct accesses to low memory are done), silence this warning
> for all BIOS objects.
> 
> Re-introduce the cc-c-option macro (see commit 036999e93e4) to check
> whether the compiler supports this warning or not.
> 
> Suggested-by: Thomas Huth <thuth@redhat.com>
> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
> ---
>   pc-bios/s390-ccw/Makefile | 3 +++
>   1 file changed, 3 insertions(+)
> 
> diff --git a/pc-bios/s390-ccw/Makefile b/pc-bios/s390-ccw/Makefile
> index 29fd9019b83..21581d1258d 100644
> --- a/pc-bios/s390-ccw/Makefile
> +++ b/pc-bios/s390-ccw/Makefile
> @@ -8,6 +8,8 @@ CFLAGS = -O2 -g
>   quiet-command = $(if $(V),$1,$(if $(2),@printf "  %-7s %s\n" $2 $3 && $1, @$1))
>   cc-option = $(if $(shell $(CC) $1 -S -o /dev/null -xc /dev/null > /dev/null \
>   	      2>&1 && echo OK), $1, $2)
> +cc-c-option = $(if $(shell $(CC) $1 $2 -c -o /dev/null -xc /dev/null \
> +	      >/dev/null 2>&1 && echo OK), $2, $3)
>   
>   VPATH_SUFFIXES = %.c %.h %.S %.m %.mak %.sh %.rc Kconfig% %.json.in
>   set-vpath = $(if $1,$(foreach PATTERN,$(VPATH_SUFFIXES),$(eval vpath $(PATTERN) $1)))
> @@ -30,6 +32,7 @@ OBJECTS = start.o main.o bootmap.o jump2ipl.o sclp.o menu.o \
>   	  virtio.o virtio-scsi.o virtio-blkdev.o libc.o cio.o dasd-ipl.o
>   
>   QEMU_CFLAGS := -Wall $(filter -W%, $(QEMU_CFLAGS))
> +QEMU_CFLAGS += $(call cc-c-option, $(QEMU_CFLAGS), -Wno-stringop-overflow)

  Hi Philippe,

looking at this patch again, I wonder whether it's really necessary to 
introduce the "cc-c-option" macro here? Wouldn't this work with the existing 
"cc-option" macro, too, since it's only about a flag that is used for the 
compiler, and not at the assembler stage?

  Thomas
Thomas Huth May 2, 2021, 11:01 a.m. UTC | #3
On 02/05/2021 12.39, Thomas Huth wrote:
> On 22/04/2021 16.59, Philippe Mathieu-Daudé wrote:
>> When building on Fedora 34 (gcc version 11.0.0 20210210) we get:
>>
>>    In file included from pc-bios/s390-ccw/main.c:11:
>>    In function ‘memset’,
>>        inlined from ‘boot_setup’ at pc-bios/s390-ccw/main.c:185:5,
>>        inlined from ‘main’ at pc-bios/s390-ccw/main.c:288:5:
>>    pc-bios/s390-ccw/libc.h:28:14: warning: writing 1 byte into a region of 
>> size 0 [-Wstringop-overflow=]
>>       28 |         p[i] = c;
>>          |         ~~~~~^~~
>>
>> The offending code is:
>>
>>    memset((char *)S390EP, 0, 6);
>>
>> where S390EP is a const address:
>>
>>    #define S390EP 0x10008
>>
>> The compiler doesn't now how big that pointed area is, so assume its
>> length is zero. This has been reported as BZ#99578 to GCC:
>> "gcc-11 -Warray-bounds or -Wstringop-overread warning when accessing a
>> pointer from integer literal"
>> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99578
>>
>> As this warning does us more harm than good in the BIOS code (where
>> lot of direct accesses to low memory are done), silence this warning
>> for all BIOS objects.
>>
>> Re-introduce the cc-c-option macro (see commit 036999e93e4) to check
>> whether the compiler supports this warning or not.
>>
>> Suggested-by: Thomas Huth <thuth@redhat.com>
>> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
>> ---
>>   pc-bios/s390-ccw/Makefile | 3 +++
>>   1 file changed, 3 insertions(+)
>>
>> diff --git a/pc-bios/s390-ccw/Makefile b/pc-bios/s390-ccw/Makefile
>> index 29fd9019b83..21581d1258d 100644
>> --- a/pc-bios/s390-ccw/Makefile
>> +++ b/pc-bios/s390-ccw/Makefile
>> @@ -8,6 +8,8 @@ CFLAGS = -O2 -g
>>   quiet-command = $(if $(V),$1,$(if $(2),@printf "  %-7s %s\n" $2 $3 && 
>> $1, @$1))
>>   cc-option = $(if $(shell $(CC) $1 -S -o /dev/null -xc /dev/null > 
>> /dev/null \
>>             2>&1 && echo OK), $1, $2)
>> +cc-c-option = $(if $(shell $(CC) $1 $2 -c -o /dev/null -xc /dev/null \
>> +          >/dev/null 2>&1 && echo OK), $2, $3)
>>   VPATH_SUFFIXES = %.c %.h %.S %.m %.mak %.sh %.rc Kconfig% %.json.in
>>   set-vpath = $(if $1,$(foreach PATTERN,$(VPATH_SUFFIXES),$(eval vpath 
>> $(PATTERN) $1)))
>> @@ -30,6 +32,7 @@ OBJECTS = start.o main.o bootmap.o jump2ipl.o sclp.o 
>> menu.o \
>>         virtio.o virtio-scsi.o virtio-blkdev.o libc.o cio.o dasd-ipl.o
>>   QEMU_CFLAGS := -Wall $(filter -W%, $(QEMU_CFLAGS))
>> +QEMU_CFLAGS += $(call cc-c-option, $(QEMU_CFLAGS), -Wno-stringop-overflow)
> 
> Hi Philippe,
> 
> looking at this patch again, I wonder whether it's really necessary to 
> introduce the "cc-c-option" macro here? Wouldn't this work with the existing 
> "cc-option" macro, too, since it's only about a flag that is used for the 
> compiler, and not at the assembler stage?

Darn, that old cc-option macro seems to be broken ... needs to be fixed 
first ... I'll try to come up with a patch.

  Thomas
diff mbox series

Patch

diff --git a/pc-bios/s390-ccw/Makefile b/pc-bios/s390-ccw/Makefile
index 29fd9019b83..21581d1258d 100644
--- a/pc-bios/s390-ccw/Makefile
+++ b/pc-bios/s390-ccw/Makefile
@@ -8,6 +8,8 @@  CFLAGS = -O2 -g
 quiet-command = $(if $(V),$1,$(if $(2),@printf "  %-7s %s\n" $2 $3 && $1, @$1))
 cc-option = $(if $(shell $(CC) $1 -S -o /dev/null -xc /dev/null > /dev/null \
 	      2>&1 && echo OK), $1, $2)
+cc-c-option = $(if $(shell $(CC) $1 $2 -c -o /dev/null -xc /dev/null \
+	      >/dev/null 2>&1 && echo OK), $2, $3)
 
 VPATH_SUFFIXES = %.c %.h %.S %.m %.mak %.sh %.rc Kconfig% %.json.in
 set-vpath = $(if $1,$(foreach PATTERN,$(VPATH_SUFFIXES),$(eval vpath $(PATTERN) $1)))
@@ -30,6 +32,7 @@  OBJECTS = start.o main.o bootmap.o jump2ipl.o sclp.o menu.o \
 	  virtio.o virtio-scsi.o virtio-blkdev.o libc.o cio.o dasd-ipl.o
 
 QEMU_CFLAGS := -Wall $(filter -W%, $(QEMU_CFLAGS))
+QEMU_CFLAGS += $(call cc-c-option, $(QEMU_CFLAGS), -Wno-stringop-overflow)
 QEMU_CFLAGS += -ffreestanding -fno-delete-null-pointer-checks -fno-common -fPIE
 QEMU_CFLAGS += -fwrapv -fno-strict-aliasing -fno-asynchronous-unwind-tables
 QEMU_CFLAGS += $(call cc-option, $(QEMU_CFLAGS), -fno-stack-protector)