Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 03 Mar 2008 14:51:59 -0800
From:      Xin LI <delphij@delphij.net>
To:        Alexandre Biancalana <biancalana@gmail.com>
Cc:        freebsd-stable@freebsd.org
Subject:   Re: AMD64 only Segmentation fault (was: 7-STABLE(AMD64)+Qmail-LDAP core	dump)
Message-ID:  <47CC810F.5030807@delphij.net>
In-Reply-To: <8e10486b0803031424x31556698qa1bd1bbab8e8376f@mail.gmail.com>
References:  <8e10486b0803031424x31556698qa1bd1bbab8e8376f@mail.gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help
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@delphij.net>	http://www.delphij.net/
FreeBSD - The Power to Serve!



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?47CC810F.5030807>