Dwarves Archive on lore.kernel.org
 help / color / Atom feed
From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: Mark Wielaard <mark@klomp.org>
Cc: dwarves@vger.kernel.org
Subject: Re: DWARF5 DW_AT_data_bit_offset
Date: Fri, 2 Oct 2020 18:18:19 -0300
Message-ID: <20201002211819.GA127275@kernel.org> (raw)
In-Reply-To: <5ee85ca6e3b06b07c83b150912fbcfc1a4c13e19.camel@klomp.org>

Em Fri, Oct 02, 2020 at 06:11:06PM +0200, Mark Wielaard escreveu:
> 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.

Thanks for the detailed report, I'm releasing v1.18 right now, will look
into that for v1.19.

- Arnaldo

      reply index

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-02 16:11 Mark Wielaard
2020-10-02 21:18 ` Arnaldo Carvalho de Melo [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201002211819.GA127275@kernel.org \
    --to=acme@kernel.org \
    --cc=dwarves@vger.kernel.org \
    --cc=mark@klomp.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Dwarves Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/dwarves/0 dwarves/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 dwarves dwarves/ https://lore.kernel.org/dwarves \
		dwarves@vger.kernel.org
	public-inbox-index dwarves

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.dwarves


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git