From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by sourceware.org (Postfix) with ESMTPS id 87A9E3858D39 for ; Wed, 8 Feb 2023 12:23:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 87A9E3858D39 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 (m0098404.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 318BgDAZ017589; Wed, 8 Feb 2023 12:22:38 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=tsQ0vsxF4NLEXemoiffgfPIEUi8SHKdCmN62N/prsG8=; b=ihEwn4rXQOCe5Jd5aNGrGa93pGIx3RMhaEQFKOFt0joSoZZdsKvyBO1R8O8+VeqKYpgR Sqq6iFLmULQAU+4JvJ60RQQTSxIXR7VHOOKTEjbNSjcUIOZWpRI24IYrSXzrLp6bEsBP 4ft0XjBw30bSdnIsw8/0YMNXCDMy8U9UVgiGrv/RBX0Caanc4ydl+etUjaLsERiqpizb 6LR332UW2jRMEQvvxglCUAuN8VnuHCc6rVYso8YmZi9Y2U3PVWXb/y6GXHAFH/7iiJV6 Sk1OOFKgGPFdWRC5B/fp6NH2MHYqMlmKfOSzTKrGtNK04SkPJnaDfvfu3YPlkMbO49Ot ww== Received: from ppma06fra.de.ibm.com (48.49.7a9f.ip4.static.sl-reverse.com [159.122.73.72]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3nmb3d0w54-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 08 Feb 2023 12:22:37 +0000 Received: from pps.filterd (ppma06fra.de.ibm.com [127.0.0.1]) by ppma06fra.de.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 317EtMY9017536; Wed, 8 Feb 2023 12:22:35 GMT Received: from smtprelay06.fra02v.mail.ibm.com ([9.218.2.230]) by ppma06fra.de.ibm.com (PPS) with ESMTPS id 3nhemfkg3v-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 08 Feb 2023 12:22:35 +0000 Received: from smtpav07.fra02v.mail.ibm.com (smtpav07.fra02v.mail.ibm.com [10.20.54.106]) by smtprelay06.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 318CMWk322806876 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 8 Feb 2023 12:22:32 GMT Received: from smtpav07.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id BE5E520043; Wed, 8 Feb 2023 12:22:32 +0000 (GMT) Received: from smtpav07.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 72E7820040; Wed, 8 Feb 2023 12:22:32 +0000 (GMT) Received: from [9.179.29.204] (unknown [9.179.29.204]) by smtpav07.fra02v.mail.ibm.com (Postfix) with ESMTP; Wed, 8 Feb 2023 12:22:32 +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: Wed, 08 Feb 2023 13:22:32 +0100 In-Reply-To: <20230207204426.GD25444@gnu.wildebeest.org> References: <20230206222513.1773039-1-iii@linux.ibm.com> <20230206222513.1773039-4-iii@linux.ibm.com> <20230207204426.GD25444@gnu.wildebeest.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-GUID: 07qP1eOADT8J8Znoyh4xzMTjoLmDGAB4 X-Proofpoint-ORIG-GUID: 07qP1eOADT8J8Znoyh4xzMTjoLmDGAB4 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.122.1 definitions=2023-02-08_04,2023-02-08_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 bulkscore=0 priorityscore=1501 mlxscore=0 adultscore=0 mlxlogscore=964 phishscore=0 impostorscore=0 spamscore=0 lowpriorityscore=0 malwarescore=0 clxscore=1011 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2212070000 definitions=main-2302080109 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,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 21:44 +0100, Mark Wielaard wrote: > Hi Ilya (CC Frank), >=20 > On Mon, Feb 06, 2023 at 11:25:05PM +0100, Ilya Leoshkevich via > Elfutils-devel wrote: > > clang complains: > >=20 > > =C2=A0=C2=A0=C2=A0 debuginfod.cxx:354:1: error: unused variable 'apba__= ' [- > > Werror,-Wunused-const-variable] > > =C2=A0=C2=A0=C2=A0 ARGP_PROGRAM_BUG_ADDRESS_DEF =3D PACKAGE_BUGREPORT; > > =C2=A0=C2=A0=C2=A0 ^ > > =C2=A0=C2=A0=C2=A0 ../lib/printversion.h:47:21: note: expanded from mac= ro > > 'ARGP_PROGRAM_BUG_ADDRESS_DEF' > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 const char *const apba__ __asm ("argp_pr= ogram_bug_address") > > =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 > > This is as expected: it's used by argp via the > > "argp_program_bug_address" name, which is not visible on the C > > level. > > Add __attribute__ ((used)) to make sure that the compiler emits it. >=20 > Actually I think it found a real issue. Note that the same construct > is used the C eu tools.=C2=A0 But in debuginfod.cxx it says: >=20 > /* Name and version of program.=C2=A0 */ > /* ARGP_PROGRAM_VERSION_HOOK_DEF =3D print_version; */ // not this > simple for C++ >=20 > /* Bug report address.=C2=A0 */ > ARGP_PROGRAM_BUG_ADDRESS_DEF =3D PACKAGE_BUGREPORT; >=20 > Note how ARGP_PROGRAM_VERSION_HOOK_DEF is commented out and in main > it > has: >=20 > =C2=A0=C2=A0 /* Parse and process arguments.=C2=A0 */ > =C2=A0=C2=A0 int remaining; > =C2=A0=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); >=20 > So it sets print_version, but not argp_program_bug_address. > And indeed debuginfod --help is missing the bug reporting address. >=20 > I don't really know/understand why the printversion.h macro trick > doesn't work with C++ (symbol mangling?). But we do need at least > this patch: >=20 > diff --git a/debuginfod/debuginfod.cxx b/debuginfod/debuginfod.cxx > index 4271acf4..0ec326d5 100644 > --- a/debuginfod/debuginfod.cxx > +++ b/debuginfod/debuginfod.cxx > @@ -4172,6 +4165,7 @@ main (int argc, char *argv[]) > =C2=A0=C2=A0 /* Parse and process arguments.=C2=A0 */ > =C2=A0=C2=A0 int remaining; > =C2=A0=C2=A0 argp_program_version_hook =3D print_version; // this works > +=C2=A0 argp_program_bug_address =3D PACKAGE_BUGREPORT; > =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 > Then debuginfod --help will say: Report bugs to > https://sourceware.org/bugzilla. >=20 > That of course doesn't help with the -Wunused-const-variable warning. >=20 > If we cannot figure out the magic variable naming trick with with C++ > then maybe we can just not include printversion.h and do it "by > hand"? > (as attached) >=20 > Cheers, >=20 > Mark If I build: const char *const apba__ __asm ("argp_program_bug_address") \ __attribute__ ((used)) =3D "foobarbaz"; with C and C++, the difference is going to be: @@ -1,6 +1,5 @@ .file "1.c" .text - .globl argp_program_bug_address .section .rodata.str1.1,"aMS",@progbits,1 .LC0: .string "foobarbaz" This must have to do with C and C++ standards treating const differently [1]. The solution is to add extern: --- a/lib/printversion.h +++ b/lib/printversion.h @@ -44,6 +44,7 @@ void print_version (FILE *stream, struct argp_state *state); void (*const apvh) (FILE *, struct argp_state *) \ __asm ("argp_program_version_hook") #define ARGP_PROGRAM_BUG_ADDRESS_DEF \ + extern const char *const apba__; \ const char *const apba__ __asm ("argp_program_bug_address") \ __attribute__ ((used)) I can include this in v2 if it works for you. [1] https://stackoverflow.com/questions/8908071/const-correctness-in-c-vs-c