Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [PATCH 0/2] [gdb/build] Two Wstringop-overflow updates
@ 2026-10-28 12:54 Tom de Vries
  2026-10-28 12:54 ` [PATCH 1/2] [gdb/build] Fix Wstringop-overflow in selftests::vex2_to_vex3 Tom de Vries
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Tom de Vries @ 2026-10-28 12:54 UTC (permalink / raw)
  To: gdb-patches

This series contains two patches.

The first fixes a Wstringop-overflow false positive.

The second adds Wno-error=stringop-overflow.

Tom de Vries (2):
  [gdb/build] Fix Wstringop-overflow in selftests::vex2_to_vex3
  [gdb/build] Add Wno-error=stringop-overflow

 gdb/amd64-tdep.c      | 22 +++++++++++++---------
 gdb/configure         |  1 +
 gdbserver/configure   |  1 +
 gdbsupport/configure  |  1 +
 gdbsupport/warning.m4 |  1 +
 5 files changed, 17 insertions(+), 9 deletions(-)


base-commit: 7a593bcacd21f1ae684ed49dc2f8e3ea558c7c64
-- 
2.51.0


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

* [PATCH 1/2] [gdb/build] Fix Wstringop-overflow in selftests::vex2_to_vex3
  2026-10-28 12:54 [PATCH 0/2] [gdb/build] Two Wstringop-overflow updates Tom de Vries
@ 2026-10-28 12:54 ` Tom de Vries
  2026-10-28 12:54 ` [PATCH 2/2] [gdb/build] Add Wno-error=stringop-overflow Tom de Vries
  2026-10-28 16:23 ` [PATCH 0/2] [gdb/build] Two Wstringop-overflow updates Tom Tromey
  2 siblings, 0 replies; 5+ messages in thread
From: Tom de Vries @ 2026-10-28 12:54 UTC (permalink / raw)
  To: gdb-patches

When building gdb with -O3 on x86_64-linux, I run into:
...
    inlined from ‘void std::vector<_Tp, _Alloc>::resize(size_type) [with _Tp = unsigned char; _Alloc = gdb::default_init_allocator<unsigned char, std::allocator<unsigned char> >]’ at /usr/include/c++/15/bits/stl_vector.h:1146:21,
    inlined from ‘void selftests::vex2_to_vex3(gdb::byte_vector&, gdb::byte_vector&)’ at /data/vries/gdb/leap-16-0/build/../../src/gdb/amd64-tdep.c:3896:15:
/usr/include/c++/15/bits/new_allocator.h:191:11: warning: writing 8 bytes into a region of size between 1 and 5 [-Wstringop-overflow=]
  191 |         { ::new((void *)__p) _Up(std::forward<_Args>(__args)...); }
      |           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
...

The warning complains about this resize:
...
  vex3.resize (3);
  vex3[0] = 0xc4;
  vex3[1] = (r << 7) | (x << 6) | (b << 5) | m;
  vex3[2] = (vex2[1] & ~0x80) | (w << 7);
...

This is a false positive [1].

Get rid of the warning by using std::vector<gdb_byte> instead.  The only
difference is default initialization, and for small vectors that doesn't
matter.

[1] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106093
---
 gdb/amd64-tdep.c | 22 +++++++++++++---------
 1 file changed, 13 insertions(+), 9 deletions(-)

diff --git a/gdb/amd64-tdep.c b/gdb/amd64-tdep.c
index 18b8f2a4c0b..27491cb995c 100644
--- a/gdb/amd64-tdep.c
+++ b/gdb/amd64-tdep.c
@@ -3877,12 +3877,15 @@ amd64_target_description (uint64_t xstate_bv, bool segments)
 
 #if GDB_SELF_TEST
 
