public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCHv2] gdb: Ignore some stringop-overflow and restrict warnings on sparc
@ 2023-01-24  0:44 Mark Wielaard
  2023-01-24  3:32 ` Enze Li
  2023-01-24 15:25 ` Tom Tromey
  0 siblings, 2 replies; 8+ messages in thread
From: Mark Wielaard @ 2023-01-24  0:44 UTC (permalink / raw)
  To: gdb-patches; +Cc: Simon Marchi, Sam James, Mark Wielaard

For some reason g++ 12.2.1 on sparc produces a spurious warning for
stringop-overread and restrict in fbsd-tdep.c for some memcpy calls.
Add new DIAGNOSTIC_IGNORE_STRINGOP_OVERFLOW and
DIAGNOSTIC_IGNORE_RESTRICT macro to suppress these warnings:

In function ‘void* memcpy(void*, const void*, size_t)’,
    inlined from ‘gdb::optional<std::vector<unsigned char, gdb::default_init_allocator<unsigned char, std::allocator<unsigned char> > > > fbsd_make_note_desc(target_object, uint32_t)’ at ../../binutils-gdb/gdb/fbsd-tdep.c:666:10:
/usr/include/bits/string_fortified.h:29:33: error: ‘void* __builtin_memcpy(void*, const void*, long unsigned int)’ specified bound 18446744073709551612 exceeds maximum object size 9223372036854775807 [-Werror=stringop-overflow=]

In function ‘void* memcpy(void*, const void*, size_t)’,
    inlined from ‘gdb::optional<std::vector<unsigned char, gdb::default_init_allocator<unsigned char, std::allocator<unsigned char> > > > fbsd_make_note_desc(target_object, uint32_t)’ at ../../binutils-gdb/gdb/fbsd-tdep.c:673:10:
/usr/include/bits/string_fortified.h:29:33: error: ‘void* __builtin_memcpy(void*, const void*, long unsigned int)’ accessing 18446744073709551612 bytes at offsets 0 and 0 overlaps 9223372036854775801 bytes at offset -9223372036854775805 [-Werror=restrict]

include/ChangeLog:

	* diagnostics.h (DIAGNOSTIC_IGNORE_STRINGOP_OVERFLOW): New
	macro.
	(DIAGNOSTIC_IGNORE_RESTRICT): Likewise.

gdb/ChangeLog:

	* fbsd-tdep.c (fbsd_make_note_desc): Use
	DIAGNOSTIC_IGNORE_STRINGOP_OVERFLOW and
	DIAGNOSTIC_IGNORE_RESTRICT on sparc.
---

V2: Fix typos and add example errors to commit messages

 gdb/fbsd-tdep.c       | 10 ++++++++++
 include/diagnostics.h | 10 ++++++++++
 2 files changed, 20 insertions(+)

diff --git a/gdb/fbsd-tdep.c b/gdb/fbsd-tdep.c
index 203390d9880..ee2a4b54e85 100644
--- a/gdb/fbsd-tdep.c
+++ b/gdb/fbsd-tdep.c
@@ -19,6 +19,7 @@
 
 #include "defs.h"
 #include "auxv.h"
+#include "diagnostics.h"
 #include "gdbcore.h"
 #include "inferior.h"
 #include "objfiles.h"
@@ -663,7 +664,16 @@ fbsd_make_note_desc (enum target_object object, uint32_t structsize)
 
   gdb::byte_vector desc (sizeof (structsize) + buf->size ());
   memcpy (desc.data (), &structsize, sizeof (structsize));
+#if defined (__sparc__)
+  /* g++ 12.2.1 on sparc seems confused about the vector buf sizes.  */
+  DIAGNOSTIC_PUSH
+  DIAGNOSTIC_IGNORE_STRINGOP_OVERFLOW
+  DIAGNOSTIC_IGNORE_RESTRICT
+#endif
   memcpy (desc.data () + sizeof (structsize), buf->data (), buf->size ());
