Bug #7838 pipe_sig_handler should be static
Submitted: 12 Jan 2005 15:08 Modified: 17 Feb 2005 20:57
Reporter: Sylvain Chapeland Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server Severity:S3 (Non-critical)
Version:4.1.8 OS:Linux (Linux)
Assigned to: Jani Tolonen CPU Architecture:Any

[12 Jan 2005 15:08] Sylvain Chapeland
Description:
Llinking a program with mysql and another library fails. Both libraries export a symbol for a pipe_sig_handler() function. Of course the linker doesn't like it:

/usr/lib/mysql/libmysqlclient.a(libmysql.o)(.text+0x1e0): In function `pipe_sig_handler':
: multiple definition of `pipe_sig_handler'

I had no problem while using 4.0.20, but it appeared immediately after the upgrade to 4.1.8. This is no serious issue, but one should have the freedom of defining function names in his code. (And anyway I have no control over the other library defining the same symbol).

How to repeat:
The "bug" can be seen by compiling the following test program:
gcc test.c `mysql_config --libs`
If renaming pipe_sig_handler by another name in the code, it works fine. It's really just a name confict problem.

test.c:
---------

#include <stdio.h>
#include <signal.h>
#include <mysql/mysql.h>

void pipe_sig_handler(int sig) {
	printf("SIGPIPE received - %d\n",sig);
	return;	
}

int main(){
	MYSQL mysql;
	mysql_init(&mysql);
	
	signal(SIGPIPE,pipe_sig_handler);
	for(;;){
		sleep(1);
	}
	return 0;
}

Suggested fix:
Declare pipe_sig_handler() as static in libmysqlclient, so that the symbol is not visible from outside.
[13 Jan 2005 11:08] Aleksey Kishkin
got:

 gcc test.c `/usr/local/mysql/bin/mysql_config --cflags --libs`
/usr/local/mysql/lib/mysql/libmysqlclient.a(libmysql.o)(.text+0x2400): In function `pipe_sig_handler':
: multiple definition of `pipe_sig_handler'
/tmp/ccIpyLQA.o(.text+0x0): first defined here
/usr/lib/gcc-lib/i486-slackware-linux/3.3.4/../../../../i486-slackware-linux/bin/ld: Warning: size of symbol `pipe_sig_handler' changed from 27 in /tmp/ccIpyLQA.o to 31 in /usr/local/mysql/lib/mysql/libmysqlclient.a(libmysql.o)
collect2: ld returned 1 exit status
[17 Feb 2005 20:57] Jani Tolonen
Changed function name to my_pipe_sig_handler(). Function cannot be
static, as it is used in client.c.