+/* We're using std::vector<gdb_byte> instead of gdb::byte_vector here to work
+   around Wstringop-overflow false positives (PR gcc/106093).  */
+
 namespace selftests {
 
 /* Recode a vex2 instruction into a vex3 instruction.  */
 
 static void
-vex2_to_vex3 (gdb::byte_vector &vex2, gdb::byte_vector &vex3)
+vex2_to_vex3 (std::vector<gdb_byte> &vex2, std::vector<gdb_byte> &vex3)
 {
   gdb_assert (vex2.size () >= 2);
   gdb_assert (vex2[0] == 0xc5);
@@ -3908,13 +3911,13 @@ static void
 test_vex2_to_vex3 (void)
 {
   /* INSN: vzeroall, vex2 prefix.  */
-  gdb::byte_vector vex2 = { 0xc5, 0xfc, 0x77 };
+  std::vector<gdb_byte> vex2 = { 0xc5, 0xfc, 0x77 };
 
-  gdb::byte_vector vex3;
+  std::vector<gdb_byte> vex3;
   vex2_to_vex3 (vex2, vex3);
 
   /* INSN: vzeroall, vex3 prefix.  */
-  gdb::byte_vector vex3_ref = { 0xc4, 0xe1, 0x7c, 0x77 };
+  std::vector<gdb_byte> vex3_ref = { 0xc4, 0xe1, 0x7c, 0x77 };
   SELF_CHECK (vex3 == vex3_ref);
 }
 
@@ -3924,7 +3927,7 @@ static void
 test_amd64_get_insn_details (void)
 {
   struct amd64_insn details;
-  gdb::byte_vector insn, tmp;
+  std::vector<gdb_byte> insn, tmp;
 
   /* INSN: add %eax,(%rcx).  */
   insn = { 0x01, 0x01 };
@@ -3961,11 +3964,12 @@ test_amd64_get_insn_details (void)
   SELF_CHECK (rip_relative_offset (&details) == 3);
 
   /* INSN: lea 0x1e(%ecx),%rdi, rex prefix.  */
-  gdb::byte_vector updated_insn = { 0x48, 0x8d, 0xb9, 0x1e, 0x00, 0x00, 0x00 };
+  std::vector<gdb_byte> updated_insn
+    = { 0x48, 0x8d, 0xb9, 0x1e, 0x00, 0x00, 0x00 };
   fixup_riprel (details, insn.data (), ECX_REG_NUM);
   SELF_CHECK (insn == updated_insn);
 
-  gdb::byte_vector vex2, vex3;
+  std::vector<gdb_byte> vex2, vex3;
 
   /* INSN: vzeroall, vex2 prefix.  */
   vex2 = { 0xc5, 0xfc, 0x77 };
@@ -4008,7 +4012,7 @@ test_amd64_get_insn_details (void)
   SELF_CHECK (details.modrm_offset == 3);
 
   /* INSN: vmovdqu 0x9(%rcx),%ymm3, vex2 prefix.  */
-  gdb::byte_vector updated_vex2
+  std::vector<gdb_byte> updated_vex2
     = { 0xc5, 0xfe, 0x6f, 0x99, 0x09, 0x00, 0x00, 0x00 };
   tmp = vex2;
   fixup_riprel (details, tmp.data (), ECX_REG_NUM);
@@ -4023,7 +4027,7 @@ test_amd64_get_insn_details (void)
   SELF_CHECK (details.modrm_offset == 4);
 
   /* INSN: vmovdqu 0x9(%rcx),%ymm3, vex3 prefix.  */
-  gdb::byte_vector updated_vex3;
+  std::vector<gdb_byte> updated_vex3;
   vex2_to_vex3 (updated_vex2, updated_vex3);
   tmp = vex3;
   fixup_riprel (details, tmp.data (), ECX_REG_NUM);
-- 
2.51.0


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

* [PATCH 2/2] [gdb/build] Add Wno-error=stringop-overflow
  2026-10-28 12:54 [PATCH 0/2] [gdb/build] Two Wstringop-overflow updates Tom de Vries
  2026-10-28 12:54 ` [PATCH 1/2] [gdb/build] Fix Wstringop-overflow in selftests::vex2_to_vex3 Tom de Vries
@ 2026-10-28 12:54 ` Tom de Vries
  2026-10-28 16:23 ` [PATCH 0/2] [gdb/build] Two Wstringop-overflow updates Tom Tromey
  2 siblings, 0 replies; 5+ messages in thread
From: Tom de Vries @ 2026-10-28 12:54 UTC (permalink / raw)
  To: gdb-patches

Add Wno-error=stringop-overflow to the build warning setup, to account for the
fact that it's likely to have false positives [1].

[1] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88443
---
 gdb/configure         | 1 +
 gdbserver/configure   | 1 +
 gdbsupport/configure  | 1 +
 gdbsupport/warning.m4 | 1 +
 4 files changed, 4 insertions(+)

diff --git a/gdb/configure b/gdb/configure
index e747ffce49f..76ad40871a9 100755
--- a/gdb/configure
+++ b/gdb/configure
@@ -31159,6 +31159,7 @@ build_warnings=" \
 -Wmissing-declarations \
 -Wno-char-subscripts \
 -Wno-error=deprecated-register \
+-Wno-error=stringop-overflow \
 -Wno-mismatched-tags \
 -Wno-sign-compare -Wno-error=maybe-uninitialized \
 -Wno-switch \
diff --git a/gdbserver/configure b/gdbserver/configure
index e00e1e1c1c5..6c24a7b8fc0 100755
--- a/gdbserver/configure
+++ b/gdbserver/configure
@@ -12889,6 +12889,7 @@ build_warnings=" \
 -Wmissing-declarations \
 -Wno-char-subscripts \
 -Wno-error=deprecated-register \
+-Wno-error=stringop-overflow \
 -Wno-mismatched-tags \
 -Wno-sign-compare -Wno-error=maybe-uninitialized \
 -Wno-switch \
diff --git a/gdbsupport/configure b/gdbsupport/configure
index 7ed4e259ffe..882b91017ab 100755
--- a/gdbsupport/configure
+++ b/gdbsupport/configure
@@ -13892,6 +13892,7 @@ build_warnings=" \
 -Wmissing-declarations \
 -Wno-char-subscripts \
 -Wno-error=deprecated-register \
+-Wno-error=stringop-overflow \
 -Wno-mismatched-tags \
 -Wno-sign-compare -Wno-error=maybe-uninitialized \
 -Wno-switch \
diff --git a/gdbsupport/warning.m4 b/gdbsupport/warning.m4
index 3148feb740a..558fd2177da 100644
--- a/gdbsupport/warning.m4
+++ b/gdbsupport/warning.m4
@@ -47,6 +47,7 @@ build_warnings=" \
 -Wmissing-declarations \
 -Wno-char-subscripts \
 -Wno-error=deprecated-register \
+-Wno-error=stringop-overflow \
 -Wno-mismatched-tags \
 -Wno-sign-compare -Wno-error=maybe-uninitialized \
 -Wno-switch \
-- 
2.51.0


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

* Re: [PATCH 0/2] [gdb/build] Two Wstringop-overflow updates
  2026-10-28 12:54 [PATCH 0/2] [gdb/build] Two Wstringop-overflow updates Tom de Vries
  2026-10-28 12:54 ` [PATCH 1/2] [gdb/build] Fix Wstringop-overflow in selftests::vex2_to_vex3 Tom de Vries
  2026-10-28 12:54 ` [PATCH 2/2] [gdb/build] Add Wno-error=stringop-overflow Tom de Vries
@ 2026-10-28 16:23 ` Tom Tromey
  2026-10-28 23:15   ` Tom de Vries
  2 siblings, 1 reply; 5+ messages in thread
From: Tom Tromey @ 2026-10-28 16:23 UTC (permalink / raw)
  To: Tom de Vries; +Cc: gdb-patches

>>>>> "Tom" == Tom de Vries <tdevries@suse.de> writes:

Tom> This series contains two patches.
Tom> The first fixes a Wstringop-overflow false positive.

What if we just disable this warning?
It seems like a fairly fragile warning without a big upside.

Tom

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

* Re: [PATCH 0/2] [gdb/build] Two Wstringop-overflow updates
  2026-10-28 16:23 ` [PATCH 0/2] [gdb/build] Two Wstringop-overflow updates Tom Tromey
@ 2026-10-28 23:15   ` Tom de Vries
  0 siblings, 0 replies; 5+ messages in thread
From: Tom de Vries @ 2026-10-28 23:15 UTC (permalink / raw)
  To: Tom Tromey; +Cc: gdb-patches

On 10/28/26 5:23 PM, Tom Tromey wrote:
>>>>>> "Tom" == Tom de Vries <tdevries@suse.de> writes:
> 
> Tom> This series contains two patches.
> Tom> The first fixes a Wstringop-overflow false positive.
> 
> What if we just disable this warning?
> It seems like a fairly fragile warning without a big upside.

I'll try to send a patch using that approach tomorrow.

Thanks,
- Tom

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

end of thread, other threads:[~2026-10-28 23:16 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-28 12:54 [PATCH 0/2] [gdb/build] Two Wstringop-overflow updates Tom de Vries
2026-10-28 12:54 ` [PATCH 1/2] [gdb/build] Fix Wstringop-overflow in selftests::vex2_to_vex3 Tom de Vries
2026-10-28 12:54 ` [PATCH 2/2] [gdb/build] Add Wno-error=stringop-overflow Tom de Vries
2026-10-28 16:23 ` [PATCH 0/2] [gdb/build] Two Wstringop-overflow updates Tom Tromey
2026-10-28 23:15   ` Tom de Vries

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox