From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by sourceware.org (Postfix) with ESMTPS id 45CF03858D33 for ; Tue, 7 Feb 2023 19:49:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 45CF03858D33 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=linux.ibm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linux.ibm.com Received: from pps.filterd (m0127361.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 317JGaC8006595; Tue, 7 Feb 2023 19:49:31 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=message-id : subject : from : to : cc : date : in-reply-to : references : content-type : content-transfer-encoding : mime-version; s=pp1; bh=09EtqJl2q5OAZ4GxRJYzR5F5ceFL5Ras494WrV9G+Gw=; b=EbBofPgSi1xPzTuSONXHynzetrDwFb7a8fMzx7qLKrYPJ1lsWgHdZIhvm20bNzHFLtB/ oIFkxdRCyaW3Ie1uZhLOToXJfynsMqrYxHUhvHtxn+oWYbJYm+pNpxIRFMx5XdA4MucG GSSjQQKhAYr8lGjiQL5nd0IFkyABn7njfLW69S0DFWWRRrKpFwnDCssFsRagG9Vs51M/ E+ML/fI3Z1KteYhtZM7mvKmg1TW1hm349Ey+JATqyx8BWdCGg7hLsx4Zk+6Fr+JFcZ1f pj9iheflyTXMC94vvv5O7UUeTnnPspHqsCyiorIWs8V0S56k5Rc6zEHpCy2FLs271Rer Mw== Received: from ppma03fra.de.ibm.com (6b.4a.5195.ip4.static.sl-reverse.com [149.81.74.107]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3nkvnms5ta-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 07 Feb 2023 19:49:31 +0000 Received: from pps.filterd (ppma03fra.de.ibm.com [127.0.0.1]) by ppma03fra.de.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 3176Deqx018248; Tue, 7 Feb 2023 19:49:29 GMT Received: from smtprelay05.fra02v.mail.ibm.com ([9.218.2.225]) by ppma03fra.de.ibm.com (PPS) with ESMTPS id 3nhf06jta5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 07 Feb 2023 19:49:29 +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 317JnQmf43385326 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 7 Feb 2023 19:49:26 GMT Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id A690520043; Tue, 7 Feb 2023 19:49:26 +0000 (GMT) Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 6F02B20040; Tue, 7 Feb 2023 19:49:26 +0000 (GMT) Received: from [9.179.25.234] (unknown [9.179.25.234]) by smtpav06.fra02v.mail.ibm.com (Postfix) with ESMTP; Tue, 7 Feb 2023 19:49:26 +0000 (GMT) Message-ID: <90ce11d8b570f55e2658073ab8ca46070e8246fd.camel@linux.ibm.com> Subject: Re: [PATCH RFC 02/11] libasm: Fix xdefault_pattern initialization From: Ilya Leoshkevich To: Mark Wielaard Cc: elfutils-devel@sourceware.org Date: Tue, 07 Feb 2023 20:49:26 +0100 In-Reply-To: <20230207194122.GC25444@gnu.wildebeest.org> References: <20230206222513.1773039-1-iii@linux.ibm.com> <20230206222513.1773039-3-iii@linux.ibm.com> <20230207194122.GC25444@gnu.wildebeest.org> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.46.3 (3.46.3-1.fc37) MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: XgbHhH_wa1zimxsVzZ7u1MBSR71Hov-G X-Proofpoint-ORIG-GUID: XgbHhH_wa1zimxsVzZ7u1MBSR71Hov-G 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-07_11,2023-02-06_03,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 spamscore=0 adultscore=0 suspectscore=0 priorityscore=1501 clxscore=1015 bulkscore=0 impostorscore=0 mlxlogscore=999 lowpriorityscore=0 phishscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2212070000 definitions=main-2302070172 X-Spam-Status: No, score=-9.5 required=5.0 tests=BAYES_00,BODY_8BITS,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,GIT_PATCH_0,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 List-Id: On Tue, 2023-02-07 at 20:41 +0100, Mark Wielaard wrote: > Hi Ilya, >=20 > On Mon, Feb 06, 2023 at 11:25:04PM +0100, Ilya Leoshkevich via > Elfutils-devel wrote: > > clang complains: > >=20 > > =C2=A0=C2=A0=C2=A0 asm_newscn.c:48:22: error: field 'pattern' with vari= able 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] > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 struct FillPattern pattern; > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= ^ > >=20 > > 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: > >=20 > > =C2=A0=C2=A0=C2=A0 If an object that has static or thread storage durat= ion is not > > =C2=A0=C2=A0=C2=A0 initialized explicitly, then ... if it is a union, t= he first > > named > > =C2=A0=C2=A0=C2=A0 member is initialized (recursively) according to the= se rules, > > and > > =C2=A0=C2=A0=C2=A0 any padding is initialized to zero bits. > >=20 > > Signed-off-by: Ilya Leoshkevich > > --- > > =C2=A0libasm/asm_newscn.c | 5 ++--- > > =C2=A01 file changed, 2 insertions(+), 3 deletions(-) > >=20 > > diff --git a/libasm/asm_newscn.c b/libasm/asm_newscn.c > > index d258d969..32a3b598 100644 > > --- a/libasm/asm_newscn.c > > +++ b/libasm/asm_newscn.c > > @@ -43,17 +43,16 @@ > > =C2=A0/* Memory for the default pattern.=C2=A0 The type uses a flexible= array > > =C2=A0=C2=A0=C2=A0 which does work well with a static initializer.=C2= =A0 So we play > > some > > =C2=A0=C2=A0=C2=A0 dirty tricks here.=C2=A0 */ > > -static const struct > > +static const union > > =C2=A0{ > > =C2=A0=C2=A0 struct FillPattern pattern; > > -=C2=A0 char zero; > > +=C2=A0 char zeroes[sizeof(struct FillPattern) + 1]; > > =C2=A0} xdefault_pattern =3D > > =C2=A0=C2=A0 { > > =C2=A0=C2=A0=C2=A0=C2=A0 .pattern =3D > > =C2=A0=C2=A0=C2=A0=C2=A0 { > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 .len =3D 1 > > =C2=A0=C2=A0=C2=A0=C2=A0 }, > > -=C2=A0=C2=A0=C2=A0 .zero =3D '\0' > > =C2=A0=C2=A0 }; >=20 > Yes, I think this works. Could you update the comment just before > this > with some of the commit message explanation? Your explanation is much > better than "play some dirty trick" :) Thanks, will do. > > =C2=A0const struct FillPattern *__libasm_default_pattern =3D > > &xdefault_pattern.pattern; >=20 > I am surprised this doesn't need a cast. Do you know why? We are referencing the union's .pattern member, not the entire union, so the types still match. >=20 > Thanks, >=20 > Mark