+#if defined (__sparc__)
+  DIAGNOSTIC_POP
+#endif
   return desc;
 }
 
diff --git a/include/diagnostics.h b/include/diagnostics.h
index d3ff27bc008..617943ae0d7 100644
--- a/include/diagnostics.h
+++ b/include/diagnostics.h
@@ -94,6 +94,11 @@
   DIAGNOSTIC_IGNORE ("-Wstringop-overread")
 #endif
 
+# if __GNUC__ >= 7
+# define DIAGNOSTIC_IGNORE_STRINGOP_OVERFLOW \
+  DIAGNOSTIC_IGNORE ("-Wstringop-overflow")
+#endif
+
 # define DIAGNOSTIC_IGNORE_FORMAT_NONLITERAL \
   DIAGNOSTIC_IGNORE ("-Wformat-nonliteral")
 
@@ -113,6 +118,7 @@
 #  define DIAGNOSTIC_ERROR_SWITCH DIAGNOSTIC_ERROR ("-Wswitch")
 # endif
 
+#define DIAGNOSTIC_IGNORE_RESTRICT DIAGNOSTIC_IGNORE ("-Wrestrict")
 #endif
 
 #ifndef DIAGNOSTIC_IGNORE_SELF_MOVE
@@ -139,6 +145,10 @@
 # define DIAGNOSTIC_IGNORE_STRINGOP_OVERREAD
 #endif
 
+#ifndef DIAGNOSTIC_IGNORE_STRINGOP_OVERFLOW
+# define DIAGNOSTIC_IGNORE_STRINGOP_OVERFLOW
+#endif
+
 #ifndef DIAGNOSTIC_IGNORE_FORMAT_NONLITERAL
 # define DIAGNOSTIC_IGNORE_FORMAT_NONLITERAL
 #endif
-- 
2.31.1


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCHv2] gdb: Ignore some stringop-overflow and restrict warnings on sparc
  2023-01-24  0:44 [PATCHv2] gdb: Ignore some stringop-overflow and restrict warnings on sparc Mark Wielaard
@ 2023-01-24  3:32 ` Enze Li
  2023-01-24  9:35   ` Mark Wielaard
  2023-01-24 15:19   ` Tom Tromey
  2023-01-24 15:25 ` Tom Tromey
  1 sibling, 2 replies; 8+ messages in thread
From: Enze Li @ 2023-01-24  3:32 UTC (permalink / raw)
  To: Mark Wielaard; +Cc: gdb-patches, Simon Marchi, Sam James

On Tue, Jan 24 2023 at 01:44:44 AM +0100, Mark Wielaard wrote:

> For some reason g++ 12.2.1 on sparc produces a spurious warning for
> stringop-overread and restrict in fbsd-tdep.c for some memcpy calls.
> Add new DIAGNOSTIC_IGNORE_STRINGOP_OVERFLOW and
> DIAGNOSTIC_IGNORE_RESTRICT macro to suppress these warnings:
>
> In function ‘void* memcpy(void*, const void*, size_t)’,
>     inlined from ‘gdb::optional<std::vector<unsigned char, gdb::default_init_allocator<unsigned char, std::allocator<unsigned char> > > > fbsd_make_note_desc(target_object, uint32_t)’ at ../../binutils-gdb/gdb/fbsd-tdep.c:666:10:
> /usr/include/bits/string_fortified.h:29:33: error: ‘void* __builtin_memcpy(void*, const void*, long unsigned int)’ specified bound 18446744073709551612 exceeds maximum object size 9223372036854775807 [-Werror=stringop-overflow=]
>
> In function ‘void* memcpy(void*, const void*, size_t)’,
>     inlined from ‘gdb::optional<std::vector<unsigned char, gdb::default_init_allocator<unsigned char, std::allocator<unsigned char> > > > fbsd_make_note_desc(target_object, uint32_t)’ at ../../binutils-gdb/gdb/fbsd-tdep.c:673:10:
> /usr/include/bits/string_fortified.h:29:33: error: ‘void* __builtin_memcpy(void*, const void*, long unsigned int)’ accessing 18446744073709551612 bytes at offsets 0 and 0 overlaps 9223372036854775801 bytes at offset -9223372036854775805 [-Werror=restrict]
>
> include/ChangeLog:
>
> 	* diagnostics.h (DIAGNOSTIC_IGNORE_STRINGOP_OVERFLOW): New
> 	macro.
> 	(DIAGNOSTIC_IGNORE_RESTRICT): Likewise.
>
> gdb/ChangeLog:
>
> 	* fbsd-tdep.c (fbsd_make_note_desc): Use
> 	DIAGNOSTIC_IGNORE_STRINGOP_OVERFLOW and
> 	DIAGNOSTIC_IGNORE_RESTRICT on sparc.
> ---

Hi Mark,

Since GDB 12, ChangeLog entries are no longer required.  See here[1].

[1] https://sourceware.org/pipermail/gdb-patches/2021-June/179872.html

Thanks,
Enze

>
> V2: Fix typos and add example errors to commit messages
>
>  gdb/fbsd-tdep.c       | 10 ++++++++++
>  include/diagnostics.h | 10 ++++++++++
>  2 files changed, 20 insertions(+)
>
> diff --git a/gdb/fbsd-tdep.c b/gdb/fbsd-tdep.c
> index 203390d9880..ee2a4b54e85 100644
> --- a/gdb/fbsd-tdep.c
> +++ b/gdb/fbsd-tdep.c
> @@ -19,6 +19,7 @@
>  
>  #include "defs.h"
>  #include "auxv.h"
> +#include "diagnostics.h"
>  #include "gdbcore.h"
>  #include "inferior.h"
>  #include "objfiles.h"
> @@ -663,7 +664,16 @@ fbsd_make_note_desc (enum target_object object, uint32_t structsize)
>  
>    gdb::byte_vector desc (sizeof (structsize) + buf->size ());
>    memcpy (desc.data (), &structsize, sizeof (structsize));
> +#if defined (__sparc__)
> +  /* g++ 12.2.1 on sparc seems confused about the vector buf sizes.  */
> +  DIAGNOSTIC_PUSH
> +  DIAGNOSTIC_IGNORE_STRINGOP_OVERFLOW
> +  DIAGNOSTIC_IGNORE_RESTRICT
> +#endif
>    memcpy (desc.data () + sizeof (structsize), buf->data (), buf->size ());
> +#if defined (__sparc__)
> +  DIAGNOSTIC_POP
> +#endif
>    return desc;
>  }
>  
> diff --git a/include/diagnostics.h b/include/diagnostics.h
> index d3ff27bc008..617943ae0d7 100644
> --- a/include/diagnostics.h
> +++ b/include/diagnostics.h
> @@ -94,6 +94,11 @@
>    DIAGNOSTIC_IGNORE ("-Wstringop-overread")
>  #endif
>  
> +# if __GNUC__ >= 7
> +# define DIAGNOSTIC_IGNORE_STRINGOP_OVERFLOW \
> +  DIAGNOSTIC_IGNORE ("-Wstringop-overflow")
> +#endif
> +
>  # define DIAGNOSTIC_IGNORE_FORMAT_NONLITERAL \
>    DIAGNOSTIC_IGNORE ("-Wformat-nonliteral")
>  
> @@ -113,6 +118,7 @@
>  #  define DIAGNOSTIC_ERROR_SWITCH DIAGNOSTIC_ERROR ("-Wswitch")
>  # endif
>  
> +#define DIAGNOSTIC_IGNORE_RESTRICT DIAGNOSTIC_IGNORE ("-Wrestrict")
>  #endif
>  
>  #ifndef DIAGNOSTIC_IGNORE_SELF_MOVE
> @@ -139,6 +145,10 @@
>  # define DIAGNOSTIC_IGNORE_STRINGOP_OVERREAD
>  #endif
>  
> +#ifndef DIAGNOSTIC_IGNORE_STRINGOP_OVERFLOW
> +# define DIAGNOSTIC_IGNORE_STRINGOP_OVERFLOW
> +#endif
> +
>  #ifndef DIAGNOSTIC_IGNORE_FORMAT_NONLITERAL
>  # define DIAGNOSTIC_IGNORE_FORMAT_NONLITERAL
>  #endif

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCHv2] gdb: Ignore some stringop-overflow and restrict warnings on sparc
  2023-01-24  3:32 ` Enze Li
@ 2023-01-24  9:35   ` Mark Wielaard
  2023-01-24 15:25     ` Tom Tromey
  2023-01-24 15:19   ` Tom Tromey
  1 sibling, 1 reply; 8+ messages in thread
