public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Pedro Alves <pedro@palves.net>
To: gdb-patches@sourceware.org
Subject: [PATCH 1/3] struct packed: Use gcc_struct on Windows
Date: Thu, 21 Jul 2022 16:21:30 +0100	[thread overview]
Message-ID: <20220721152132.3489524-2-pedro@palves.net> (raw)
In-Reply-To: <20220721152132.3489524-1-pedro@palves.net>

Building GDB on mingw/gcc hosts is currently broken, due to a static
assertion failure in gdbsupport/packed.h:

  In file included from ../../../../../binutils-gdb/gdb/../gdbsupport/common-defs.h:201,
		   from ../../../../../binutils-gdb/gdb/defs.h:28,
		   from ../../../../../binutils-gdb/gdb/dwarf2/read.c:31:
  ../../../../../binutils-gdb/gdb/../gdbsupport/packed.h: In instantiation of 'packed<T, Bytes>::packed(T) [with T = dwarf_unit_type; long long unsigned int Bytes = 1]':
  ../../../../../binutils-gdb/gdb/dwarf2/read.h:181:74:   required from here
  ../../../../../binutils-gdb/gdb/../gdbsupport/packed.h:41:40: error: static assertion failed
     41 |     gdb_static_assert (sizeof (packed) == Bytes);
	|                        ~~~~~~~~~~~~~~~~^~~~~~~~
  ../../../../../binutils-gdb/gdb/../gdbsupport/gdb_assert.h:27:48: note: in definition of macro 'gdb_static_assert'
     27 | #define gdb_static_assert(expr) static_assert (expr, "")
	|                                                ^~~~
  ../../../../../binutils-gdb/gdb/../gdbsupport/packed.h:41:40: note: the comparison reduces to '(4 == 1)'
     41 |     gdb_static_assert (sizeof (packed) == Bytes);
	|                        ~~~~~~~~~~~~~~~~^~~~~~~~


The issue is that mingw gcc defaults to "-mms-bitfields", which
affects how bitfields are laid out.  We can however tell GCC that we
want the regular GCC layout instead using attribute gcc_struct.

Attribute gcc_struct is not implemented in "clang -target
x86_64-pc-windows-gnu", so that will need a different fix.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29373

Change-Id: I023315ee03622c59c397bf4affc0b68179c32374
---
 gdbsupport/packed.h | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/gdbsupport/packed.h b/gdbsupport/packed.h
index 3468cf44207..53164a9e0c3 100644
--- a/gdbsupport/packed.h
+++ b/gdbsupport/packed.h
@@ -27,8 +27,16 @@
    bit-fields (and ENUM_BITFIELD), when the fields must have separate
    memory locations to avoid data races.  */
 
+/* We need gcc_struct on Windows GCC, as otherwise the size of e.g.,
+   "packed<int, 1>" will be larger than what we want.  */
+#if defined _WIN32
+# define ATTRIBUTE_GCC_STRUCT __attribute__((__gcc_struct__))
+#else
+# define ATTRIBUTE_GCC_STRUCT
+#endif
+
 template<typename T, size_t Bytes = sizeof (T)>
-struct packed
+struct ATTRIBUTE_GCC_STRUCT packed
 {
 public:
   packed () noexcept = default;
-- 
2.36.0


  reply	other threads:[~2022-07-21 15:21 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-21 15:21 [PATCH 0/3] struct packed and Windows ports (PR build/29373) Pedro Alves
2022-07-21 15:21 ` Pedro Alves [this message]
2022-07-21 16:03   ` [PATCH 1/3] struct packed: Use gcc_struct on Windows Eli Zaretskii
2022-07-21 17:05     ` Pedro Alves
2022-07-21 17:40       ` Eli Zaretskii
2022-07-21 18:15         ` Pedro Alves
2022-07-21 18:23           ` Eli Zaretskii
2022-07-21 18:30             ` Pedro Alves
2022-07-21 18:45               ` Eli Zaretskii
2022-07-21 18:57                 ` Pedro Alves
2022-07-21 18:18         ` Pedro Alves
2022-07-21 18:28           ` Eli Zaretskii
2022-07-21 18:38             ` Pedro Alves
2022-07-21 15:21 ` [PATCH 2/3] struct packed: Unit tests and more operators Pedro Alves
2022-07-21 15:21 ` [PATCH 3/3] struct packed: Add fallback byte array implementation Pedro Alves
2022-07-25 14:58 ` [PATCH 0/3] struct packed and Windows ports (PR build/29373) Tom Tromey
2022-07-25 15:18   ` Pedro Alves

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220721152132.3489524-2-pedro@palves.net \
    --to=pedro@palves.net \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).