Dwarves Archive on lore.kernel.org
 help / color / Atom feed
From: Arnaldo Carvalho de Melo <acme-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
To: jamal <hadi-fAAogVwAN2Kw5LPnMra/2Q@public.gmane.org>
Cc: dwarves-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: Re: Changing the word-size was: Re: eat your own dog food?
Date: Sun, 13 Jan 2008 16:26:57 -0200
Message-ID: <20080113182657.GI17675@ghostprotocols.net> (raw)
In-Reply-To: <20080113181901.GH17675-f8uhVLnGfZaxAyOMLChx1axOck334EZe@public.gmane.org>

Em Sun, Jan 13, 2008 at 04:19:01PM -0200, Arnaldo Carvalho de Melo escreveu:
> Em Sun, Jan 13, 2008 at 04:07:30PM -0200, Arnaldo Carvalho de Melo escreveu:
> > Em Sun, Jan 13, 2008 at 02:31:06PM -0200, Arnaldo Carvalho de Melo escreveu:
> > > Em Sat, Jan 12, 2008 at 08:15:55PM -0500, jamal escreveu:
> > > > On Sat, 2008-12-01 at 19:42 -0500, jamal wrote:
> > > > 
> > > > In this case the tail padding should be 7.
> > > > 
> > > > The rules say:
> > > > 1) aggregates have alignment equal to that of their most aligned
> > > >   member - which happens to be 8 above
> > > > 2) aggregates have sizes which are a multiple of their alignment
> > > >   This may result in tail padding - the tail contains a char.
> > > > 
> > > > So the padding above should be 7.
> > > 
> > > Working on that, implementing type__most_aligned_member(), that will
> > > recursively find the member that is most aligned, but then how to deal
> > > with packed structs?
> > 
> > Should be fixed now for non-packed structs, please ACK.
> 
> Oops, I concentrated on the tail padding, have to check how we're
> handling rule number 1, but now we infrastructure is there, should be
> easy.

Looks OK:

[acme@doppio examples]$ file align
align: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically
linked (uses shared libs), for GNU/Linux 2.6.9, not stripped
[acme@doppio examples]$ ../build/pahole align
struct foo {
	char                       l;                    /*     0     1 */

	/* XXX 7 bytes hole, try to pack */

	struct {
		unsigned int       b;                    /*     8     4 */
		struct {
			long unsigned int c;             /*    16     8 */
		};                                       /*    16     8 */
	};                                               /*     8    16 */
	char                       a;                    /*    24     1 */

	/* size: 32, cachelines: 1 */
	/* sum members: 18, holes: 1, sum holes: 7 */
	/* padding: 7 */
	/* last cacheline: 32 bytes */
};

[acme@doppio examples]$ ../build/pahole -w4 align
struct foo {
	char                       l;                    /*     0     1 */

	/* XXX 3 bytes hole, try to pack */

	struct {
		unsigned int       b;                    /*     4     4 */
		struct {
			long unsigned int c;             /*     8     4 */
		};                                       /*     8     4 */
	};                                               /*     4     8 */
	char                       a;                    /*    12     1 */

	/* size: 16, cachelines: 1 */
	/* sum members: 10, holes: 1, sum holes: 3 */
	/* padding: 3 */
	/* last cacheline: 16 bytes */
};

Looks ok when going from 32-bit to 64-bit

[acme@doppio examples]$ gcc -m32 -g align.c -o align
[acme@doppio examples]$ file align
align: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV),
dynamically linked (uses shared libs), for GNU/Linux 2.6.9, not stripped

[acme@doppio examples]$ ../build/pahole align
struct foo {
	char                       l;                    /*     0     1 */

	/* XXX 3 bytes hole, try to pack */

	struct {
		unsigned int       b;                    /*     4     4 */
		struct {
			long unsigned int c;             /*     8     4 */
		};                                       /*     8     4 */
	};                                               /*     4     8 */
	char                       a;                    /*    12     1 */

	/* size: 16, cachelines: 1 */
	/* sum members: 10, holes: 1, sum holes: 3 */
	/* padding: 3 */
	/* last cacheline: 16 bytes */
};

[acme@doppio examples]$ ../build/pahole -w8 align
struct foo {
	char                       l;                    /*     0     1 */

	/* XXX 3 bytes hole, try to pack */

	struct {
		unsigned int       b;                    /*     4     4 */

		/* XXX 4 bytes hole, try to pack */

		struct {
			long unsigned int c;             /*    12     8 */
		};                                       /*    12     8 */
	};                                               /*     4    16 */

	/* Bitfield combined with next fields */

	char                       a;                    /*    16     1 */

