AMD64 only Segmentation fault (was: 7-STABLE(AMD64)+Qmail-LDAP
core dump)
Xin LI
delphij at delphij.net
Mon Mar 3 22:52:08 UTC 2008
Alexandre Biancalana wrote:
> Hi list,
>
> I found a situation that I can't explain, I have qmail-ldap running
> at some FreeBSD 6.2 without any problem. Friday after Installed a new
> server this time with 7-STABLE. I stated to get core dumped from
> qmail-ldap when they try access the OpenLDAP database.
>
> I compiled/run this simple C program in 7-STABLE i386 and AMD64 and
> the program dumps the core only in AMD64.
I have tried to reproduce the problem and have the following
observations. To make a long story short, you *must* either use the new
ldap_initialize API instead of the old one, or to define LDAP_DEPRECATED
at the risk of having the program to break in the future, and *NOT*
ignoring any warnings issued by the compiler.
So here is the reason why we have a coredump. ldap_init is defined only
when LDAP_DEPRECATED is defined, when ldap.h is included, and by
default, C will assume that the return type is "int".
On i386, this is not a problem because sizeof(int) equals to sizeof(void
*), and the implicit cast would work; On amd64, we have sizeof(int) ==
4 and sizeof(void *) == 8, by casting the result to int (because the
header did not gave the type of ldap_init), and back (because of the
assignment ld =), we lose 4 bytes (the high 32 bits) of the pointer, and
therefore, when referring it we got a SEGV.
This is one of the most common culprit when your 32-bit application
"magically" broken on amd64 :-)
Cheers,
--
Xin LI <delphij at delphij.net> http://www.delphij.net/
FreeBSD - The Power to Serve!
More information about the freebsd-stable
mailing list