Bug 29711 - In libdw.h struct Dwarf, struct Dwarf_Abbrev is defined using typedef and not using #include <libdwP.h> is not the way to comply with the specification?
Summary: In libdw.h struct Dwarf, struct Dwarf_Abbrev is defined using typedef and not...
Status: RESOLVED NOTABUG
Alias: None
Product: elfutils
Classification: Unclassified
Component: libdw (show other bugs)
Version: unspecified
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2022-10-21 01:30 UTC by lin zhuorong
Modified: 2022-10-27 21:30 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed: 2022-10-21 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description lin zhuorong 2022-10-21 01:30:34 UTC
Is directly typedef an undefined struct not in compliance with the specification.

libdw.h
```
typedef struct Dwarf_Abbrev Dwarf_Abbrev;

/* Returned to show the last DIE has be returned.  */
#define DWARF_END_ABBREV ((Dwarf_Abbrev *) -1l)

/* Source code line information for CU.  */
typedef struct Dwarf_Lines_s Dwarf_Lines;

/* One source code line information.  */
typedef struct Dwarf_Line_s Dwarf_Line;

/* Source file information.  */
typedef struct Dwarf_Files_s Dwarf_Files;

/* One address range record.  */
typedef struct Dwarf_Arange_s Dwarf_Arange;

/* Address ranges of a file.  */
typedef struct Dwarf_Aranges_s Dwarf_Aranges;
```

libdwP.h
```

/* Abbreviation representation.  */
struct Dwarf_Abbrev
{
  Dwarf_Off offset;	  /* Offset to start of abbrev into .debug_abbrev.  */
  unsigned char *attrp;   /* Pointer to start of attribute name/form pairs. */
  bool has_children : 1;  /* Whether or not the DIE has children. */
  unsigned int code : 31; /* The (unique) abbrev code.  */
  unsigned int tag;	  /* The tag of the DIE. */
} attribute_packed;

#include "dwarf_abbrev_hash.h"


/* Files in line information records.  */
struct Dwarf_Files_s
  {
    unsigned int ndirs;
    unsigned int nfiles;
    struct Dwarf_Fileinfo_s
    {
      char *name;
      Dwarf_Word mtime;
      Dwarf_Word length;
    } info[0];
    /* nfiles of those, followed by char *[ndirs].  */
  };
typedef struct Dwarf_Fileinfo_s Dwarf_Fileinfo;


/* Representation of a row in the line table.  */

struct Dwarf_Line_s
{
  Dwarf_Files *files;

  Dwarf_Addr addr;
  unsigned int file;
  int line;
  unsigned short int column;
  unsigned int is_stmt:1;
  unsigned int basic_block:1;
  unsigned int end_sequence:1;
  unsigned int prologue_end:1;
  unsigned int epilogue_begin:1;
  /* The remaining bit fields are not flags, but hold values presumed to be
     small.  All the flags and other bit fields should add up to 48 bits
     to give the whole struct a nice round size.  */
  unsigned int op_index:8;
  unsigned int isa:8;
  unsigned int discriminator:24;
};

struct Dwarf_Lines_s
{
  size_t nlines;
  struct Dwarf_Line_s info[0];
};
```
Comment 1 Frank Ch. Eigler 2022-10-21 01:44:36 UTC
No specification requires elfutils to provide an other than forward declaration of these types.  Keeping the definitions private is fine, given that opaque pointers are used in the various libdw* api calls to clients.