* also save/restore the size of the padding of record/objectsymtables

* when creating a child class, ignore the padding added to the parent
    in case of objcclasses (gcc/clang also do that; maybe the same
    has to be done for cppclass as well)
  -> objcclass layouts seem to finally completely match the gcc ones

git-svn-id: trunk@18119 -
This commit is contained in:
Jonas Maebe 2011-08-06 18:01:39 +00:00
parent 1c11f6c8b7
commit 0398ff6bf5
4 changed files with 29 additions and 11 deletions

View File

@ -43,7 +43,7 @@ type
{$endif Test_Double_checksum}
const
CurrentPPUVersion = 132;
CurrentPPUVersion = 133;
{ buffer sizes }
maxentrysize = 1024;

View File

@ -3002,6 +3002,7 @@ implementation
trecordsymtable(symtable).padalignment:=shortint(ppufile.getbyte);
trecordsymtable(symtable).usefieldalignment:=shortint(ppufile.getbyte);
trecordsymtable(symtable).datasize:=ppufile.getasizeint;
trecordsymtable(symtable).paddingsize:=ppufile.getword;
trecordsymtable(symtable).ppuload(ppufile);
{ requires usefieldalignment to be set }
symtable.defowner:=self;
@ -3087,6 +3088,7 @@ implementation
ppufile.putbyte(byte(trecordsymtable(symtable).padalignment));
ppufile.putbyte(byte(trecordsymtable(symtable).usefieldalignment));
ppufile.putasizeint(trecordsymtable(symtable).datasize);
ppufile.putword(trecordsymtable(symtable).paddingsize);
end;
ppufile.writeentry(ibrecorddef);
@ -4385,6 +4387,7 @@ implementation
stringdispose(import_lib);
symtable:=tObjectSymtable.create(self,objrealname^,0);
tObjectSymtable(symtable).datasize:=ppufile.getasizeint;
tObjectSymtable(symtable).paddingsize:=ppufile.getword;
tObjectSymtable(symtable).fieldalignment:=shortint(ppufile.getbyte);
tObjectSymtable(symtable).recordalignment:=shortint(ppufile.getbyte);
vmt_offset:=ppufile.getlongint;
@ -4555,6 +4558,7 @@ implementation
else
ppufile.putstring('');
ppufile.putasizeint(tObjectSymtable(symtable).datasize);
ppufile.putword(tObjectSymtable(symtable).paddingsize);
ppufile.putbyte(byte(tObjectSymtable(symtable).fieldalignment));
ppufile.putbyte(byte(tObjectSymtable(symtable).recordalignment));
ppufile.putlongint(vmt_offset);
@ -4804,6 +4808,10 @@ implementation
if (tObjectSymtable(c.symtable).usefieldalignment=C_alignment) and
(tObjectSymtable(symtable).usefieldalignment=C_alignment) then
tObjectSymtable(symtable).fieldalignment:=tObjectSymtable(c.symtable).fieldalignment;
{ the padding is not inherited for Objective-C classes (maybe not
for cppclass either?) }
if objecttype=odt_objcclass then
tObjectSymtable(symtable).datasize:=tObjectSymtable(symtable).datasize-tObjectSymtable(c.symtable).paddingsize;
if (oo_has_vmt in objectoptions) and
(oo_has_vmt in c.objectoptions) then
tObjectSymtable(symtable).datasize:=tObjectSymtable(symtable).datasize-sizeof(pint);

View File

@ -92,14 +92,18 @@ interface
function has_single_field(out sym:tfieldvarsym): boolean;
function get_unit_symtable: tsymtable;
protected
_datasize : asizeint;
{ size in bytes including padding }
_datasize : asizeint;
{ size in bits of the data in case of bitpacked record. Only important during construction, }
{ no need to save in/restore from ppu file. datasize is always (databitsize+7) div 8. }
databitsize : asizeint;
{ size in bytes of padding }
_paddingsize : word;
procedure setdatasize(val: asizeint);
public
function iscurrentunit: boolean; override;
property datasize : asizeint read _datasize write setdatasize;
property paddingsize: word read _paddingsize write _paddingsize;
end;
trecordsymtable = class(tabstractrecordsymtable)
@ -1021,6 +1025,8 @@ implementation
procedure tabstractrecordsymtable.addalignmentpadding;
var
padded_datasize: asizeint;
begin
{ make the record size aligned correctly so it can be
used as elements in an array. For C records we
@ -1043,7 +1049,9 @@ implementation
else
padalignment:=min(recordalignment,usefieldalignment);
end;
_datasize:=align(_datasize,padalignment);
padded_datasize:=align(_datasize,padalignment);
_paddingsize:=padded_datasize-_datasize;
_datasize:=padded_datasize;
end;

View File

@ -1975,11 +1975,12 @@ begin
writeln(space,' Name of Record : ',getstring);
write (space,' Options : ');
readobjectdefoptions;
writeln(space,' FieldAlign : ',getbyte);
writeln(space,' RecordAlign : ',getbyte);
writeln(space,' PadAlign : ',getbyte);
writeln(space,'UseFieldAlignment : ',getbyte);
writeln(space,' DataSize : ',getaint);
writeln(space,' FieldAlign : ',shortint(getbyte));
writeln(space,' RecordAlign : ',shortint(getbyte));
writeln(space,' PadAlign : ',shortint(getbyte));
writeln(space,'UseFieldAlignment : ',shortint(getbyte));
writeln(space,' DataSize : ',getasizeint);
writeln(space,' PaddingSize : ',getword);
if not EndOfEntry then
HasMoreInfos;
{read the record definitions and symbols}
@ -2013,9 +2014,10 @@ begin
end;
writeln(space,' External name : ',getstring);
writeln(space,' Import lib : ',getstring);
writeln(space,' DataSize : ',getaint);
writeln(space,' FieldAlign : ',getbyte);
writeln(space,' RecordAlign : ',getbyte);
writeln(space,' DataSize : ',getasizeint);
writeln(space,' PaddingSize : ',getword);
writeln(space,' FieldAlign : ',shortint(getbyte));
writeln(space,' RecordAlign : ',shortint(getbyte));
writeln(space,' Vmt offset : ',getlongint);
write (space, ' Ancestor Class : ');
readderef('');