From nobody Sun Apr 6 22:04:08 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1736541323; cv=none; d=zohomail.com; s=zohoarc; b=lDDb2pIv1BrcvaYxfFZQDIkP/kRtJo7gl6a1A98eQUqSmTY2hiZnBc3UN4yeglfI1k3Xl7Eh2iYZ5Ap4Pdo6znn1u0lCFvU9XZtl0Czi1u9y9kWmC+WjBgmsAS2ZIvDw7ct/Hl6ZEiQDFzvD6GiR8/r8XFZIIqRjayg+hCHRp1Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1736541323; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=g9R9dQpF5UbzJZ6Kb11hyvYzYtKnLXxRBjcuMGn4NXM=; b=ZEDvFnU4gsOKGzT8iN4bVXQJYkuki9uHCb4oSeAZc0HAjp8UtqEciD90SsPitImMvMyMm8vYB7zXflMrDXxq0PekWtxrWnX/YkJXHw96b88d9ucf+hsNgm+uGFrOo5D+9tQrolar3y1ReIVOqHwdzLVl9OuBG3HiN4LYxXxRGhM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1736541323887289.15840377359814; Fri, 10 Jan 2025 12:35:23 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tWLhz-0000WE-S4; Fri, 10 Jan 2025 15:34:19 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tWLhw-0000VK-Tv for qemu-devel@nongnu.org; Fri, 10 Jan 2025 15:34:16 -0500 Received: from mail-pl1-x62c.google.com ([2607:f8b0:4864:20::62c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tWLhv-0005f2-4Z for qemu-devel@nongnu.org; Fri, 10 Jan 2025 15:34:16 -0500 Received: by mail-pl1-x62c.google.com with SMTP id d9443c01a7336-2165cb60719so44203015ad.0 for ; Fri, 10 Jan 2025 12:34:14 -0800 (PST) Received: from pc.. ([38.39.164.180]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-a318e8ecacfsm3215947a12.38.2025.01.10.12.34.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Jan 2025 12:34:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1736541253; x=1737146053; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=g9R9dQpF5UbzJZ6Kb11hyvYzYtKnLXxRBjcuMGn4NXM=; b=VtIpE3p59kQ0rOFVvsvhaAI+1nZgwi+N18g5A94+9znPjDvH9aWuheNf3HW896hPFJ FjAOibPt0pYM3F8aTPp/NJqg/oShxQs+kUeSFStQS/CYtCEAgZBSWKCICA/HtTURvaCR 6GGR3bKZp46zX/60Mw0GYsbTg+RJYfG6/C9S7XjcpHzOdZguJzKVCNV0KG3Lji5oL0+Z G9qNQIJ8iu/9n7NOVZGs864I2EbQHx07utJydSJvORos2dtnFz3odLzbcovAEV5lOZcg ZBiEtROVJwIX1LOFy4QDzeSAmNQSc0kWuGEHMu052IaGa2/Z0zzdYDamVwVW8VFqumcs ipiQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736541253; x=1737146053; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=g9R9dQpF5UbzJZ6Kb11hyvYzYtKnLXxRBjcuMGn4NXM=; b=X20JFfmV5aWRlwpLwHZAbhEf15tpts1uWQACgjnv9D90H4M4bzaDeuB4TZpWloWDHA 6tO1EyxNmLVC+ud0KXPIoOQ2rTRe5ixMUH/vckyFTqsb5BCTDTI9OMIrXAR1AMTiBjJK 7ROFQ7N5deTFEbbjE9Hvd/hiDLxWMh/MmsISdyVfUwO69XV8Cba39LJHghrOQvTmUxxK pjepPhkhG7a/QDx1FQIwhaCi2fdWDH+jHXn5G3ptgyWl0ermTyVCbkETIf/nTGGCUsCf jj5k0sLOnAfwoFWfHSnkgKN1irFuyBvzunpywAkc3rt9EZYLJYDfCBGXw7lilBfWXgX+ FgMA== X-Gm-Message-State: AOJu0Yw/1OzLZw1ks9rFCmMUdbQmUgaf0n9xCsiMDi169wWC6hVTlklE K1UVlFHORw6gEeRIWVoHhxnTbiC2vjN5IkR7w3NqmkpD1ZP91t2wDvTOjk20K8o4WvkSVhWdyx1 ujwVCgA== X-Gm-Gg: ASbGncs0q0UM1DisrQSLMpnk6/IYSmS7zyiDsUxl4ecp9TiiIyJZ0JBs+u1K0Cfqr3V jli9Kgl6siQb1w5c8r4ArGFZa6Q6Ec+7dJ44kmhkkO2CVejMhwSoSHil62vFQ7WVQbPZrMaOOH7 l6Jtsq6N2g8EXJ9qJeDZhbfRBgHuBWb0tFU1Dx+ItyoOzs/j1Ua3q0SFuM1WYfnz+hTaTikBnhZ mGv/Fo3g4VM92v1hNlwQYfGdtuqLveV6B8Ncl/+YTJss+4qgaD1eWvQ X-Google-Smtp-Source: AGHT+IH6wCuxtcT3FFj/3mFPlad27XCOZu4H48N7u/eV/WeqlO2/S9/Amz7cwBFmCK9dVz+afnoNIg== X-Received: by 2002:aa7:88cd:0:b0:725:f097:ed21 with SMTP id d2e1a72fcca58-72d21f471d6mr17088257b3a.15.1736541253266; Fri, 10 Jan 2025 12:34:13 -0800 (PST) From: Pierrick Bouvier To: qemu-devel@nongnu.org Cc: Mahmoud Mandour , Markus Armbruster , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Thomas Huth , Paolo Bonzini , Pierrick Bouvier , Stefano Garzarella , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?Alex=20Benn=C3=A9e?= , "Michael S. Tsirkin" , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Alexandre Iooss , Richard Henderson Subject: [PATCH v4 2/3] docs/devel/style: add a section about bitfield, and disallow them for packed structures Date: Fri, 10 Jan 2025 12:34:00 -0800 Message-Id: <20250110203401.178532-3-pierrick.bouvier@linaro.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250110203401.178532-1-pierrick.bouvier@linaro.org> References: <20250110203401.178532-1-pierrick.bouvier@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::62c; envelope-from=pierrick.bouvier@linaro.org; helo=mail-pl1-x62c.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1736541325258116600 Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Richard Henderson Signed-off-by: Pierrick Bouvier --- docs/devel/style.rst | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/docs/devel/style.rst b/docs/devel/style.rst index 2f68b500798..d025933808e 100644 --- a/docs/devel/style.rst +++ b/docs/devel/style.rst @@ -416,6 +416,26 @@ definitions instead of typedefs in headers and functio= n prototypes; this avoids problems with duplicated typedefs and reduces the need to include headers from other headers. =20 +Bitfields +--------- + +C bitfields can be a cause of non-portability issues, especially under win= dows +where `MSVC has a different way to lay them out than GCC +`_, or where +endianness matters. + +For this reason, we disallow usage of bitfields in packed structures and i= n any +structures which are supposed to exactly match a specific layout in guest +memory. Some existing code may use it, and we carefully ensured the layout= was +the one expected. + +We also suggest avoiding bitfields even in structures where the exact +layout does not matter, unless you can show that they provide a significant +usability benefit. + +We encourage the usage of ``include/hw/registerfields.h`` as a safe replac= ement +for bitfields. + Reserved namespaces in C and POSIX ---------------------------------- =20 --=20 2.39.5