From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1551) id 8894C3857809; Mon, 25 Jul 2022 15:12:10 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8894C3857809 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Pedro Alves To: gdb-cvs@sourceware.org Subject: [binutils-gdb] struct packed: Use gcc_struct on Windows X-Act-Checkin: binutils-gdb X-Git-Author: Pedro Alves X-Git-Refname: refs/heads/master X-Git-Oldrev: f7f904e4fda6fb571d40a3547ed03ec6028e6694 X-Git-Newrev: 4ca26ad7dec88ab6fa8507ba069e9f1b3c5196da Message-Id: <20220725151210.8894C3857809@sourceware.org> Date: Mon, 25 Jul 2022 15:12:10 +0000 (GMT) X-BeenThere: gdb-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 25 Jul 2022 15:12:10 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D4ca26ad7dec8= 8ab6fa8507ba069e9f1b3c5196da commit 4ca26ad7dec88ab6fa8507ba069e9f1b3c5196da Author: Pedro Alves Date: Tue Jul 19 00:26:33 2022 +0100 struct packed: Use gcc_struct on Windows =20 Building GDB on mingw/gcc hosts is currently broken, due to a static assertion failure in gdbsupport/packed.h: =20 In file included from ../../../../../binutils-gdb/gdb/../gdbsupport/c= ommon-defs.h:201, from ../../../../../binutils-gdb/gdb/defs.h:28, from ../../../../../binutils-gdb/gdb/dwarf2/read.c:3= 1: ../../../../../binutils-gdb/gdb/../gdbsupport/packed.h: In instantiat= ion of 'packed::packed(T) [with T =3D dwarf_unit_type; long long = unsigned int Bytes =3D 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) =3D=3D Bytes); | ~~~~~~~~~~~~~~~~^~~~~~~~ ../../../../../binutils-gdb/gdb/../gdbsupport/gdb_assert.h:27:48: not= e: 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: t= he comparison reduces to '(4 =3D=3D 1)' 41 | gdb_static_assert (sizeof (packed) =3D=3D Bytes); | ~~~~~~~~~~~~~~~~^~~~~~~~ =20 =20 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. =20 Attribute gcc_struct is not implemented in "clang -target x86_64-pc-windows-gnu", so that will need a different fix. =20 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=3D29373 =20 Change-Id: I023315ee03622c59c397bf4affc0b68179c32374 Diff: --- 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. */ =20 +/* We need gcc_struct on Windows GCC, as otherwise the size of e.g., + "packed" will be larger than what we want. */ +#if defined _WIN32 +# define ATTRIBUTE_GCC_STRUCT __attribute__((__gcc_struct__)) +#else +# define ATTRIBUTE_GCC_STRUCT +#endif + template -struct packed +struct ATTRIBUTE_GCC_STRUCT packed { public: packed () noexcept =3D default;