From ada0b493285392baa63650294be59cbcf9748f00 Mon Sep 17 00:00:00 2001
From: "antony@pcg5ppc.xiphis.org" <>
Date: Thu, 25 Oct 2007 21:19:28 -0700
Subject: [PATCH] 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.

---
 config/ac-macros/plugins.m4 | 11 +++++++++++
 configure.in                | 13 ++++++++++++-
 sql/sql_yacc.yy             |  2 +-
 3 files changed, 24 insertions(+), 2 deletions(-)

diff --git a/config/ac-macros/plugins.m4 b/config/ac-macros/plugins.m4
index 4875456399..8dfb698709 100644
--- a/config/ac-macros/plugins.m4
+++ b/config/ac-macros/plugins.m4
@@ -360,6 +360,17 @@ AC_DEFUN([__MYSQL_EMIT_CHECK_PLUGIN],[
      AC_MSG_ERROR([cannot disable mandatory plugin])
    fi
    [mysql_plugin_]$2=yes
+  ],[
+   case "$with_mysqld_ldflags " in
+     *"-all-static "*)
+       # No need to build shared plugins when mysqld is linked with
+       # -all-static as it won't be able to load them.
+       if test "X[$mysql_plugin_]$2" != Xyes -a \
+               "X[$with_plugin_]$2" != Xyes; then
+	     [with_plugin_]$2=no
+	   fi
+     ;;
+   esac
   ])
   if test "X[$with_plugin_]$2" = Xno; then
     AC_MSG_RESULT([no])
diff --git a/configure.in b/configure.in
index 0fe2f1b551..0c5fe692ed 100644
--- a/configure.in
+++ b/configure.in
@@ -1745,7 +1745,18 @@ then
   LDFLAGS="$LDFLAGS -rdynamic"
   AC_MSG_RESULT("-rdynamic")
 else
-  AC_MSG_RESULT("none")
+  case "$SYSTEM_TYPE$with_mysqld_ldflags " in
+  *freebsd*"-all-static "*|*dragonfly*"-all-static "*)
+    AC_MSG_RESULT("none")
+    ;;
+  *freebsd*|*dragonfly*)
+    MYSQLD_EXTRA_LDFLAGS="$MYSQLD_EXTRA_LDFLAGS -export-dynamic"
+    AC_MSG_RESULT("-export-dynamic")
+    ;;
+  *)
+    AC_MSG_RESULT("none")
+    ;;
+  esac
 fi
 
 dnl Checks for typedefs, structures, and compiler characteristics.
diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy
index 30e62c5d7b..16fda2886f 100644
--- a/sql/sql_yacc.yy
+++ b/sql/sql_yacc.yy
@@ -6492,7 +6492,7 @@ bool_pri:
           { $$= (*$2)(0)->create($1,$3); }
         | bool_pri comp_op all_or_any '(' subselect ')' %prec EQ
           { $$= all_any_subquery_creator($1, $2, $3, $5); }
-        | predicate ;
+        | predicate
         ;
 
 predicate:
-- 
2.30.9