On alignment

Nicola Pero nicola@brainstorm.co.uk
Tue Apr 22 16:26:00 GMT 2003


> >  > > That packing rule is part of the i86 psABI
> >  > 
> >  > It's still mighty odd, and of course in Ada you have to override this rule
> >  > since it conflicts with the Ada standard, which requires that the default
> >  > minimum alignment of a composite be not less than the alignment of any
> >  > component.
> >
> > It's pretty weird in C++.
> 
> It's the same in C.  Weird or not, that's what the SVR4 psABI says, so
> that's what we do.

I suspect this is not just weird, but it would have consequences for
Objective-C.

The ObjC runtime library is supposed to be able to compute alignments in
structures at runtime (for various tasks, like encoding / decoding /
forwarding).

At runtime, the ObjC runtime library has information about the struct -
the type of each member.  At the moment, it loops on the struct members,
and uses __alignof__ on each of them to get the alignment of that member
inside the struct (then, can read/write the struct members).  As far as I
understand from this discussion, this doesn't work any longer.

For a typical example, look at libobjc/archive.c, functions
objc_write_type() and objc_read_type().

Assuming that we have to live with this weird ABI thing, what alternative
is there in order to compute alignments inside structs at runtime ?

In other words, how can objc_write_type() and objc_read_type() be
fixed/rewritten in order to work with the weird/unsane ABI thing ?

I don't have time to spend on this issue at the moment, but I thought I'd
raise the issue since it seems you're not aware of it.  I can provide
testcases for objc_write_type() and objc_read_type() if needed.



More information about the Gcc mailing list