From: Mark Wielaard @ 2023-01-24  9:35 UTC (permalink / raw)
  To: Enze Li; +Cc: gdb-patches, Simon Marchi, Sam James

Hi Enze,

On Tue, Jan 24, 2023 at 11:32:32AM +0800, Enze Li wrote:
> On Tue, Jan 24 2023 at 01:44:44 AM +0100, Mark Wielaard wrote:
> > include/ChangeLog:
> >
> > 	* diagnostics.h (DIAGNOSTIC_IGNORE_STRINGOP_OVERFLOW): New
> > 	macro.
> > 	(DIAGNOSTIC_IGNORE_RESTRICT): Likewise.
> >
> > gdb/ChangeLog:
> >
> > 	* fbsd-tdep.c (fbsd_make_note_desc): Use
> > 	DIAGNOSTIC_IGNORE_STRINGOP_OVERFLOW and
> > 	DIAGNOSTIC_IGNORE_RESTRICT on sparc.
> > ---
> 
> Since GDB 12, ChangeLog entries are no longer required.  See here[1].
> 
> [1] https://sourceware.org/pipermail/gdb-patches/2021-June/179872.html

Ah, too bad :{ I really like ChangeLog entries for (self) review of
patches. Do you want me to post a V3 without them?

Thanks,

Mark

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCHv2] gdb: Ignore some stringop-overflow and restrict warnings on sparc
  2023-01-24  3:32 ` Enze Li
  2023-01-24  9:35   ` Mark Wielaard
@ 2023-01-24 15:19   ` Tom Tromey
  2023-01-24 15:22     ` Tom Tromey
  1 sibling, 1 reply; 8+ messages in thread
From: Tom Tromey @ 2023-01-24 15:19 UTC (permalink / raw)
  To: Enze Li via Gdb-patches; +Cc: Mark Wielaard, Enze Li, Simon Marchi, Sam James

>>>>> "Enze" == Enze Li via Gdb-patches <gdb-patches@sourceware.org> writes:

Enze> Since GDB 12, ChangeLog entries are no longer required.  See here[1].
Enze> [1] https://sourceware.org/pipermail/gdb-patches/2021-June/179872.html

They might be for include/ since it's shared with gcc.

Can we even approve changes to include/diagnostics.h, or does it need to
go via gcc first?  I don't really recall the status of this.

Tom

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCHv2] gdb: Ignore some stringop-overflow and restrict warnings on sparc
  2023-01-24 15:19   ` Tom Tromey
@ 2023-01-24 15:22     ` Tom Tromey
  0 siblings, 0 replies; 8+ messages in thread
From: Tom Tromey @ 2023-01-24 15:22 UTC (permalink / raw)
  To: Tom Tromey
  Cc: Enze Li via Gdb-patches, Mark Wielaard, Enze Li, Simon Marchi, Sam James

Tom> Can we even approve changes to include/diagnostics.h, or does it need to
Tom> go via gcc first?  I don't really recall the status of this.

Oh, never mind, diagnostic.h isn't actually in gcc.

