[fpc-pascal] Packed record

Tomas Hajny XHajT03 at mbox.vol.cz
Thu Oct 20 10:59:41 CEST 2005


Florian Klaempfl napsal(a):
> Adriaan van Os wrote:
>> Florian Klaempfl wrote:
>>> Carsten Bager wrote:
>>>
>>>> I am using the compiler on an embedded Arm7 platform (no
>>>> operating system). So fare things are working ok, but now I have
>>>> discovered a problem when packing records (Vi have to maintain
>>>> bindery compatibility with older systems)
>>>> If I have a packed record like this
>>>>
>>>> Test_typ= packed record
>>>>      B:byte;
>>>>      I:LongInt;
>>>> end;
>>>>
>>>> Var
>>>>   Test:Test_typ;
>>>>
>>>> Begin
>>>>   Test.i:=1;
>>>>   Write(test.i);
>>>> End.
>>>>
>>>>
>>>> The output is wrong.
>>>
>>>
>>> Usual ARM cores can't handle unaligned memory accesses and on e.g.
>>> arm-linux you
>>> would get a sigbus exception on your code.
>>>
>>>> If I remove "Packed" the output is OK.
>>>
>>>
>>> What can do is:
>>> - modify your pascal code:
>>>
>>> l:longint;
>>> move(l,Test.i,sizeof(Test.i));  // move can handle unaligned access
>>> and that how
>>> C code usually solves it
>>>
>>> - add an exception handler to your OS to catch unaligned access and
>>> fix things
>>> but emulating the memory access
>>
>>
>> - or fix the compiler to ignore "packed" for ARM. This could be a
>> compiler switch, on by default for ARM (gpc has --ignore-packed).
>>
>
> No. He needs to maintain binary compatibility with an older system so this
> is no
> option, see initial post.

What exactly happens there now (I don't have an ARM, just curious ;-) )?
Is it that the compiler generates the code as it is instructed to do (i.e.
regardless the fact that it might not work under ARM), and that the
particular instruction is just ignored by the CPU (without exception), or
what?

Tomas




More information about the fpc-pascal mailing list