From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr1-f45.google.com (mail-wr1-f45.google.com [209.85.221.45]) by sourceware.org (Postfix) with ESMTPS id 9237D384D1A3 for ; Thu, 21 Jul 2022 15:21:39 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 9237D384D1A3 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=palves.net Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-wr1-f45.google.com with SMTP id bu1so2745041wrb.9 for ; Thu, 21 Jul 2022 08:21:39 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ErlVMSV80yi5DEXsiAg0pbuCY67Aiz5biiI1M55pY2Q=; b=Rfru0aP3BJxYpUCbJ7SGAxWnFxokQFWttJLo2Y5ApHod8/znZmrqt/MJzCvG58o+D6 IiPMwwS89YuzNL1WoANmaW6dAaqzeuqR7okCixgyy4+yU2RRunKFyMIVb3jiNqUS3Fxn Xnw4Ar/DEWBNGOj+iGUoZVyju+isjdS7hPyviep2HwKKvpgK1VwaMw1qZapf4fHqkcTy xYohLO1tE1ksPq2ndQkJN7GMTWz1O5G4cHPQfrkgbbrii6qYj//j9yt0FjUIkQRQG5G/ vKLtZHwVJn24X1ckrzi9ObU3KtLB5gznVstdlu1qJ6C77OA1HPsQlV8xE9xYq/dC1x33 rhTQ== X-Gm-Message-State: AJIora9YpvWgL6CP8JcQkfYtk+2sDko0tXodVjMxHMBePv7WHKmH4Idq /I3vl63erCWADt8qCumg/g9gjqaCcFA= X-Google-Smtp-Source: AGRyM1vH3MmzYC14xILBbUqjGQv3R/nkrid5eiWDIJiEi7PbKGNSm2RwUtnd07WXxFnrtYOj7oj2Kw== X-Received: by 2002:a05:6000:1686:b0:21d:6e46:2fa with SMTP id y6-20020a056000168600b0021d6e4602famr34739745wrd.691.1658416897690; Thu, 21 Jul 2022 08:21:37 -0700 (PDT) Received: from localhost ([2001:8a0:f924:2600:209d:85e2:409e:8726]) by smtp.gmail.com with ESMTPSA id c15-20020adfe70f000000b0021bbf6687b1sm2757004wrm.81.2022.07.21.08.21.36 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 21 Jul 2022 08:21:36 -0700 (PDT) From: Pedro Alves 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 Message-Id: <20220721152132.3489524-2-pedro@palves.net> X-Mailer: git-send-email 2.36.0 In-Reply-To: <20220721152132.3489524-1-pedro@palves.net> References: <20220721152132.3489524-1-pedro@palves.net> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-9.9 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 21 Jul 2022 15:21:41 -0000 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::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" 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 = default; -- 2.36.0