public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Manfred Spraul <manfred@colorfullife.com>
To: Anton Blanchard <anton@samba.org>
Cc: torvalds@transmeta.com, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] 2.5 fast poll on ppc64
Date: Thu, 26 Dec 2002 13:09:21 +0100	[thread overview]
Message-ID: <3E0AF171.9050405@colorfullife.com> (raw)
In-Reply-To: <20021226064821.GA21628@krispykreme>

[-- Attachment #1: Type: text/plain, Size: 965 bytes --]

Anton Blanchard wrote:

>Hi,
>
>I was unable to boot 2.5-BK on ppc64 and narrowed it down to the fast
>poll patch.  I found:
>
>offsetof(struct poll_list, entries) == 12 but
>sizeof(struct poll_list) == 16
>
>This means pp+1 did not match up with pp->entries. Im not sure what the
>alignment requirements are for a zero length struct (ie is this a
>compiler bug) but the following patch fixes the problem and also changes
>->len to a long to ensure 8 byte alignment of ->entries on 64bit archs.
>  
>
That seems to be the root of the problem: ->entries requires 4 byte 
alignment, while struct poll_list requires 8 byte alignment. Thus the 
compiler aligns entries to a 4-byte boundary, and rounds up 
sizeof(struct poll_list) to 16.

Attached is a small test case that shows the problem on both 64-bit and 
32-bit platforms. I'm not sure if this is a gcc bug: the Compaq C 
compiler on Tru64 and MSVC on Windows generate the same structure layout.

--
    Manfred

[-- Attachment #2: test.c --]
[-- Type: text/plain, Size: 1524 bytes --]

/*
 * Testcase for a possible compiler bug:
 * structure with flexible array member.
 * offsetof(struct,flexible_member) != sizeof(struct).
 *
 * That seems to be a violation of 6.7.2.1, constraint 16 of the C99
 * standard:
 * "First, the size of the structure shall be equal to the offset of the
 * last element of an otherwise identical structure that replaces the
 * flexible array member with an array of unspecified length.
 */
#include <stdio.h>

/*
 * structure: sizeof() = 4.
 * alignment: 2, due to the short.
 */
struct pollfd {
	short fd;
	char events;
	char revents;
};

/*
 * sizeof: 12
 * alignment: 4, due to the int.
 */
struct n2 {
	/* offset 0 */
	int m;
	/* offset 4 */
	char n;
	/* one byte padding, 'struct pollfd' requires 2 byte alignment */
	/* offset 6 */
	struct pollfd a[1];
	/* offset 10: two bytes padding for 4 byte alignment,
	 * required for the int in this structure */
};

/*
 * sizeof: 8.
 * XXX
 * Is this correct?
 * offsetof(struct n1, a) is 6
 * --> offsetof(struct n1, a) != sizeof(struct n1)
 * XXX
 */
struct n1 {
	/* offset 0 */
	int m;
	/* offset 4 */
	char n;
	/* one byte padding, 'struct pollfd' required 2 byte alignment */
	/* offset 6 */
	struct pollfd a[];
};
	
#define offsetof(a,b) \
		(int)&((a*)NULL)->b

int main(void)
{
	printf("pollfd: sizeof: %d.\n", sizeof(struct pollfd));
	printf("fix: sizeof: %d, offsetof: %d.\n", sizeof(struct n2), offsetof(struct n2, a));
	printf("var: sizeof: %d, offsetof: %d.\n", sizeof(struct n1), offsetof(struct n1, a));
	return 0;
}

  reply	other threads:[~2002-12-26 12:02 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-12-26  6:48 [PATCH] 2.5 fast poll on ppc64 Anton Blanchard
2002-12-26 12:09 ` Manfred Spraul [this message]
  -- strict thread matches above, loose matches on Subject: below --
2002-12-26 12:57 Mikael Pettersson
2002-12-26 13:53 ` Manfred Spraul
2002-12-26 20:55 Mikael Pettersson
2002-12-26 21:23 ` Linus Torvalds
2002-12-26 21:42 ` Manfred Spraul
2002-12-27  0:14 ` Richard Henderson

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=3E0AF171.9050405@colorfullife.com \
    --to=manfred@colorfullife.com \
    --cc=anton@samba.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=torvalds@transmeta.com \
    /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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox