[Bug,libdw/30077] New: Duplicate definition of typedef struct debuginfod_client in libdwfl

Message ID bug-30077-10460@http.sourceware.org/bugzilla/
State Committed
Headers
Series [Bug,libdw/30077] New: Duplicate definition of typedef struct debuginfod_client in libdwfl |

Commit Message

fche at redhat dot com Feb. 3, 2023, 8:12 p.m. UTC
  https://sourceware.org/bugzilla/show_bug.cgi?id=30077

            Bug ID: 30077
           Summary: Duplicate definition of typedef struct
                    debuginfod_client in libdwfl
           Product: elfutils
           Version: unspecified
            Status: NEW
          Severity: normal
          Priority: P2
         Component: libdw
          Assignee: unassigned at sourceware dot org
          Reporter: dje at sourceware dot org
                CC: elfutils-devel at sourceware dot org
  Target Milestone: ---

typedef struct debuginfod_client is defined in both libdwfl/libdwfl.h and in
debuginfod.h included by libdwfl/libdwflP.h.  Although innocuous, this is
invalid C and causes compilation failures with strict compliance.

One possible set of patches is:
  

Comments

fche at redhat dot com Feb. 4, 2023, 6:25 p.m. UTC | #1
https://sourceware.org/bugzilla/show_bug.cgi?id=30077

Sam James <sam at gentoo dot org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |sam at gentoo dot org

--- Comment #2 from Sam James <sam at gentoo dot org> ---
These issues sometimes appear with -flto -Wlto-type-mismatch but not clear
that's the case here.
  
fche at redhat dot com Feb. 5, 2023, 10:35 a.m. UTC | #2
https://sourceware.org/bugzilla/show_bug.cgi?id=30077

--- Comment #4 from Mark Wielaard <mark at klomp dot org> ---
(In reply to Sam James from comment #2)
> These issues sometimes appear with -flto -Wlto-type-mismatch but not clear
> that's the case here.

Yes, but typedefs don't define new types, just alias types.
Also it looks like this is actually allowed (at least in C11, maybe some
compilers didn't accept it before?):

- a typedef name may be redefined to denote the same type as it currently does,
provided that type is not a variably modified type
  
fche at redhat dot com Feb. 5, 2023, 10:46 a.m. UTC | #3
https://sourceware.org/bugzilla/show_bug.cgi?id=30077

--- Comment #5 from Mark Wielaard <mark at klomp dot org> ---
(In reply to David Edelsohn from comment #3)
> The struct is needed by libdwfl.h to prototype
> 
> extern debuginfod_client *dwfl_get_debuginfod_client (Dwfl *dwfl);
> 
> but that function is defined in debuginfod-client.c protected by
> 
> #ifdef ENABLE_LIBDEBUGINFOD
> 
> It already is protected where it is referenced by an existing macro.  The
> problem is the header logic doesn't match the logic in the file that uses
> that prototype.
> 
> So, again, it would seem better to include the struct from
> debuginfod-client.h directly instead of adding more macros to protect the
> headers and types that already are protected.  Something like:

The public headers are independent and can be used with or without the other
being available. And the function must be defined with or without libdebuginfod
support available or installed.

You cannot use the same guards in the public headers and the implementation
sources because they are independent.

It might be helpful to know in which configuration you are having this issue.
  
fche at redhat dot com Feb. 5, 2023, 9:41 p.m. UTC | #4
https://sourceware.org/bugzilla/show_bug.cgi?id=30077

--- Comment #6 from David Edelsohn <dje at sourceware dot org> ---
The error is reported if one configures and builds with Clang.

Also, yes, this is a C11 feature, but libdwfl/Makefile.in explicitly invokes
the compiler with -std=gnu99 (AM_CFLAGS).
  
fche at redhat dot com Feb. 6, 2023, 9:47 a.m. UTC | #5
https://sourceware.org/bugzilla/show_bug.cgi?id=30077

Mark Wielaard <mark at klomp dot org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |FIXED

--- Comment #7 from Mark Wielaard <mark at klomp dot org> ---
(In reply to David Edelsohn from comment #6)
> The error is reported if one configures and builds with Clang.

Aha. I am not sure things will build with clang. It seems to have a couple more
quirks like not supporting some uses of flexible arrays.

Note that this really is a pendantic warning and shouldn't be enabled by
default imho. You can simply silence it with -Wno-typedef-redefinition

> Also, yes, this is a C11 feature, but libdwfl/Makefile.in explicitly invokes
> the compiler with -std=gnu99 (AM_CFLAGS).

Maybe it is time to switch to gnu11 these days. But since this is in public
headers and we don't control the compiler/standard users use lets simply make
sure there is only one typedef:

commit 45576ab5f24cd39669a418fa8e005b4d04f8e9ca (HEAD -> master)
Author: Mark Wielaard <mark@klomp.org>
Date:   Mon Feb 6 10:21:58 2023 +0100

    debuginfod: Make sure there is only one typedef for debuginfod_client

    Both debuginfod.h and libdwfl.h have a simple typedef for struct
    debuginfod_client. Some compilers pedantically warn when including
    both headers that such typedefs are only officially supported in
    C11. So guard them with _ELFUTILS_DEBUGINFOD_CLIENT_TYPEDEF to
    make them happy.

    https://sourceware.org/bugzilla/show_bug.cgi?id=30077

    Signed-off-by: Mark Wielaard <mark@klomp.org>
  

Patch

--- libdwfl.h.orig      2023-02-03 15:03:57.669810336 -0500
+++ libdwfl.h   2023-02-03 15:00:53.959921348 -0500
@@ -49,8 +49,10 @@ 
    PC location described by an FDE belonging to Dwfl_Thread.  */
 typedef struct Dwfl_Frame Dwfl_Frame;

+#ifndef ENABLE_LIBDEBUGINFOD
 /* Handle for debuginfod-client connection.  */
 typedef struct debuginfod_client debuginfod_client;
+#endif

 /* Callbacks.  */
 typedef struct

--- libdwflP.h.orig     2023-02-03 15:04:29.749793736 -0500
+++ libdwflP.h  2023-02-03 14:53:56.320181520 -0500
@@ -29,6 +29,10 @@ 
 #ifndef _LIBDWFLP_H
 #define _LIBDWFLP_H    1

+#ifdef ENABLE_LIBDEBUGINFOD
+#include "../debuginfod/debuginfod.h"
+#endif
+
 #include <libdwfl.h>
 #include <libebl.h>
 #include <assert.h>
@@ -41,10 +45,6 @@ 
 #include "../libdw/libdwP.h"   /* We need its INTDECLs.  */
 #include "../libdwelf/libdwelfP.h"

-#ifdef ENABLE_LIBDEBUGINFOD
-#include "../debuginfod/debuginfod.h"
-#endif
-
 typedef struct Dwfl_Process Dwfl_Process;

 #define DWFL_ERRORS                                                          \