From patchwork Wed Feb 8 19:52:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilya Leoshkevich X-Patchwork-Id: 64499 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id BAF583858C39 for ; Wed, 8 Feb 2023 19:53:05 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BAF583858C39 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1675885985; bh=89Ksc3Ymztn9aIYfd8kNEeHwkZnewrCCc9MnyAzi7Ak=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Help:List-Subscribe:From: Reply-To:From; b=TOr1QsURs6rG3P+ff6U+j4V4o0ejed7BXCLg7gyF+djZYr2rOzJ+1KeS02a1aE9of hjG/1ee0Ifm+ud/vtdwxOShXjXZuw0BosQbc4IdOB5UPiXDJOAqK03aYr10KrxxGct QB9wbjyLqgNiSULeV7LbsQWii7ZJsZ5oYPIghnZQ= X-Original-To: elfutils-devel@sourceware.org Delivered-To: elfutils-devel@sourceware.org Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by sourceware.org (Postfix) with ESMTPS id 998533858C53 for ; Wed, 8 Feb 2023 19:52:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 998533858C53 Received: from pps.filterd (m0098396.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 318J8vQm005444; Wed, 8 Feb 2023 19:52:36 GMT Received: from ppma04ams.nl.ibm.com (63.31.33a9.ip4.static.sl-reverse.com [169.51.49.99]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3nmhdch8rn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 08 Feb 2023 19:52:36 +0000 Received: from pps.filterd (ppma04ams.nl.ibm.com [127.0.0.1]) by ppma04ams.nl.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 3186Ivj8023711; Wed, 8 Feb 2023 19:52:33 GMT Received: from smtprelay05.fra02v.mail.ibm.com ([9.218.2.225]) by ppma04ams.nl.ibm.com (PPS) with ESMTPS id 3nhf06wakw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 08 Feb 2023 19:52:33 +0000 Received: from smtpav06.fra02v.mail.ibm.com (smtpav06.fra02v.mail.ibm.com [10.20.54.105]) by smtprelay05.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 318JqUtH46989746 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 8 Feb 2023 19:52:30 GMT Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 3D94E2004B; Wed, 8 Feb 2023 19:52:30 +0000 (GMT) Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id EB47220043; Wed, 8 Feb 2023 19:52:29 +0000 (GMT) Received: from heavy.ibmuc.com (unknown [9.179.24.149]) by smtpav06.fra02v.mail.ibm.com (Postfix) with ESMTP; Wed, 8 Feb 2023 19:52:29 +0000 (GMT) To: Mark Wielaard Cc: elfutils-devel@sourceware.org, Ilya Leoshkevich Subject: [PATCH v2 1/7] libasm: Fix xdefault_pattern initialization Date: Wed, 8 Feb 2023 20:52:20 +0100 Message-Id: <20230208195226.144143-2-iii@linux.ibm.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230208195226.144143-1-iii@linux.ibm.com> References: <20230208195226.144143-1-iii@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: R5Fh2IUncV56qkIJIxTR02LNykKoXQBy X-Proofpoint-GUID: R5Fh2IUncV56qkIJIxTR02LNykKoXQBy X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.219,Aquarius:18.0.930,Hydra:6.0.562,FMLib:17.11.122.1 definitions=2023-02-08_09,2023-02-08_02,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 suspectscore=0 phishscore=0 impostorscore=0 clxscore=1015 malwarescore=0 mlxscore=0 mlxlogscore=891 spamscore=0 adultscore=0 priorityscore=1501 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2212070000 definitions=main-2302080167 X-Spam-Status: No, score=-11.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_EF, GIT_PATCH_0, 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: elfutils-devel@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Elfutils-devel mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-Patchwork-Original-From: Ilya Leoshkevich via Elfutils-devel From: Ilya Leoshkevich Reply-To: Ilya Leoshkevich Errors-To: elfutils-devel-bounces+patchwork=sourceware.org@sourceware.org Sender: "Elfutils-devel" clang complains: asm_newscn.c:48:22: error: field 'pattern' with variable sized type 'struct FillPattern' not at the end of a struct or class is a GNU extension [-Werror,-Wgnu-variable-sized-type-not-at-end] struct FillPattern pattern; ^ Fix by using a union instead. Define the second union member to be a char array 1 byte larger than struct FillPattern. This should be legal according to 6.7.9: If an object that has static or thread storage duration is not initialized explicitly, then ... if it is a union, the first named member is initialized (recursively) according to these rules, and any padding is initialized to zero bits. Signed-off-by: Ilya Leoshkevich --- libasm/asm_newscn.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/libasm/asm_newscn.c b/libasm/asm_newscn.c index d258d969..f28c40f9 100644 --- a/libasm/asm_newscn.c +++ b/libasm/asm_newscn.c @@ -41,19 +41,25 @@ /* Memory for the default pattern. The type uses a flexible array - which does work well with a static initializer. So we play some - dirty tricks here. */ -static const struct + which does work well with a static initializer. Work around this by + wrapping it in a union, whose second member is a char array 1 byte larger + than struct FillPattern. According to 6.7.9, this does what we need: + + If an object that has static or thread storage duration is not + initialized explicitly, then ... if it is a union, the first named + member is initialized (recursively) according to these rules, and + any padding is initialized to zero bits. */ + +static const union { struct FillPattern pattern; - char zero; + char zeroes[sizeof(struct FillPattern) + 1]; } xdefault_pattern = { .pattern = { .len = 1 }, - .zero = '\0' }; const struct FillPattern *__libasm_default_pattern = &xdefault_pattern.pattern;