Bug #30296 Dynamic plugins fail to load on FreeBSD
Submitted: 8 Aug 2007 9:12 Modified: 15 Nov 2007 7:24
Reporter: Vasil Dimov Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Compiling Severity:S2 (Serious)
Version:5.1 OS:FreeBSD
Assigned to: Antony Curtis CPU Architecture:Any
Tags: Contribution

[8 Aug 2007 9:12] Vasil Dimov
Description:
Attempting to load any dynamic plugin into MySQL under FreeBSD ends up with the following error:

14:37:40 mysql> install plugin aaa soname 'ha_innodb.so';
ERROR 1126 (HY000): Can't open shared library '/mnt/mnt0001/inst-5.1/lib/mysql/ha_innodb.so' (errno: 0 Undefined symbol "_ZN7handler5cloneEP11st_mem_root")

14:38:17 mysql> install plugin aaa soname 'ha_blackhole.so';
ERROR 1126 (HY000): Can't open shared library '/mnt/mnt0001/inst-5.1/lib/mysql/ha_blackhole.so' (errno: 0 Undefined symbol "_ZN7handler5cloneEP11st_mem_root")

14:38:57 mysql> install plugin aaa soname 'ha_example.so';
ERROR 1126 (HY000): Can't open shared library '/mnt/mnt0001/inst-5.1/lib/mysql/ha_example.so' (errno: 0 Undefined symbol "_ZN7handler5cloneEP11st_mem_root")

(regardless of the plugin name requested - "aaa" in this example)

This is because, by default, symbols defined in an executable are not available for resolving undefined references in libraries opened via dlopen().

From http://www.freebsd.org/cgi/man.cgi?query=dlopen:
  NOTES
     ELF executables need to be linked using the -export-dynamic option to
     ld(1) for symbols defined in the executable to become visible to dlsym().

How to repeat:
Try to load a dynamic plugin on FreeBSD.

Suggested fix:
Use -export-dynamic as described in dlopen(3):

--- configure.in.orig   Wed Aug  8 12:08:37 2007
+++ ./configure.in      Mon Aug  6 18:34:43 2007
@@ -1021,24 +1021,25 @@
   *freebsd*|*dragonfly*)
     AC_MSG_WARN([Adding fix for interrupted reads])
     OSVERSION=`sysctl -a | grep osreldate | awk '{ print $2 }'`
     if test "$OSVERSION" -gt "480100" && \
        test "$OSVERSION" -lt "500000" || \
        test "$OSVERSION" -gt "500109"
     then
        CXXFLAGS="$CXXFLAGS -DMYSQLD_NET_RETRY_COUNT=1000000"
     else
        CFLAGS="$CFLAGS -DHAVE_BROKEN_REALPATH"
        CXXFLAGS="$CXXFLAGS -DMYSQLD_NET_RETRY_COUNT=1000000 -DHAVE_BROKEN_REALPATH"
     fi
+    LDFLAGS="$LDFLAGS -export-dynamic"
     ;;
   *netbsd*)
     AC_MSG_WARN([Adding flag -Dunix])
     CFLAGS="$CFLAGS -Dunix"
     CXXFLAGS="$CXXFLAGS -Dunix"
     OVERRIDE_MT_LD_ADD="\$(top_srcdir)/mit-pthreads/obj/libpthread.a"
     ;;
   *bsdi*)
     AC_MSG_WARN([Adding fix for BSDI])
     CFLAGS="$CFLAGS -D__BSD__ -DHAVE_BROKEN_REALPATH"
     AC_DEFINE_UNQUOTED([SOCKOPT_OPTLEN_TYPE], [size_t],
                        [Last argument to get/setsockopt])
[8 Aug 2007 11:19] MySQL Verification Team
Thank you for the bug report and contribution.
[26 Oct 2007 4:19] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/36398

ChangeSet@1.2596, 2007-10-25 21:19:28-07:00, antony@pcg5ppc.xiphis.org +3 -0
  Bug#30296
    "Dynamic plugins fail to load on FreeBSD"
    ELF executables need to be linked using the -export-dynamic option to
    ld(1) for symbols defined in the executable to become visible to dlsym().
    Also, do not build plugins on an all-static build.
[30 Oct 2007 17:35] Antony Curtis
Queued to 5.1-engines and 6.0-engines repositories.
[14 Nov 2007 9:41] Bugs System
Pushed into 6.0.4-alpha
[14 Nov 2007 9:45] Bugs System
Pushed into 5.1.23-rc
[15 Nov 2007 7:24] MC Brown
A note has been added to the 5.1.23 and 6.0.4 changelogs: 

When loading a dynamic plugin on FreeBSD, the plugin would fail to load. This was due to a build error where the required symbols would be not exported correctly.