public inbox for elfutils@sourceware.org
 help / color / mirror / Atom feed
From: Ilya Leoshkevich <iii@linux.ibm.com>
To: Mark Wielaard <mark@klomp.org>
Cc: elfutils-devel@sourceware.org, fche@elastic.org
Subject: Re: [PATCH RFC 03/11] printversion: Fix unused variable
Date: Thu, 09 Feb 2023 15:57:51 +0100	[thread overview]
Message-ID: <b4061a95d29d0ca63a55e3c0a90fde920ddc92fd.camel@linux.ibm.com> (raw)
In-Reply-To: <4f4ff08bfa9d6601432291fb078dad033ab89057.camel@klomp.org>

On Thu, 2023-02-09 at 15:04 +0100, Mark Wielaard wrote:
> Hi Ilya,
> 
> On Wed, 2023-02-08 at 13:22 +0100, Ilya Leoshkevich wrote:
> > If I build:
> > 
> > const char *const apba__ __asm ("argp_program_bug_address") \
> > __attribute__ ((used)) = "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
> 
> 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 *state);
>     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")
>  
> 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[]
> =
>  
>  
>  /* Name and version of program.  */
> -/* ARGP_PROGRAM_VERSION_HOOK_DEF = print_version; */ // not this
> simple for C++
> +ARGP_PROGRAM_VERSION_HOOK_DEF = print_version;
>  
>  /* Bug report address.  */
>  ARGP_PROGRAM_BUG_ADDRESS_DEF = PACKAGE_BUGREPORT;
> @@ -4171,7 +4171,6 @@ main (int argc, char *argv[])
>  
>    /* Parse and process arguments.  */
>    int remaining;
> -  argp_program_version_hook = print_version; // this works
>    (void) argp_parse (&argp, argc, argv, ARGP_IN_ORDER, &remaining,
> NULL);
>    if (remaining != argc)
>        error (EXIT_FAILURE, 0,
> 
> Thanks,
> 
> Mark

This works for me, I will add this to v3. Thanks!

  reply	other threads:[~2023-02-09 14:58 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-06 22:25 [PATCH RFC 00/11] Add Memory Sanitizer support Ilya Leoshkevich
2023-02-06 22:25 ` [PATCH RFC 01/11] libdwfl: Fix debuginfod_client redefinition Ilya Leoshkevich
2023-02-07 19:22   ` Mark Wielaard
2023-02-07 19:47     ` Ilya Leoshkevich
2023-02-06 22:25 ` [PATCH RFC 02/11] libasm: Fix xdefault_pattern initialization Ilya Leoshkevich
2023-02-07 19:41   ` Mark Wielaard
2023-02-07 19:49     ` Ilya Leoshkevich
2023-02-06 22:25 ` [PATCH RFC 03/11] printversion: Fix unused variable Ilya Leoshkevich
2023-02-07 20:44   ` Mark Wielaard
2023-02-08 12:22     ` Ilya Leoshkevich
2023-02-09 14:04       ` Mark Wielaard
2023-02-09 14:57         ` Ilya Leoshkevich [this message]
2023-02-06 22:25 ` [PATCH RFC 04/11] readelf: Fix set but not used parameter Ilya Leoshkevich
2023-02-08 16:52   ` Mark Wielaard
2023-02-06 22:25 ` [PATCH RFC 05/11] readelf: Fix set but not used variable Ilya Leoshkevich
2023-02-08 17:09   ` Mark Wielaard
2023-02-06 22:25 ` [PATCH RFC 06/11] Initialize reglocs for VMCOREINFO Ilya Leoshkevich
2023-02-08 17:27   ` Mark Wielaard
2023-02-06 22:25 ` [PATCH RFC 07/11] addr2line: Do not test demangling in run-addr2line-i-test.sh Ilya Leoshkevich
2023-02-08 18:15   ` Mark Wielaard
2023-02-06 22:25 ` [PATCH RFC 08/11] x86_64_return_value_location: Support lvalue and rvalue references Ilya Leoshkevich
2023-02-06 22:25 ` [PATCH RFC 09/11] configure: Use -fno-addrsig if possible Ilya Leoshkevich
2023-02-06 22:25 ` [PATCH RFC 10/11] configure: Add --disable-demangle Ilya Leoshkevich
2023-02-08 18:14   ` Mark Wielaard
2023-02-06 22:25 ` [PATCH RFC 11/11] configure: Add --enable-sanitize-memory Ilya Leoshkevich
2023-02-07 19:05 ` [PATCH RFC 00/11] Add Memory Sanitizer support Mark Wielaard
2023-02-07 19:46   ` Ilya Leoshkevich

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=b4061a95d29d0ca63a55e3c0a90fde920ddc92fd.camel@linux.ibm.com \
    --to=iii@linux.ibm.com \
    --cc=elfutils-devel@sourceware.org \
    --cc=fche@elastic.org \
    --cc=mark@klomp.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).