Re: [PATCH 1/7] omfs: define filesystem structures

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Jamie Lokier
Date: Saturday, March 29, 2008 - 8:29 am

Arnd Bergmann wrote:

That's not quite true.  Some architectures supported by Linux add
"external" padding to the size and alignment of a structure.

	struct my_subtype {
		unsigned char st1, st2;
	};

On Linux/ARM, sizeof(my_subtype) == 4 and __alignof__(my_subtype) == 4.
On Linux/x86, sizeof(my_subtype) == 2 and __alignof__(my_subtype) == 1.

This will break code which expects them to pack into an array, or
which is accessing this structure from a 2-byte aligned address.

This also effects structures containing other structures:

	struct my_type {
		unsigned char a, b, c, d;
		struct my_subtype st[2];
		unsigned char e, f, g, h;
	};

On Linux/ARM, sizeof(my_type) == 16 and __alignof__(my_subtype) == 4.
On Linux/ARM, sizeof(my_type) == 12 and __alignof__(my_subtype) == 1.

This did break one of my programs on Linux.  I had to decide between
using __attribute__((packed)) and losing portability, or stop using a
struct to access the data which was ugly but portable (the structures
had a lot more fields than this example).

-- Jamie
--
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[PATCH 1/7] omfs: define filesystem structures, Bob Copeland, (Wed Mar 26, 5:45 pm)
Re: [PATCH 1/7] omfs: define filesystem structures, Pavel Machek, (Fri Mar 28, 1:19 pm)
Re: [PATCH 1/7] omfs: define filesystem structures, Bob Copeland, (Fri Mar 28, 4:18 pm)
Re: [PATCH 1/7] omfs: define filesystem structures, Arnd Bergmann, (Fri Mar 28, 8:15 pm)
Re: [PATCH 1/7] omfs: define filesystem structures, Jamie Lokier, (Sat Mar 29, 8:29 am)
Re: [PATCH 1/7] omfs: define filesystem structures, Bob Copeland, (Sat Mar 29, 8:16 pm)