Good eye, thanks for reporting this. Pointers on the stack or in static storage are pointer-aligned by default on all of Apple's platforms.
On Mar 3, 2015, at 7:27 PM, Andy Rahn <andy.rahn at gmail.com> wrote: > > Hi SQLite users; > > I have a question about _sqliteZone_ in mem1.c. I notice that the > address of this static variable is used in a call to > OSAtomicCompareAndSwapPtrBarrier on MacOS and iOS. That system call > is declared in OSAtomic.h, which includes a note about the pointer > alignment of its arguments: > >> * WARNING: all addresses passed to these functions must be "naturally >> aligned", >> * i.e. * <code>int32_t</code> pointers must be 32-bit aligned (low 2 bits of >> * address are zeroes), and <code>int64_t</code> pointers must be 64-bit >> aligned >> * (low 3 bits of address are zeroes.) > > I wonder, therefore, if it might be prudent to declare _sqliteZone_ > with the alignment attribute, so that the compiler is sure to put it > at a 32 / 64 bit aligned address space? e .g. > > static __attribute__((aligned(8))) malloc_zone_t* _sqliteZone_; > > and also, because this local variable is used in that same function: > > __attribute__((aligned(8))) malloc_zone_t* newzone = > malloc_create_zone(4096, 0); > > I see that attribute is used one other place, so this may be an > important nuance. On a 32-bit architecture, it would be safe to use > aligned(4) instead of aligned(8) but I'm not sure anyone will care > about the (possible) 4-byte savings. > > - Andy > _______________________________________________ > sqlite-users mailing list > sqlite-users at mailinglists.sqlite.org > http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users