Tom

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCHv2] gdb: Ignore some stringop-overflow and restrict warnings on sparc
  2023-01-24  0:44 [PATCHv2] gdb: Ignore some stringop-overflow and restrict warnings on sparc Mark Wielaard
  2023-01-24  3:32 ` Enze Li
@ 2023-01-24 15:25 ` Tom Tromey
  2023-01-24 19:26   ` Mark Wielaard
  1 sibling, 1 reply; 8+ messages in thread
From: Tom Tromey @ 2023-01-24 15:25 UTC (permalink / raw)
  To: Mark Wielaard; +Cc: gdb-patches, Simon Marchi, Sam James

>>>>> "Mark" == Mark Wielaard <mark@klomp.org> writes:

Mark> For some reason g++ 12.2.1 on sparc produces a spurious warning for
Mark> stringop-overread and restrict in fbsd-tdep.c for some memcpy calls.
Mark> Add new DIAGNOSTIC_IGNORE_STRINGOP_OVERFLOW and
Mark> DIAGNOSTIC_IGNORE_RESTRICT macro to suppress these warnings:

Mark>    gdb::byte_vector desc (sizeof (structsize) + buf->size ());
Mark>    memcpy (desc.data (), &structsize, sizeof (structsize));
Mark> +#if defined (__sparc__)
Mark> +  /* g++ 12.2.1 on sparc seems confused about the vector buf sizes.  */
Mark> +  DIAGNOSTIC_PUSH
Mark> +  DIAGNOSTIC_IGNORE_STRINGOP_OVERFLOW
Mark> +  DIAGNOSTIC_IGNORE_RESTRICT
Mark> +#endif
Mark>    memcpy (desc.data () + sizeof (structsize), buf->data (), buf->size ());
Mark> +#if defined (__sparc__)
Mark> +  DIAGNOSTIC_POP
Mark> +#endif

Is there any chance that std::copy or std::memmove would avoid the
warning?  It would be nice if this could be fixed without having to add
a bunch of #if goo.

However, if not, this is ok.

Tom

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCHv2] gdb: Ignore some stringop-overflow and restrict warnings on sparc
  2023-01-24  9:35   ` Mark Wielaard
@ 2023-01-24 15:25     ` Tom Tromey
  0 siblings, 0 replies; 8+ messages in thread
From: Tom Tromey @ 2023-01-24 15:25 UTC (permalink / raw)
  To: Mark Wielaard; +Cc: Enze Li, gdb-patches, Simon Marchi, Sam James

>>>>> "Mark" == Mark Wielaard <mark@klomp.org> writes:

Mark> Ah, too bad :{ I really like ChangeLog entries for (self) review of
Mark> patches. Do you want me to post a V3 without them?

No need to repost.
You should probably leave include/ChangeLog in place.

Tom

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCHv2] gdb: Ignore some stringop-overflow and restrict warnings on sparc
  2023-01-24 15:25 ` Tom Tromey
@ 2023-01-24 19:26   ` Mark Wielaard
  0 siblings, 0 replies; 8+ messages in thread
From: Mark Wielaard @ 2023-01-24 19:26 UTC (permalink / raw)
  To: Tom Tromey; +Cc: gdb-patches, Simon Marchi, Sam James

Hi Tom,

On Tue, Jan 24, 2023 at 08:25:13AM -0700, Tom Tromey wrote:
> Is there any chance that std::copy or std::memmove would avoid the
> warning?  It would be nice if this could be fixed without having to add
> a bunch of #if goo.

memmove also doesn't work since although this would resolve the
overlapping confusion, gcc still believes specified bound
18446744073709551612 exceeds maximum object size 9223372036854775807.

But it looks like the std::copy approach does just compile without
issue. I'll sent a v3.

Thanks,

Mark

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2023-01-24 19:26 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-24  0:44 [PATCHv2] gdb: Ignore some stringop-overflow and restrict warnings on sparc Mark Wielaard
2023-01-24  3:32 ` Enze Li
2023-01-24  9:35   ` Mark Wielaard
2023-01-24 15:25     ` Tom Tromey
2023-01-24 15:19   ` Tom Tromey
2023-01-24 15:22     ` Tom Tromey
2023-01-24 15:25 ` Tom Tromey
2023-01-24 19:26   ` Mark Wielaard

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).