Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

jhorwitz (4227)

  reversethis-{gro.gnihsams} {ta} {ffej}

System administrator, Perl hacker, author of "Unix System Management Primer Plus" (SAMS 2003), mod_parrot, extproc_perl, Authen::Krb4, Authen::Krb5.

Journal of jhorwitz (4227)

Monday October 04, 2004
07:20 PM

DBD::SQLite alignment fix

[ #21189 ]
I have a patch that fixes DBD::SQLite on Sparc so it passes all its tests and doesn't core dump. Turns out GCC likes to inline its own "optimized" version of memcpy, which assumes 8-byte aligned structures. SQLite does a buttload of casting from char * to structures and back, which wreaks havoc on this assumption.

The solution was to coerce GCC into not using its own inline memcpy without affecting other inlining. Turns out all you have to do is make the size argument a variable rather than a constant. So I changed lines like this:

memcpy(to, from, 8);

to this:

int sz = 8;
memcpy(to, from, sz);

I'll send this off to Matt tonight, and I should also port it to the main SQLite codebase. This took way too long to figure out...

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.
  • Given that memcpy is prototyped void *memcpy(void *dst, const void *src, size_t len); is sqlite actually at fault here? Or is the gcc optimisation buggy? I'm not a sufficiently good C standards guru to know this, even if I looked at precisely what the code is doing. (Which I confess, I haven't)

    • I believe both are at fault. GCC should not provide this optimization in *all* cases, at least without providing an option on those platforms to specifically disable it (curiously, there's an option for MIPS but not Solaris).

      On the SQLite side, arrays of char * were being casted to structs and then memcpy'd. With this layout, every other array element was misaligned on Solaris, but it was fine on x86. Very, very bad. D. Richard Hipp (author of SQLite) and I actually worked out a better solution than m