summaryrefslogtreecommitdiff
path: root/gdbsupport
diff options
context:
space:
mode:
authorPedro Alves <pedro@palves.net>2022-07-19 00:26:33 +0100
committerPedro Alves <pedro@palves.net>2022-07-25 16:04:05 +0100
commit4ca26ad7dec88ab6fa8507ba069e9f1b3c5196da (patch)
treefa700e4b28e26409d03dac0dc187f73565f00c55 /gdbsupport
parentf7f904e4fda6fb571d40a3547ed03ec6028e6694 (diff)
downloadbinutils-gdb-4ca26ad7dec88ab6fa8507ba069e9f1b3c5196da.tar.gz
struct packed: Use gcc_struct on Windows
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
Diffstat (limited to 'gdbsupport')
-rw-r--r--gdbsupport/packed.h10
1 files changed, 9 insertions, 1 deletions
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;