Re: [PATCH linux-next] net: batman-adv: use "__packed __aligned(2)" for each structure instead of "__packed(2)" region

From: James Hogan
Date: Sat Jan 18 2014 - 20:11:00 EST

On Saturday 18 January 2014 14:03:26 Antonio Quartulli wrote:
> On 18/01/14 12:31, Chen Gang wrote:
> > Unfortunately, not all compilers assumes the structures within a pack
> > region also need be packed (e.g. metag), so need add a pack explicitly
> > to satisfy all compilers.
> >
> > The related error (under metag with allmodconfig):
> > MODPOST 2952 modules
> >
> > ERROR: "__compiletime_assert_431" [net/batman-adv/batman-adv.ko]
> > undefined!
> > ERROR: "__compiletime_assert_432" [net/batman-adv/batman-adv.ko]
> > undefined!
> > ERROR: "__compiletime_assert_429" [net/batman-adv/batman-adv.ko]
> > undefined!
> > ERROR: "__compiletime_assert_428" [net/batman-adv/batman-adv.ko]
> > undefined!
> > ERROR: "__compiletime_assert_423" [net/batman-adv/batman-adv.ko]
> > undefined!
> >
> > Signed-off-by: Chen Gang <gang.chen.5i5j@xxxxxxxxx>
> David, what do you think about this change?
> Can "__packed __aligned(2)" generate a different structure padding than
> "#pragma pack(2)" ?
> I am not really sure about the difference between the two. But if we
> have the possibility that the padding may change then this patch should
> go into net, otherwise we will have a protocol compatibility problem
> between 3.13 and 3.14.

(Chen: sorry I didn't twig what you were referring to before about #pragma
pack not working)

It appears that the following gcc patch adds support for #pragma pack:

I gave it a quick spin on metag gcc (which is unfortunately stuck on an old
version) and it seems to fix my simple test case so that #pragma pack(2)
becomes equivalent to __packed __aligned(2) (for sizeof and __alignof__).

However, the __packed and __aligned are linux specific macros to abstract
compiler details, whereas #pragma pack appears to be a compiler-specific WIN32
style equivalent to GCC's __attribute__((packed)) and
__attribute__((aligned(2))) (these are what __packed and __aligned use in

Therefore I believe using the Linux abstractions is still more correct here.


Attachment: signature.asc
Description: This is a digitally signed message part.