	/* size: 24, cachelines: 1 */
	/* sum members: 14, holes: 1, sum holes: 3 */
	/* padding: 7 */
	/* last cacheline: 24 bytes */
};

But not when going from 32-bit to 64-bit, sigh :-\

And there is another bug, the bitfield combining code got confused,
because the offset for 'a' is not at 20 as it should even when not
correctly aligning the outernmost unnamed struct.

Will fix.

- Arnaldo
-
To unsubscribe from this list: send the line "unsubscribe dwarves" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

  parent reply index

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-01-10 12:42 jamal
2008-01-10 13:39 ` Arnaldo Carvalho de Melo
     [not found]   ` <20080110133926.GF22437-f8uhVLnGfZaxAyOMLChx1axOck334EZe@public.gmane.org>
2008-01-10 13:55     ` jamal
2008-01-10 14:06       ` Arnaldo Carvalho de Melo
     [not found]         ` <20080110140635.GG22437-f8uhVLnGfZaxAyOMLChx1axOck334EZe@public.gmane.org>
2008-01-10 16:39           ` Arnaldo Carvalho de Melo
     [not found]             ` <20080110163959.GJ22437-f8uhVLnGfZaxAyOMLChx1axOck334EZe@public.gmane.org>
2008-01-10 21:37               ` jamal
2008-01-10 21:44                 ` Arnaldo Carvalho de Melo
     [not found]                   ` <20080110214438.GT22437-f8uhVLnGfZaxAyOMLChx1axOck334EZe@public.gmane.org>
2008-01-11  0:45                     ` jamal
2008-01-11  1:04                       ` jamal
2008-01-10 21:39               ` Arnaldo Carvalho de Melo
     [not found]                 ` <20080110213909.GS22437-f8uhVLnGfZaxAyOMLChx1axOck334EZe@public.gmane.org>
2008-01-10 21:41                   ` jamal
2008-01-12 15:21                     ` Arnaldo Carvalho de Melo
     [not found]                       ` <20080112152109.GA23567-f8uhVLnGfZaxAyOMLChx1axOck334EZe@public.gmane.org>
2008-01-12 15:54                         ` Changing the word-size was: " Arnaldo Carvalho de Melo
     [not found]                           ` <20080112155404.GB23567-f8uhVLnGfZaxAyOMLChx1axOck334EZe@public.gmane.org>
2008-01-12 16:28                             ` Arnaldo Carvalho de Melo
     [not found]                               ` <20080112162808.GC23567-f8uhVLnGfZaxAyOMLChx1axOck334EZe@public.gmane.org>
2008-01-12 17:28                                 ` Arnaldo Carvalho de Melo
     [not found]                                   ` <20080112172856.GD23567-f8uhVLnGfZaxAyOMLChx1axOck334EZe@public.gmane.org>
2008-01-12 18:08                                     ` jamal
2008-01-12 18:42                                       ` Arnaldo Carvalho de Melo
     [not found]                                         ` <20080112184211.GA17675-f8uhVLnGfZaxAyOMLChx1axOck334EZe@public.gmane.org>
2008-01-13  0:42                                           ` jamal
2008-01-13  1:15                                             ` jamal
     [not found]                                               ` <20080113163106.GE17675@ghostprotocols.net>
     [not found]                                                 ` <20080113163106.GE17675-f8uhVLnGfZaxAyOMLChx1axOck334EZe@public.gmane.org>
2008-01-13 18:07                                                   ` Arnaldo Carvalho de Melo
     [not found]                                                     ` <20080113180730.GG17675-f8uhVLnGfZaxAyOMLChx1axOck334EZe@public.gmane.org>
2008-01-13 18:19                                                       ` Arnaldo Carvalho de Melo
     [not found]                                                         ` <20080113181901.GH17675-f8uhVLnGfZaxAyOMLChx1axOck334EZe@public.gmane.org>
2008-01-13 18:26                                                           ` Arnaldo Carvalho de Melo [this message]
     [not found]                                                             ` <20080113182657.GI17675-f8uhVLnGfZaxAyOMLChx1axOck334EZe@public.gmane.org>
2008-01-13 19:13                                                               ` jamal
2008-01-12 21:36                                     ` Arnaldo Carvalho de Melo
     [not found]                                       ` <20080112213635.GC17675-f8uhVLnGfZaxAyOMLChx1axOck334EZe@public.gmane.org>
2008-01-12 22:08                                         ` Arnaldo Carvalho de Melo

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=20080113182657.GI17675@ghostprotocols.net \
    --to=acme-h+wxahxf7alqt0dzr+alfa@public.gmane.org \
    --cc=dwarves-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=hadi-fAAogVwAN2Kw5LPnMra/2Q@public.gmane.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