* rtti alignment fixed

This commit is contained in:
florian 2004-10-04 21:23:15 +00:00
parent 4bdae840a3
commit b39c0af01b
5 changed files with 77 additions and 14 deletions

View File

@ -28,7 +28,7 @@
{$define FPCPROCVAR} {$define FPCPROCVAR}
{$define USEEXCEPT} {$define USEEXCEPT}
{$ifdef cpuarm} {$ifdef cpuarm}
{$packrecords c} {$packrecords c}
{$endif cpuarm} {$endif cpuarm}
@ -59,6 +59,7 @@
{$define cpuflags} {$define cpuflags}
{$define noopt} {$define noopt}
{$define cputargethasfixedstack} {$define cputargethasfixedstack}
{$define cpurequiresproperalignment}
{$endif sparc} {$endif sparc}
{$ifdef powerpc} {$ifdef powerpc}
@ -72,6 +73,7 @@
{$define cpuneedsdiv32helper} {$define cpuneedsdiv32helper}
{$define cputargethasfixedstack} {$define cputargethasfixedstack}
{$define noopt} {$define noopt}
{$define cpurequiresproperalignment}
{$endif arm} {$endif arm}
{$ifdef m68k} {$ifdef m68k}
@ -82,7 +84,10 @@
{ {
$Log$ $Log$
Revision 1.41 2004-09-21 19:59:51 peter Revision 1.42 2004-10-04 21:23:15 florian
* rtti alignment fixed
Revision 1.41 2004/09/21 19:59:51 peter
* x86_64 fixes * x86_64 fixes
* cleanup of fpcdefs.icn * cleanup of fpcdefs.icn

View File

@ -3261,6 +3261,9 @@ implementation
begin begin
rttiList.concat(Tai_const.Create_8bit(tkrecord)); rttiList.concat(Tai_const.Create_8bit(tkrecord));
write_rtti_name; write_rtti_name;
{$ifdef cpurequiresproperalignment}
rttilist.concat(Tai_align.Create(sizeof(TConstPtrUInt)));
{$endif cpurequiresproperalignment}
rttiList.concat(Tai_const.Create_32bit(size)); rttiList.concat(Tai_const.Create_32bit(size));
Count:=0; Count:=0;
FRTTIType:=rt; FRTTIType:=rt;
@ -5523,6 +5526,9 @@ implementation
rttiList.concat(Tai_const.Create_8bit(proctypesinfo)); rttiList.concat(Tai_const.Create_8bit(proctypesinfo));
rttiList.concat(Tai_const.Create_8bit(length(tpropertysym(sym).realname))); rttiList.concat(Tai_const.Create_8bit(length(tpropertysym(sym).realname)));
rttiList.concat(Tai_string.Create(tpropertysym(sym).realname)); rttiList.concat(Tai_string.Create(tpropertysym(sym).realname));
{$ifdef cpurequiresproperalignment}
rttilist.concat(Tai_align.Create(sizeof(TConstPtrUInt)));
{$endif cpurequiresproperalignment}
end; end;
else internalerror(1509992); else internalerror(1509992);
end; end;
@ -5698,7 +5704,9 @@ implementation
{ generate the name } { generate the name }
rttiList.concat(Tai_const.Create_8bit(length(objrealname^))); rttiList.concat(Tai_const.Create_8bit(length(objrealname^)));
rttiList.concat(Tai_string.Create(objrealname^)); rttiList.concat(Tai_string.Create(objrealname^));
{$ifdef cpurequiresproperalignment}
rttilist.concat(Tai_align.Create(sizeof(TConstPtrUInt)));
{$endif cpurequiresproperalignment}
case rt of case rt of
initrtti : initrtti :
begin begin
@ -5740,11 +5748,19 @@ implementation
rttiList.concat(Tai_const.Create_8bit(length(current_module.realmodulename^))); rttiList.concat(Tai_const.Create_8bit(length(current_module.realmodulename^)));
rttiList.concat(Tai_string.Create(current_module.realmodulename^)); rttiList.concat(Tai_string.Create(current_module.realmodulename^));
{$ifdef cpurequiresproperalignment}
rttilist.concat(Tai_align.Create(sizeof(TConstPtrUInt)));
{$endif cpurequiresproperalignment}
{ write published properties count } { write published properties count }
count:=0; count:=0;
symtable.foreach({$ifdef FPCPROCVAR}@{$endif}count_published_properties,nil); symtable.foreach({$ifdef FPCPROCVAR}@{$endif}count_published_properties,nil);
rttiList.concat(Tai_const.Create_16bit(count)); rttiList.concat(Tai_const.Create_16bit(count));
{$ifdef cpurequiresproperalignment}
rttilist.concat(Tai_align.Create(sizeof(TConstPtrUInt)));
{$endif cpurequiresproperalignment}
{ count is used to write nameindex } { count is used to write nameindex }
{ but we need an offset of the owner } { but we need an offset of the owner }
@ -6184,7 +6200,10 @@ implementation
end. end.
{ {
$Log$ $Log$
Revision 1.256 2004-09-21 23:36:51 hajny Revision 1.257 2004-10-04 21:23:15 florian
* rtti alignment fixed
Revision 1.256 2004/09/21 23:36:51 hajny
* SetTextLineEnding implemented, FileRec.Name position alignment for CPU64 * SetTextLineEnding implemented, FileRec.Name position alignment for CPU64
Revision 1.255 2004/09/21 17:25:12 peter Revision 1.255 2004/09/21 17:25:12 peter

View File

@ -127,6 +127,16 @@
{$endif HASINTF} {$endif HASINTF}
function aligntoptr(p : pointer) : pointer;
begin
{$ifdef FPC_REQUIRES_PROPER_ALIGNMENT}
if (ptrint(p) mod sizeof(ptrint))<>0 then
inc(ptrint(p),sizeof(ptrint)-ptrint(p) mod sizeof(ptrint));
result:=p;
{$endif FPC_REQUIRES_PROPER_ALIGNMENT}
end;
{**************************************************************************** {****************************************************************************
TOBJECT TOBJECT
****************************************************************************} ****************************************************************************}
@ -552,6 +562,7 @@
inc(Temp); inc(Temp);
I:=Temp^; I:=Temp^;
inc(temp,I+1); // skip name string; inc(temp,I+1); // skip name string;
temp:=aligntoptr(temp);
{$ifdef FPC_REQUIRES_PROPER_ALIGNMENT} {$ifdef FPC_REQUIRES_PROPER_ALIGNMENT}
move(PRecRec(Temp)^.Count,Count,sizeof(Count)); move(PRecRec(Temp)^.Count,Count,sizeof(Count));
{$else FPC_REQUIRES_PROPER_ALIGNMENT} {$else FPC_REQUIRES_PROPER_ALIGNMENT}
@ -745,7 +756,10 @@
{ {
$Log$ $Log$
Revision 1.38 2004-04-29 21:33:22 florian Revision 1.39 2004-10-04 21:26:16 florian
* rtti alignment fixed
Revision 1.38 2004/04/29 21:33:22 florian
* fixed tobject.dispatch for 64 bit cpus * fixed tobject.dispatch for 64 bit cpus
Revision 1.37 2004/04/28 20:48:20 peter Revision 1.37 2004/04/28 20:48:20 peter

View File

@ -80,7 +80,7 @@ PArrayRec = ^TArrayRec;
TArrayRec = record TArrayRec = record
Size,Count : Longint; Size,Count : Longint;
Info : Pointer; Info : Pointer;
end; end;
Procedure fpc_Initialize (Data,TypeInfo : pointer);saveregisters;[Public,Alias : 'FPC_INITIALIZE']; {$ifdef hascompilerproc} compilerproc; {$endif} Procedure fpc_Initialize (Data,TypeInfo : pointer);saveregisters;[Public,Alias : 'FPC_INITIALIZE']; {$ifdef hascompilerproc} compilerproc; {$endif}
@ -124,6 +124,7 @@ begin
inc(Temp); inc(Temp);
I:=Temp^; I:=Temp^;
inc(temp,I+1); // skip name string; inc(temp,I+1); // skip name string;
temp:=aligntoptr(temp);
{$ifdef FPC_REQUIRES_PROPER_ALIGNMENT} {$ifdef FPC_REQUIRES_PROPER_ALIGNMENT}
move(PRecRec(Temp)^.Count,Count,sizeof(Count)); // get element Count move(PRecRec(Temp)^.Count,Count,sizeof(Count)); // get element Count
For I:=1 to count Do For I:=1 to count Do
@ -196,6 +197,7 @@ begin
inc(Temp); inc(Temp);
I:=Temp^; I:=Temp^;
inc(temp,I+1); // skip name string; inc(temp,I+1); // skip name string;
temp:=aligntoptr(temp);
{$ifdef FPC_REQUIRES_PROPER_ALIGNMENT} {$ifdef FPC_REQUIRES_PROPER_ALIGNMENT}
move(PRecRec(Temp)^.Count,Count,sizeof(Count)); // get element Count move(PRecRec(Temp)^.Count,Count,sizeof(Count)); // get element Count
For I:=1 to count Do For I:=1 to count Do
@ -272,6 +274,7 @@ begin
Inc(Temp); Inc(Temp);
I:=Temp^; I:=Temp^;
temp:=temp+(I+1); // skip name string; temp:=temp+(I+1); // skip name string;
temp:=aligntoptr(temp);
{$ifdef FPC_REQUIRES_PROPER_ALIGNMENT} {$ifdef FPC_REQUIRES_PROPER_ALIGNMENT}
move(PRecRec(Temp)^.Count,Count,sizeof(Count)); // get element Count move(PRecRec(Temp)^.Count,Count,sizeof(Count)); // get element Count
For I:=1 to count Do For I:=1 to count Do
@ -345,6 +348,7 @@ begin
inc(Temp); inc(Temp);
I:=temp^; I:=temp^;
inc(temp,I+1); // skip name string; inc(temp,I+1); // skip name string;
temp:=aligntoptr(temp);
{$ifdef FPC_REQUIRES_PROPER_ALIGNMENT} {$ifdef FPC_REQUIRES_PROPER_ALIGNMENT}
move(PRecRec(Temp)^.Count,Count,sizeof(Count)); // get element Count move(PRecRec(Temp)^.Count,Count,sizeof(Count)); // get element Count
For I:=1 to count Do For I:=1 to count Do
@ -381,7 +385,10 @@ procedure fpc_finalize_array(data,typeinfo : pointer;count,size : longint); [Pub
{ {
$Log$ $Log$
Revision 1.14 2004-08-18 21:03:35 florian Revision 1.15 2004-10-04 21:26:16 florian
* rtti alignment fixed
Revision 1.14 2004/08/18 21:03:35 florian
* sparc uses wait4 as well * sparc uses wait4 as well
Revision 1.13 2004/07/02 21:21:09 peter Revision 1.13 2004/07/02 21:21:09 peter

View File

@ -133,7 +133,11 @@ unit typinfo;
end; end;
// unsed, just for completeness // unsed, just for completeness
TPropData = packed record TPropData =
{$ifndef FPC_REQUIRES_PROPER_ALIGNMENT}
packed
{$endif FPC_REQUIRES_PROPER_ALIGNMENT}
record
PropCount : Word; PropCount : Word;
PropList : record end; PropList : record end;
end; end;
@ -281,6 +285,16 @@ type
Auxiliary methods Auxiliary methods
---------------------------------------------------------------------} ---------------------------------------------------------------------}
function aligntoptr(p : pointer) : pointer;
begin
{$ifdef FPC_REQUIRES_PROPER_ALIGNMENT}
if (ptrint(p) mod sizeof(ptrint))<>0 then
inc(ptrint(p),sizeof(ptrint)-ptrint(p) mod sizeof(ptrint));
result:=p;
{$endif FPC_REQUIRES_PROPER_ALIGNMENT}
end;
Function GetEnumName(TypeInfo : PTypeInfo;Value : Integer) : string; Function GetEnumName(TypeInfo : PTypeInfo;Value : Integer) : string;
Var PS : PShortString; Var PS : PShortString;
@ -407,7 +421,7 @@ end;
Function GetTypeData(TypeInfo : PTypeInfo) : PTypeData; Function GetTypeData(TypeInfo : PTypeInfo) : PTypeData;
begin begin
GetTypeData:=PTypeData(pointer(TypeInfo)+2+PByte(pointer(TypeInfo)+1)^); GetTypeData:=PTypeData(aligntoptr(PTypeData(pointer(TypeInfo)+2+PByte(pointer(TypeInfo)+1)^)));
end; end;
@ -428,7 +442,7 @@ begin
// skip the name // skip the name
hp:=GetTypeData(Typeinfo); hp:=GetTypeData(Typeinfo);
// the class info rtti the property rtti follows immediatly // the class info rtti the property rtti follows immediatly
pd:=pointer(pointer(@hp^.UnitName)+Length(hp^.UnitName)+1); pd:=aligntoptr(pointer(pointer(@hp^.UnitName)+Length(hp^.UnitName)+1));
Result:=@pd^.PropList; Result:=@pd^.PropList;
for i:=1 to pd^.PropCount do for i:=1 to pd^.PropCount do
begin begin
@ -436,7 +450,7 @@ begin
if Upcase(Result^.Name)=P then if Upcase(Result^.Name)=P then
exit; exit;
// skip to next property // skip to next property
Result:=PPropInfo(pointer(@Result^.Name)+byte(Result^.Name[0])+1); Result:=PPropInfo(aligntoptr(pointer(@Result^.Name)+byte(Result^.Name[0])+1));
end; end;
// parent class // parent class
Typeinfo:=hp^.ParentInfo; Typeinfo:=hp^.ParentInfo;
@ -533,17 +547,18 @@ Var
begin begin
TD:=GetTypeData(TypeInfo); TD:=GetTypeData(TypeInfo);
// Get this objects TOTAL published properties count // Get this objects TOTAL published properties count
TP:=(@TD^.UnitName+Length(TD^.UnitName)+1); TP:=aligntoptr(PPropInfo(aligntoptr((@TD^.UnitName+Length(TD^.UnitName)+1))));
Count:=PWord(TP)^; Count:=PWord(TP)^;
// Now point TP to first propinfo record. // Now point TP to first propinfo record.
Inc(Pointer(TP),SizeOF(Word)); Inc(Pointer(TP),SizeOF(Word));
tp:=aligntoptr(tp);
While Count>0 do While Count>0 do
begin begin
PropList^[0]:=TP; PropList^[0]:=TP;
Inc(Pointer(PropList),SizeOf(Pointer)); Inc(Pointer(PropList),SizeOf(Pointer));
// Point to TP next propinfo record. // Point to TP next propinfo record.
// Located at Name[Length(Name)+1] ! // Located at Name[Length(Name)+1] !
TP:=PPropInfo(pointer(@TP^.Name)+PByte(@TP^.Name)^+1); TP:=aligntoptr(PPropInfo(pointer(@TP^.Name)+PByte(@TP^.Name)^+1));
Dec(Count); Dec(Count);
end; end;
// recursive call for parent info. // recursive call for parent info.
@ -1475,7 +1490,10 @@ end;
end. end.
{ {
$Log$ $Log$
Revision 1.28 2004-08-16 16:12:28 peter Revision 1.29 2004-10-04 21:26:16 florian
* rtti alignment fixed
Revision 1.28 2004/08/16 16:12:28 peter
* patch from mattias to fix endianness and bufferoverflow with * patch from mattias to fix endianness and bufferoverflow with
1 and 2 byte ordinals 1 and 2 byte ordinals