Alexandre Biancalana
2008-Mar-03 22:25 UTC
AMD64 only Segmentation fault (was: 7-STABLE(AMD64)+Qmail-LDAP core dump)
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. The following the C program trigger the core dump #include <stdio.h> #include <stdlib.h> #include <errno.h> #include <unistd.h> #include <lber.h> #include <ldap.h> int main (void ) { LDAP *ld; int rc,version; version=3; if ( (ld = ldap_init("127.0.0.1",LDAP_PORT)) == 0) { perror("Connecting.."); } rc = ldap_set_option(ld, LDAP_OPT_PROTOCOL_VERSION, &version); if ( rc != LDAP_OPT_SUCCESS) { printf("Errorrrr (%s)\n", ldap_err2string(rc)); } } Using the following commands to compile: # gcc -I/usr/local/include -g -c a.c # gcc -L/usr/local/lib -o a a.o -lldap When I run the binary in AMD64 I get this: # ./a Segmentation fault (core dumped) Then I compiled the libldap.so with debug symbols and run the program througth gdb: # gdb a GNU gdb 6.1.1 [FreeBSD] Copyright 2004 Free Software Foundation, Inc. GDB is free software, covered by the GNU General Public License, and you are welcome to change it and/or distribute copies of it under certain conditions. Type "show copying" to see the conditions. There is absolutely no warranty for GDB. Type "show warranty" for details. This GDB was configured as "amd64-marcel-freebsd"... (gdb) run Starting program: /tmp/a Program received signal SIGSEGV, Segmentation fault. ldap_set_option (ld=0xf30040, option=17, invalue=0x7fffffffec2c) at options.c:358 358 assert( LDAP_VALID( ld ) ); (gdb) bt #0 ldap_set_option (ld=0xf30040, option=17, invalue=0x7fffffffec2c) at options.c:358 #1 0x000000000040083c in main () at a.c:19 (gdb) Now I reach to a point that I don't know what more to do.... Any help is *very* appreciated ! Best Regards, Alexandre
Xin LI
2008-Mar-03 22:52 UTC
AMD64 only Segmentation fault (was: 7-STABLE(AMD64)+Qmail-LDAP core dump)
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!