[v2,2/7] printversion: Fix unused variable

Message ID 20230208195226.144143-3-iii@linux.ibm.com
State Superseded
Series Add Memory Sanitizer support |

Commit Message

Ilya Leoshkevich Feb. 8, 2023, 7:52 p.m. UTC
  clang complains:

    debuginfod.cxx:354:1: error: unused variable 'apba__' [-Werror,-Wunused-const-variable]
    ../lib/printversion.h:47:21: note: expanded from macro 'ARGP_PROGRAM_BUG_ADDRESS_DEF'
      const char *const apba__ __asm ("argp_program_bug_address")

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.

While at it, fix debuginfod not printing the bug report address.

Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
 lib/printversion.h | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)


diff --git a/lib/printversion.h b/lib/printversion.h
index a9e059ff..37adff7e 100644
--- a/lib/printversion.h
+++ b/lib/printversion.h
@@ -39,11 +39,14 @@  void print_version (FILE *stream, struct argp_state *state);
    argp_program_bug_address, in all programs.  argp.h declares these
    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.  */
+   the .rodata section.  Define macros to do the trick.  The default
+   linkage for consts in C++ is internal, so declare them extern.  */
   void (*const apvh) (FILE *, struct argp_state *) \
    __asm ("argp_program_version_hook")
-  const char *const apba__ __asm ("argp_program_bug_address")
+  extern const char *const apba__; \
+  const char *const apba__ __asm ("argp_program_bug_address") \
+  __attribute__ ((used))