DWARF5 DW_AT_data_bit_offset

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

Seems pahole with a recent version of elfutils libdw already handles
most DWARF5 encodings. One thing it doesn't handle yet is
DW_AT_data_bit_offset (this is actually a DWARF4 thing, but gcc only
emits it for -gdwarf-5).

Note that the actual bit offset for the different attributes is defined
differently:

DW_AT_bit_offset: The bit offset attribute describes the offset in bits
of the high order bit of a value of the given type from the high order
bit of the storage unit used to contain that value.

DW_AT_data_bit_offset: the value is an integer constant that specifies
the number of bits from the beginning of the containing entity to the
beginning of the data member.

If there is a DW_AT_data_bit_offset instead of a
DW_AT_data_member_location then there will be no DW_AT_byte_size and no
DW_AT_bit_offset.

DWARF5 has some example for big and little endian in D.2.8 C/C++ Bit-
Field Examples

dwarf_loader.c already seems to do the right thing for little-endian
machines with DW_AT_data_member_location and DW_AT_bit_offset. For
DW_AT_data_bit_offset it doesn't have to do this fixup because it is
already defined as you would expect.

Example that shows the issue:

$ cat bf.c
struct pea
{
  int type;
  long a:1, b:1, c:1;
};

struct pea p;

$ gcc -gdwarf-4 -c bf.c
$ ./pahole ./bf.o 
struct pea {
	int                        type;                 /*     0     4 */

	/* Bitfield combined with previous fields */

	long int                   a:1;                  /*     0:32  8 */
	long int                   b:1;                  /*     0:33  8 */
	long int                   c:1;                  /*     0:34  8 */

	/* size: 8, cachelines: 1, members: 4 */
	/* bit_padding: 29 bits */
	/* last cacheline: 8 bytes */
};
$ gcc -gdwarf-5 -c bf.c
$ ./pahole ./bf.o 
DW_AT_<0xd>=0x21
DW_AT_<0xd>=0x21
DW_AT_<0xd>=0x21
struct pea {
	int                        type;                 /*     0     4 */
	static long int                   a;             /*     0     0 */
	static long int                   b;             /*     0     0 */
	static long int                   c;             /*     0     0 */

	/* size: 8, cachelines: 1, members: 1, static members: 3 */
	/* padding: 4 */
	/* last cacheline: 8 bytes */
};

Note that GCC11 might default to DWARF5.

Cheers,

Mark



[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux