AGOS: alignment problems
|Reported by:||SF/knakos||Owned by:||Kirben|
(c'nued from our discussion in irc)
Agos engine crashes at several points, whenever a struct is "applied" to a memory buffer.
Problem: Even though some structures have good sizes (like SubroutineLine which is 8 bytes), by not marking the struct as a packed struct the compiler (gcc) makes the assumption that a struct pointer for these will occur every time at word (32bit) boundary. This assumption is valid if all such structs are statically declared at compile time or malloc'ed at runtime. For performance reasons, these will all yield a pointer at a 4byte boundary. Thus, given this compiler-internal convention and also for performance reasons, the compiler favors word (32bit) accesses when it leads to more efficient code.
But we use (some) of these structs as "masks" onto memory buffers to extract info from, and (some) of these "masks" can be on 2byte boundary (SubroutineLine f.ex). This condition results in unaligned access error, whenever the compiler has optimized code for accessing these structs using 32bit loads/stores.
Solution: Mark the offending structs as packed structs. In particular, any struct we use as a read/write template onto game data. ScummVM generated data (through malloc, static data) with these structs do not need to be packed.
I have not attached a patch as I got the engine running trivially: In intern.h surround all struct definition with our "pack-*.h" includes (excluding all enum definitions). Kirben might want to optimize this a bit, by leaving outside of the pack directives those structs which are used by the engine internally and are not used to read/write game structs (or not of course).
(this error condition should arise in all gcc-arm targets such as gp2x)
Ticket imported from: #1657436. Ticket imported from: patches/711.