[Box Backup] x86 and ARM differences results in exception in bbackupquery

Ben Summers ben at fluffy.co.uk
Sun Nov 14 12:18:10 GMT 2010


On 13 Nov 2010, at 19:35, Stuart D Gathman wrote:
> 
> On 11/13/2010 04:39 PM, Leif Linderstam wrote:!
>> I made a quick and dirty fix to this particular struct by adding a two-byte dummy field at the end, and the bbackupquery tool worked much better. I could issue commands ls and cd, and got the expected results, but when drilling down in the directory structure I got another fault that I have not tracked down yet. It is a bit risky to use structs in this way if one wants portability between different machine architectures. I have not enough knowledge to say whether it is sufficient to manually pad all structs that are part of the protocol, and if so to what alignment they should be padded. That is why I called the fix a dirty one.
>> 
>> What do you think is the best short- and long-term solutions for this problem?
> I have lots of experience with this issue, and the best solution IMHO is
> to always stream structs in a network portable format.  What portable
> format? 
> 
> a) The style I usually use in C is to declare another struct with only
> char fields, and use a little api with stint(),stshort(),stchar(), etc
> to store various C types.  E.g.
> 
> typedef char FSHORT[2];
> typedef char FLONG[4];

...

Yes, Box Backup does indeed code things this way, eg

  http://boxbackup.org/trac/browser/box/trunk/lib/backupclient/BackupStoreFileWire.h

and is careful to output all such structs in network byte order.


> c) The oo Java style could be used in C.  When writing a struct, call
> the stream writer for that struct.  In C you will have to manually pick
> the correct function, but ANSI C type checking will make sure you used
> the right one.  E.g.


There's also autogenerated 'protocol' code which does this.


The problem appears to be that the gcc ARM compiler is ignoring the structure alignment directives, probably because they're quite expensive on that platform.

A quick google found this:

http://forums.arm.com/index.php?/topic/12616-struct-packing-gcc/

Ben


--
http://bens.me.uk







More information about the Boxbackup mailing list