Bug #25869 generate core file when invoke mysql_init
Submitted: 26 Jan 2007 12:16 Modified: 2 Mar 2007 16:24
Reporter: ni shengzheng Email Updates:
Status: No Feedback Impact on me:
None 
Category:MySQL Server: C API (client library) Severity:S1 (Critical)
Version:5.0/4.1 OS:HP/UX (HP Unix B11.11)
Assigned to: CPU Architecture:Any

[26 Jan 2007 12:16] ni shengzheng
Description:
void handle_signal(int sig)
{
        printf("handle_signal<%d>\n", sig);
}
main()
{
        signal(SIGINT, handle_signal);        
        MYSQL* conn = 0;
        mysql_init(conn);
        mysql_close (conn);
        exit (0);
}
//////////////////////
combine successfully above code with gcc on hp-ux B11.11 as below:
  gcc -o ./test01 test01.c -I/usr/local/mysql/include -L /usr/local/mysql/lib -lmysqlclient -lpthread -lxti -lz -lm -lc -static.
//////////////////////
core file is generated when execute ./test01, and run in gdb as below:
bash-3.00# gdb test01
HP gdb 5.5.0 for PA-RISC 1.1 or 2.0 (narrow), HP-UX 11.00
and target hppa1.1-hp-hpux11.00.
Copyright 1986 - 2001 Free Software Foundation, Inc.
Hewlett-Packard Wildebeest 5.5.0 (based on GDB) is covered by the
GNU General Public License. Type "show copying" to see the conditions to
change it and/or distribute copies. Type "show warranty" for warranty/support.
..
(gdb) run
Starting program: /home/hcheng/cg/merge/test01 

Program received signal SIGSEGV, Segmentation fault
  si_code: 0 - SEGV_UNKNOWN - Unknown Error.
0x7b01ea24 in __thread_sigmask+0x2c () from /usr/lib/libc.2
(gdb) bt
#0  0x7b01ea24 in __thread_sigmask+0x2c () from /usr/lib/libc.2
#1  0x7aee79d8 in _nss_nis_domain+0x2c () from /usr/lib/libnss_nis.1
#2  0x7aee7a98 in _nss_nis_constr+0x28 () from /usr/lib/libnss_nis.1
#3  0x7aee6b48 in _nss_nis_services_constr+0x30 () from /usr/lib/libnss_nis.1
#4  0x8bdd4 in nss_get_backend_u+0x198 ()
#5  0x8c6a0 in nss_search+0xf8 ()
#6  0x6179c in getservbyname+0xe0 ()
#7  0x13194 in mysql_server_init+0x84 ()
#8  0x10eb8 in mysql_init+0x20 ()
#9  0xf3a0 in main+0x40 ()
//////////////////////
here if remove gcc option 'lpthread and static', core will not be generated.
gcc version is 3.3.2
//////////////////////
this is the first report question , thank you for you response..

How to repeat:
nsz1983@163.com
[26 Jan 2007 16:31] Valeriy Kravchuk
Thank you for a problem report. You have to link with -lmysqlclient_r instead of -lmysqlclient if -lpthread is used. Please, check, and inform about the results.

Read http://dev.mysql.com/doc/refman/5.0/en/mysql-config.html also.
[29 Jan 2007 2:36] ni shengzheng
thank you for you reply.
i use -lmysqlclient_r instead of -lmysqlclient, compile is succeed, but core is generated when execute.

gcc -o ./test test.c -I/usr/local/mysql/include -L/usr/local/mysql/lib -lmysqlclient_r -lpthread -lxti -lz -lm -lc -static
[29 Jan 2007 4:37] ni shengzheng
by the way, does the mysqlclient_r library can be compiled with -lpthread and -static??
yesterday i update gcc from 3.3.2 to 3.4.5, and compile code with -lmysqlclient-r and -lpthread, except -static, there no core while exeucte.
so, there are could not compiled as static ????why?
[29 Jan 2007 11:06] Valeriy Kravchuk
Please, send the results of:

find / -name "libmysqlclient_r*" -print 2>/dev/null
find /usr -name "libpthread*" -print 2>/dev/null

Read also the following parts of the manual for some hints:

http://dev.mysql.com/doc/refman/5.0/en/other-unix-notes.html#hp-ux-11-x
http://dev.mysql.com/doc/refman/5.0/en/threaded-clients.html
[30 Jan 2007 1:36] ni shengzheng
the following command of compile is test successfully..
gcc -o ./test test.c -I/usr/local/mysql/include -L/usr/local/mysql/lib -lmysqlclient_r -L/usr/lib -lpthread -lxti -lz -lm -lc
the package i used is mysql-standard-4.1.22-hp-hpux11.11-hppa2.0w.tar.gz.
and if i compile test with "-static", sentence as below:
gcc -o ./test test.c -I/usr/local/mysql/include -L/usr/local/mysql/lib -lmysqlclient_r -L/usr/lib -lpthread -lxti -lz -lm -lc -static
the core is generated when execute test.
need i re-compile mysql with mysql-source.tar.gz??
[30 Jan 2007 3:05] ni shengzheng
bash-3.00# find / -name "libmysqlclient_r*" -print 2>/dev/null
/usr/local/mysql-standard-4.1.22-hp-hpux11.11-hppa2.0w/lib/libmysqlclient_r.a
bash-3.00# find /usr -name "libpthread*" -print 2>/dev/null
/usr/lib/libpthread.1
/usr/lib/pa20_64/libp/libpthread.a
/usr/lib/pa20_64/libpthread.a
/usr/lib/pa20_64/libpthread_tr.a
/usr/lib/pa20_64/libpthread.1
/usr/lib/pa20_64/libpthread.sl
/usr/lib/pa20_64/libpthread_tr.1
/usr/lib/pa20_64/libpthread_tr.sl
/usr/lib/libpthread.sl
/usr/lib/libpthread_tr.1
/usr/lib/libpthread_tr.sl
/usr/lib/libp/libpthread.a
/usr/lib/libpthread.a
/usr/lib/libpthread_tr.a
[31 Jan 2007 12:59] Valeriy Kravchuk
Please, specify the exact version(s) of MySQL server used (5.0.x). Do you use MySQL binaries? If no, please, send the exact version of C compiler used.
[1 Feb 2007 1:23] ni shengzheng
I respective compile program as following method
gcc -o ./test test.c -I/usr/local/mysql/include -L/usr/local/mysql/lib -lmysqlclient -lpthread -lxti -lz -lm -lc -static 
aCC -o ./test test.c -I/usr/local/mysql/include -L/usr/local/mysql/lib -lmysqlclient -lpthread -lxti -lz -lm -lc +A
the core is generated when execute
(if no static ,there will be succeed)
--------------------------------------------------------------------------
the following information from gdb debug is compiled with gcc
--------------------------------------------------------------------------
#0  0xc020b00c in fopen+0x7c () from /usr/lib/libc.2
#1  0xc00ae7ec in _nss_files_setent+0x34 () from /usr/lib/libnss_files.1
#2  0xc00aecf0 in _nss_files_XY_all+0x60 () from /usr/lib/libnss_files.1
#3  0xc00b1a34 in <unknown_procedure> + 0x2c () from /usr/lib/libnss_files.1
#4  0x8e188 in nss_search+0x248 () at lib2funcs.asm:77
#5  0x63398 in getservbyname+0xe0 () at lib2funcs.asm:77
#6  0x1304c in mysql_server_init+0x94 ()
#7  0x10d78 in mysql_init+0x20 ()
#8  0xf2f0 in main () at test.c:7
--------------------------------------------------------------------------
the following information from gdb debug is compiled with aCC
--------------------------------------------------------------------------
#0  0x6e3a0 in kill+0x10 ()
#1  0x9b814 in raise+0x1c ()
#2  0x9b7c8 in abort_C+0x114 ()
#3  0x97ce8 in abort+0x18 ()
#4  0x9b914 in shl_load+0x9c ()
#5  0x90d7c in SO_per_src_lookup+0xbc ()
#6  0x7e524 in nss_get_backend_u+0x100 ()
#7  0x7ee88 in nss_search+0xf8 ()
#8  0x545e4 in getservbyname+0xe0 ()
#9  0x84dc in mysql_server_init+0x84 ()
#10 0x6230 in mysql_init+0x20 ()
#11 0x4780 in main+0x18 ()
--------------------------------------------------------------------------
the following information from gdb debug is compiled with aCC
this program just invoke "getservbyname" function in main that "mysql_init()" is invocked.
--------------------------------------------------------------------------
#0  0x4a3e8 in kill+0x10 ()
#1  0x3bd20 in raise+0x1c ()
#2  0x2e284 in abort_C+0x114 ()
#3  0x25948 in abort+0x18 ()
#4  0x456c in shl_load+0x9c ()------>this function will be inhibit by "static"
#5  0x3febc in SO_per_src_lookup+0xbc ()
#6  0x2e61c in nss_get_backend_u+0x100 ()
#7  0x2ef80 in nss_search+0xf8 ()
#8  0x191c0 in getservbyname+0xe0 ()
#9  0x44bc in main+0x24 ()

as above just mine analysis from gdb debug.
does it correct?
[2 Feb 2007 16:24] Valeriy Kravchuk
Can you, please, try to add call mysql_library_init() call to your test case before calling mysql_init() and check, if it will make any difference. Read http://dev.mysql.com/doc/refman/5.0/en/threaded-clients.html for some details.
[3 Mar 2007 0:00] Bugs System
No feedback was provided for this bug for over a month, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".