From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gnu.wildebeest.org (gnu.wildebeest.org [45.83.234.184]) by sourceware.org (Postfix) with ESMTPS id 01AFF3858C50 for ; Thu, 9 Feb 2023 14:04:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 01AFF3858C50 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=klomp.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=klomp.org Received: from r6.localdomain (82-217-174-174.cable.dynamic.v4.ziggo.nl [82.217.174.174]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by gnu.wildebeest.org (Postfix) with ESMTPSA id A524530067CA; Thu, 9 Feb 2023 15:04:27 +0100 (CET) Received: by r6.localdomain (Postfix, from userid 1000) id 632F33402DE; Thu, 9 Feb 2023 15:04:27 +0100 (CET) Message-ID: <4f4ff08bfa9d6601432291fb078dad033ab89057.camel@klomp.org> Subject: Re: [PATCH RFC 03/11] printversion: Fix unused variable From: Mark Wielaard To: Ilya Leoshkevich Cc: elfutils-devel@sourceware.org, fche@elastic.org Date: Thu, 09 Feb 2023 15:04:27 +0100 In-Reply-To: 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" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.46.3 (3.46.3-1.fc37) MIME-Version: 1.0 X-Spam-Status: No, score=-3036.3 required=5.0 tests=BAYES_00,GIT_PATCH_0,JMQ_SPF_NEUTRAL,KAM_DMARC_STATUS,RCVD_IN_BARRACUDACENTRAL,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: Hi Ilya, 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 @@ > .file "1.c" > .text > - .globl argp_program_bug_address > .section .rodata.str1.1,"aMS",@progbits,1 > .LC0: > .string "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); > 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)) >=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 O nice, that explains it. But then in that case I don't think you need the __attribute__ ((used)) anymore. Also as a nitpick the multiline define could be just a single line if you declare the extern on its own in printversion.h. 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. Does the following work for you? 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 *sta= te); variables as non-const (which is correct in general). But we can do better, it is not going to change. So we want to move them into the .rodata section. Define macros to do the trick. */ +extern void (*const apvh) (FILE *, struct argp_state *); #define ARGP_PROGRAM_VERSION_HOOK_DEF \ void (*const apvh) (FILE *, struct argp_state *) \ __asm ("argp_program_version_hook") +extern const char *const apba__; #define ARGP_PROGRAM_BUG_ADDRESS_DEF \ const char *const apba__ __asm ("argp_program_bug_address") =20 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 =20 =20 /* Name and version of program. */ -/* ARGP_PROGRAM_VERSION_HOOK_DEF =3D print_version; */ // not this simple = for C++ +ARGP_PROGRAM_VERSION_HOOK_DEF =3D print_version; =20 /* Bug report address. */ ARGP_PROGRAM_BUG_ADDRESS_DEF =3D PACKAGE_BUGREPORT; @@ -4171,7 +4171,6 @@ main (int argc, char *argv[]) =20 /* Parse and process arguments. */ int remaining; - argp_program_version_hook =3D print_version; // this works (void) argp_parse (&argp, argc, argv, ARGP_IN_ORDER, &remaining, NULL); if (remaining !=3D argc) error (EXIT_FAILURE, 0, Thanks, Mark