All of lore.kernel.org
 help / color / mirror / Atom feed
* DWARF5 DW_AT_data_bit_offset
@ 2020-10-02 16:11 Mark Wielaard
  2020-10-02 21:18 ` Arnaldo Carvalho de Melo
  0 siblings, 1 reply; 7+ messages in thread
From: Mark Wielaard @ 2020-10-02 16:11 UTC (permalink / raw)
  To: dwarves

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

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2021-01-28 13:55 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-10-02 16:11 DWARF5 DW_AT_data_bit_offset Mark Wielaard
2020-10-02 21:18 ` Arnaldo Carvalho de Melo
2021-01-21 11:35   ` Mark Wielaard
2021-01-28 12:11     ` [PATCH/RFC] " Arnaldo Carvalho de Melo
2021-01-28 12:54       ` Daniel P. Berrangé
2021-01-28 13:48         ` Arnaldo Carvalho de Melo
2021-01-28 13:54         ` Arnaldo Carvalho de Melo

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.