Bug #48461 Error: Symbol not found: _thd_alloc_service on INSTALL PLUGIN
Submitted: 2 Nov 2009 10:49 Modified: 8 Dec 2009 17:05
Reporter: Paul McCullagh (Basic Quality Contributor) (OCA) Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Documentation Severity:S2 (Serious)
Version:5.4.4-alpha OS:Any
Assigned to: Paul DuBois CPU Architecture:Any
Tags: install, pbxt, plugin, qc, thd_alloc_service

[2 Nov 2009 10:49] Paul McCullagh
Description:
It is not possible to link a plug-in dynamically to MySQL 5.4.4, if the plug-in uses thd_alloc().

The problem can be repeated with the PBXT storage engine. INSTALL PLUGIN leads to the following error:

ERROR 1126 (HY000): Can't open shared library '/Users/build/Development/MySQL/60-test/lib/mysql/plugin/libpbxt.so' (errno: 2 dlopen(/Users/build/Development/MySQL/60-test/lib/mysql/plugin/libpbxt.so, 2): Symbol not found: _thd_alloc_service
  Referenced)

The problem is MYSQL_DYNAMIC_PLUGIN is defined which causes thd_alloc() to be 
defined  to use thd_alloc_service. But thd_alloc_service is not 
declared.

How to repeat:
Download and build MySQL 5.4.4 alpha:

bzr branch https://code.launchpad.net/~mysql/mysql-server/mysql-6.0-backup

Download and PBXT and build as follows:

bzr branch lp:pbxt
cd pbxt
./configure --with-mysql=/home/build/repositories/mysql-6.0-backup

make install both MySQL and PBXT (the PBXT plug-in will automatically be installed into the MySQL plug-in directory).

Start the MySQL server, then start mysql and enter:

mysql> install plugin PBXT soname 'libpbxt.so';

Suggested fix:
PBXT links with mysql-6.0.9-alpha (version 6.0.9), but not with mysql-6.0-backup (version 5.4.4).

Running "nm mysqld | grep thd_alloc" on both binaries:

For mysql-6.0-backup, I have:
0000000000581530 T thd_alloc
0000000000b28f00 d thd_alloc_handler

And for mysql-6.0.9-alpha I have:
00000000006129d0 T thd_alloc

In both versions the thd_alloc() function is defined as follows:

extern "C"
void *thd_alloc(MYSQL_THD thd, unsigned int size)
{
 return thd->alloc(size);
}

But 6.0-backup has the following in service_thd_alloc.h:

#ifdef MYSQL_DYNAMIC_PLUGIN

#define thd_alloc(thd,size) (thd_alloc_service->thd_alloc_func((thd), (size)))
...

PBXT is compiled with the MYSQL_DYNAMIC_PLUGIN defined (which should be correct) so there is a problem because thd_alloc_service.c is not linked to mysqld.
[19 Nov 2009 9:14] Sveta Smirnova
Thank you for the report.

When trying to compile PBXT with today 6.0-backup sources I get error:

discover_xt.cc: In function ‘bool hacked_mysql_create_table_no_lock(THD*, const char*, const char*, HA_CREATE_INFO*, Alter_info*, bool, uint)’:
discover_xt.cc:1517: error: argument of type ‘char* (Statement::)()’ does not match ‘const char*’

Can you fix it or indicate revision of mysql-6.0-backup I can compile PBXT with?
[19 Nov 2009 9:38] Sergei Golubchik
Paul, you need to link libpbxt.so with libservices.a - it provides this symbol.

It's a documentation issue, thanks for bringing it up!
[8 Dec 2009 16:01] Paul McCullagh
Hi Sergei,

Thanks for the solution, but this means my Makefile.am will have to be conditional.

Depending on the version of MySQL I must now link libservices.a or not.

Do you have a tip how I can do this?
[8 Dec 2009 16:14] Sergei Golubchik
automake supports conditionals. You can define it in your plug.in file in MYSQL_PLUGIN_ACTIONS. See "info automake conditional"
[8 Dec 2009 17:05] Paul DuBois
Thank you for your bug report. This issue has been addressed in the documentation. The updated documentation will appear on our website shortly, and will be included in the next release of the relevant products.

Modified the 5.5 manual:
http://dev.mysql.com/doc/refman/5.5/en/plugin-creating.html

Edit Makefile.am, which should look something like this:

#Makefile.am example for a plugin

pkgplugindir=$(libdir)/mysql/plugin
INCLUDES= -I$(top_builddir)/include -I$(top_srcdir)/include
#noinst_LTLIBRARIES= mypluglib.la
pkgplugin_LTLIBRARIES= mypluglib.la
mypluglib_la_SOURCES= plugin_example.c
mypluglib_la_LDFLAGS= -module -rpath $(pkgplugindir) \
        -L$(libdir)/mysql -lmysqlservices
mypluglib_la_CFLAGS= -DMYSQL_DYNAMIC_PLUGIN

Also added an entry to the 5.5.0 changelog:
http://dev.mysql.com/doc/refman/5.5/en/news-5-5-0.html

Dynamic plugins now need to be linked with the libmysqlservices.a library. For an example showing what Makefile.am should look like, see Section 21.2.3.3, “Creating a Plugin Library”.