From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx0a-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by sourceware.org (Postfix) with ESMTPS id 4115F3858C50 for ; Thu, 9 Feb 2023 14:58:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4115F3858C50 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 (m0098419.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 319ElK2x006784; Thu, 9 Feb 2023 14:57:56 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=ZtKtvocFuRL4wS+HtSJhX5/acmEL51Q+PG0URfYZvxo=; b=fsTvuA6gMnMIZc+n8BhH317lm2wGU92nbbj1m1EwcWtPOJe+SexwRZqqY0mFhmoJL+b4 WaVnDY4vOgF+yZVKHvStMQW7hdSkNU9tt6JoxIsu41OCYL0sHczP+UIEvc69pBCv4v5V 14PIMFzGiwRzoaLmkZoUF9v1K5NbgTrg39/I+zWaZT3wjPSZzhfGNv4iUD5jqz4e1Q4N BEf8edUGxMUp50qEMYCMEd5ejDjmX6OihLHr/IAzDiw9hVys7isIsmeGwJS3WPXWx2K3 HA+sDIJ5p7y50RobktlBGSkPnSOHMBB3ue/bol091Ukdngeu0xVeAggW5F+d1kXiD8Am 3Q== Received: from ppma04ams.nl.ibm.com (63.31.33a9.ip4.static.sl-reverse.com [169.51.49.99]) by mx0b-001b2d01.pphosted.com (PPS) with ESMTPS id 3nn2wb07ad-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 09 Feb 2023 14:57:56 +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 319CXVTk023824; Thu, 9 Feb 2023 14:57:54 GMT Received: from smtprelay02.fra02v.mail.ibm.com ([9.218.2.226]) by ppma04ams.nl.ibm.com (PPS) with ESMTPS id 3nhf06xc0d-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 09 Feb 2023 14:57:54 +0000 Received: from smtpav03.fra02v.mail.ibm.com (smtpav03.fra02v.mail.ibm.com [10.20.54.102]) by smtprelay02.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 319EvqcM43909432 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 9 Feb 2023 14:57:52 GMT Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 6159C20043; Thu, 9 Feb 2023 14:57:52 +0000 (GMT) Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 1737220040; Thu, 9 Feb 2023 14:57:52 +0000 (GMT) Received: from [9.171.66.233] (unknown [9.171.66.233]) by smtpav03.fra02v.mail.ibm.com (Postfix) with ESMTP; Thu, 9 Feb 2023 14:57:52 +0000 (GMT) Message-ID: Subject: Re: [PATCH RFC 03/11] printversion: Fix unused variable From: Ilya Leoshkevich To: Mark Wielaard Cc: elfutils-devel@sourceware.org, fche@elastic.org Date: Thu, 09 Feb 2023 15:57:51 +0100 In-Reply-To: <4f4ff08bfa9d6601432291fb078dad033ab89057.camel@klomp.org> References: <20230206222513.1773039-1-iii@linux.ibm.com> <20230206222513.1773039-4-iii@linux.ibm.com> <20230207204426.GD25444@gnu.wildebeest.org> <4f4ff08bfa9d6601432291fb078dad033ab89057.camel@klomp.org> Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.46.3 (3.46.3-1.fc37) X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: E6WFe5Sk3SRsH3augH5Rt6up4xJAUYUi X-Proofpoint-GUID: E6WFe5Sk3SRsH3augH5Rt6up4xJAUYUi Content-Transfer-Encoding: quoted-printable X-Proofpoint-UnRewURL: 0 URL was un-rewritten MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.219,Aquarius:18.0.930,Hydra:6.0.562,FMLib:17.11.170.22 definitions=2023-02-09_10,2023-02-09_03,2023-02-09_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 lowpriorityscore=0 mlxlogscore=999 mlxscore=0 adultscore=0 spamscore=0 priorityscore=1501 impostorscore=0 phishscore=0 suspectscore=0 malwarescore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2212070000 definitions=main-2302090138 X-Spam-Status: No, score=-10.6 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 Thu, 2023-02-09 at 15:04 +0100, Mark Wielaard wrote: > Hi Ilya, >=20 > On Wed, 2023-02-08 at 13:22 +0100, Ilya Leoshkevich wrote: > > If I build: > >=20 > > const char *const apba__ __asm ("argp_program_bug_address") \ > > __attribute__ ((used)) =3D "foobarbaz"; > >=20 > > with C and C++, the difference is going to be: > >=20 > > @@ -1,6 +1,5 @@ > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0.file=C2=A0=C2=A0=C2=A0= "1.c" > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0.text > > -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0.globl=C2=A0=C2=A0argp_progr= am_bug_address > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0.section=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0.rodata.str1.1,"aMS",@progbits,1 > > =C2=A0.LC0: > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0.string=C2=A0"foobarbaz" > >=20 > > This must have to do with C and C++ standards treating const > > differently [1]. The solution is to add extern: > >=20 > > --- a/lib/printversion.h > > +++ b/lib/printversion.h > > @@ -44,6 +44,7 @@ void print_version (FILE *stream, struct > > argp_state > > *state); > > =C2=A0=C2=A0 void (*const apvh) (FILE *, struct argp_state *) \ > > =C2=A0=C2=A0=C2=A0 __asm ("argp_program_version_hook") > > =C2=A0#define ARGP_PROGRAM_BUG_ADDRESS_DEF \ > > +=C2=A0 extern const char *const apba__; \ > > =C2=A0=C2=A0 const char *const apba__ __asm ("argp_program_bug_address"= ) \ > > =C2=A0=C2=A0 __attribute__ ((used)) > >=20 > > I can include this in v2 if it works for you. > >=20 > > [1] > > https://stackoverflow.com/questions/8908071/const-correctness-in-c-vs-c >=20 > O nice, that explains it. But then in that case I don't think you > need > the __attribute__ ((used)) anymore. >=20 > Also as a nitpick the multiline define could be just a single line if > you declare the extern on its own in printversion.h. >=20 > And it would be nice to also cleanup apvh/argp_program_version_hook > so > it too works with c++, so we can remove the hack in debuginfod.cxx. >=20 > Does the following work for you? >=20 > diff --git a/lib/printversion.h b/lib/printversion.h > index a9e059ff..bc9ca7ae 100644 > --- a/lib/printversion.h > +++ b/lib/printversion.h > @@ -40,9 +40,11 @@ void print_version (FILE *stream, struct > argp_state *state); > =C2=A0=C2=A0=C2=A0 variables as non-const (which is correct in general).= =C2=A0 But we can > =C2=A0=C2=A0=C2=A0 do better, it is not going to change.=C2=A0 So we want= to move them > into > =C2=A0=C2=A0=C2=A0 the .rodata section.=C2=A0 Define macros to do the tri= ck.=C2=A0 */ > +extern void (*const apvh) (FILE *, struct argp_state *); > =C2=A0#define ARGP_PROGRAM_VERSION_HOOK_DEF \ > =C2=A0=C2=A0 void (*const apvh) (FILE *, struct argp_state *) \ > =C2=A0=C2=A0=C2=A0 __asm ("argp_program_version_hook") > +extern const char *const apba__; > =C2=A0#define ARGP_PROGRAM_BUG_ADDRESS_DEF \ > =C2=A0=C2=A0 const char *const apba__ __asm ("argp_program_bug_address") > =C2=A0 > diff --git a/debuginfod/debuginfod.cxx b/debuginfod/debuginfod.cxx > index 4271acf4..99b1f2b9 100644 > --- a/debuginfod/debuginfod.cxx > +++ b/debuginfod/debuginfod.cxx > @@ -348,7 +348,7 @@ static const char DEBUGINFOD_SQLITE_CLEANUP_DDL[] > =3D > =C2=A0 > =C2=A0 > =C2=A0/* Name and version of program.=C2=A0 */ > -/* ARGP_PROGRAM_VERSION_HOOK_DEF =3D print_version; */ // not this > simple for C++ > +ARGP_PROGRAM_VERSION_HOOK_DEF =3D print_version; > =C2=A0 > =C2=A0/* Bug report address.=C2=A0 */ > =C2=A0ARGP_PROGRAM_BUG_ADDRESS_DEF =3D PACKAGE_BUGREPORT; > @@ -4171,7 +4171,6 @@ main (int argc, char *argv[]) > =C2=A0 > =C2=A0=C2=A0 /* Parse and process arguments.=C2=A0 */ > =C2=A0=C2=A0 int remaining; > -=C2=A0 argp_program_version_hook =3D print_version; // this works > =C2=A0=C2=A0 (void) argp_parse (&argp, argc, argv, ARGP_IN_ORDER, &remain= ing, > NULL); > =C2=A0=C2=A0 if (remaining !=3D argc) > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 error (EXIT_FAILURE, 0, >=20 > Thanks, >=20 > Mark This works for me, I will add this to v3. Thanks!