------------------------------------------------------------
revno: 4079
fixes bug: https://mariadb.atlassian.net/browse/MDEV-5529
committer: Sergei Golubchik <sergii@pisem.net>
branch nick: 5.5
timestamp: Sat 2014-02-15 21:49:11 +0100
message:
  MDEV-5529 Sync libmysqlclient.so symbol versioning across distributions
  
  An attempt to introduce libmysqlclient.so symbol versioning that is
  compatible both with Debian and Fedora all versions: put all symbols into
  libmysqlclient_18 version node (as on Debian), but also put aliases of
  old symbols into libmysqlclient_16 version node (as on Fedora).
  
  Also use a linker script to create aliases of exported symbols, not
  rpm_support.cc source file.
removed:
  libmysql/libmysql.ver.in
  libmysql/rpm_support.cc
renamed:
  libmysql/libmysql_rpm_version.in => libmysql/libmysql_versions.ld.in
modified:
  .bzrignore
  libmysql/CMakeLists.txt
  libmysql/libmysql_versions.ld.in
diff:
=== modified file '.bzrignore'
--- .bzrignore	2013-11-19 14:35:57 +0000
+++ .bzrignore	2014-02-15 20:49:11 +0000
@@ -1432,4 +1432,4 @@ storage/tokudb/ft-index/util/tests/threa
 storage/tokudb/ft-index/utils/tokudb_dump
 storage/tokudb/ft-index/utils/tokudb_gen
 storage/tokudb/ft-index/utils/tokudb_load
-libmysql/libmysql.version
+libmysql/libmysql_versions.ld

=== modified file 'libmysql/CMakeLists.txt'
--- libmysql/CMakeLists.txt	2014-01-22 14:29:36 +0000
+++ libmysql/CMakeLists.txt	2014-02-15 20:49:11 +0000
@@ -242,69 +242,53 @@ IF(CMAKE_SYSTEM_NAME MATCHES "Linux")
   # official API. Define CLIENT_API_EXTRA for the set of symbols, that required to
   # be exported on different platforms.
   
-  IF(RPM)
-    # Fedora & Co declared following functions as part of API 
-    SET(CLIENT_API_EXTRA
-      mysql_default_charset_info
-      mysql_get_charset
-      mysql_get_charset_by_csname
-      mysql_net_realloc
-      mysql_client_errors
-
-      #  Also export the non-renamed variants
-      # (in case someone wants to rebuild mysqli-php or something similar)
-      # See MDEV-4127
-      default_charset_info
-      get_charset
-      get_charset_by_csname
-      net_realloc
-      client_errors
-      THR_KEY_mysys
-    )  
-  
-    # Add special script to fix symbols renames by Fedora
-    SET(CLIENT_SOURCES_EXTRA rpm_support.cc)
-    SET(VERSION_SCRIPT_TEMPLATE 
-    ${CMAKE_CURRENT_SOURCE_DIR}/libmysql_rpm_version.in)	  
-  ELSEIF(DEB)
-    # libmyodbc on Ubuntu is using functions below
-    # If we don't export them, linker would just remove 
-    # them (they are not used inside libmysqlclient)
-    SET(CLIENT_API_EXTRA
-      strfill
-      init_dynamic_string
-    )
-    # MySQL supplied with Ubuntu does not have versioning, bug Debian does.
-    IF(DEB MATCHES "debian") 
-      SET(VERSION_SCRIPT_TEMPLATE ${CMAKE_CURRENT_SOURCE_DIR}/libmysql.ver.in)
-    ENDIF()
-  ENDIF()
+  # Fedora & Co declared following functions as part of API 
+  SET(CLIENT_API_EXTRA
+    mysql_default_charset_info
+    mysql_get_charset
+    mysql_get_charset_by_csname
+    mysql_net_realloc
+    mysql_client_errors
+
+    #  Also export the non-renamed variants
+    # (in case someone wants to rebuild mysqli-php or something similar)
+    # See MDEV-4127
+    default_charset_info
+    get_charset
+    get_charset_by_csname
+    net_realloc
+    client_errors
+    THR_KEY_mysys
+  )  
+
+  # Linker script to version symbols in Fedora- and Debian- compatible way, MDEV-5529
+  SET(VERSION_SCRIPT_TEMPLATE ${CMAKE_CURRENT_SOURCE_DIR}/libmysql_versions.ld.in)
+
+  # Generate version script.  
+  # Create semicolon separated lists of functions to export from 
+  # Since RPM packages use separate versioning for 5.1 API
+  # and 5.5 API (libmysqlclient_16 vs libmysqlclient_18), 
+  # we need 2 lists.
+  SET (CLIENT_API_5_1_LIST)
+  SET (CLIENT_API_5_1_ALIASES)
+  FOREACH (f ${CLIENT_API_FUNCTIONS_5_1})
+    SET(CLIENT_API_5_1_LIST "${CLIENT_API_5_1_LIST}\t${f};\n")
+    SET(CLIENT_API_5_1_ALIASES "${CLIENT_API_5_1_ALIASES}\"${f}@libmysqlclient_16\" = ${f};\n")
+  ENDFOREACH()
+      
+  SET (CLIENT_API_5_5_LIST)
+  FOREACH (f ${CLIENT_API_FUNCTIONS_5_5})
+    SET(CLIENT_API_5_5_LIST "${CLIENT_API_5_5_LIST}\t${f};\n")
+  ENDFOREACH()
+
+  CONFIGURE_FILE(
+    ${VERSION_SCRIPT_TEMPLATE}
+    ${CMAKE_CURRENT_BINARY_DIR}/libmysql_versions.ld
+    @ONLY@
+  )
+  SET(VERSION_SCRIPT_LINK_FLAGS 
+    "-Wl,${CMAKE_CURRENT_BINARY_DIR}/libmysql_versions.ld")
 
-  IF(VERSION_SCRIPT_TEMPLATE)
-    # Generate version script.  
-    # Create semicolon separated lists of functions to export from 
-    # Since RPM packages use separate versioning for 5.1 API
-    # and 5.5 API (libmysqlclient_16 vs libmysqlclient_18), 
-    # we need 2 lists.
-    SET (CLIENT_API_5_1_LIST)
-    FOREACH (f ${CLIENT_API_FUNCTIONS_5_1})
-      SET(CLIENT_API_5_1_LIST "${CLIENT_API_5_1_LIST}\n${f};")
-    ENDFOREACH()
-	
-    SET (CLIENT_API_5_5_LIST)
-    FOREACH (f ${CLIENT_API_FUNCTIONS_5_5})
-      SET(CLIENT_API_5_5_LIST "${CLIENT_API_5_5_LIST}\n${f};")
-    ENDFOREACH()
-
-    CONFIGURE_FILE(
-      ${VERSION_SCRIPT_TEMPLATE}
-      ${CMAKE_CURRENT_BINARY_DIR}/libmysql.version
-      @ONLY@
-    )
-    SET(VERSION_SCRIPT_LINK_FLAGS 
-      "-Wl,--version-script=${CMAKE_CURRENT_BINARY_DIR}/libmysql.version")
-  ENDIF()
-  
 ENDIF()
 
 
@@ -371,9 +355,6 @@ IF(NOT DISABLE_SHARED)
       SOVERSION "${SHARED_LIB_MAJOR_VERSION}")
     IF(LINK_FLAG_NO_UNDEFINED OR VERSION_SCRIPT_LINK_FLAGS)
       GET_TARGET_PROPERTY(libmysql_link_flags libmysql LINK_FLAGS)
-      IF(NOT libmysql_link_flag)
-        SET(libmysql_link_flags)
-      ENDIF()
       SET_TARGET_PROPERTIES(libmysql PROPERTIES LINK_FLAGS 
         "${libmysql_link_flags} ${LINK_FLAG_NO_UNDEFINED} ${VERSION_SCRIPT_LINK_FLAGS}")
     ENDIF() 

=== removed file 'libmysql/libmysql.ver.in'
--- libmysql/libmysql.ver.in	2006-01-17 14:51:08 +0000
+++ libmysql/libmysql.ver.in	1970-01-01 00:00:00 +0000
@@ -1 +0,0 @@
-libmysqlclient_@SHARED_LIB_MAJOR_VERSION@ { global: *; };

=== renamed file 'libmysql/libmysql_rpm_version.in' => 'libmysql/libmysql_versions.ld.in'
--- libmysql/libmysql_rpm_version.in	2013-02-18 19:35:11 +0000
+++ libmysql/libmysql_versions.ld.in	2014-02-15 20:49:11 +0000
@@ -1,62 +1,88 @@
-# This version script is heavily inspired  by Fedora's and Mageia's version scripts for
-# MySQL client shared library. It is used in MariaDB for building RPMs.
+/*
+  This version script is heavily inspired  by Fedora's and Mageia's version
+  scripts for MySQL client shared library.
+  But it was modified to support Debian-compatible versioning too.
 
-libmysqlclient_16 {
+  In RedHat universe, symbols from old libmysqlclient.so.16
+  keep their libmysqlclient_16 version. New symbols added in
+  libmysqlclient.so.18 get the new libmysqlclient_18 version.
+
+  In Debian all symbols in libmysqlclient.so.18 have libmysqlclient_18 version,
+  including symbols that existed in libmysqlclient.so.16
+
+  We solve this by putting all symbols into libmysqlclient_18 version node,
+  but creating aliases for old symbols in the libmysqlclient_16 version node.
+*/
+
+@CLIENT_API_5_1_ALIASES@
+
+/*
+  On Fedora the following symbols are exported, but renamed into a mysql_
+  namespace. We export them as aliases, but keep original symbols too. See
+  MDEV-4127.
+*/
+mysql_default_charset_info = default_charset_info;
+mysql_get_charset = get_charset;
+mysql_get_charset_by_csname = get_charset_by_csname;
+mysql_net_realloc = net_realloc;
+mysql_client_errors = client_errors;
+
+VERSION {
+
+libmysqlclient_18 {
   global:
 @CLIENT_API_5_1_LIST@
+@CLIENT_API_5_5_LIST@
+
+/* Versioning for Fedora additionally exported symbols */
+
+  /*  mysql-connector-odbc requires these */
+	mysql_default_charset_info;
+	mysql_get_charset;
+	mysql_get_charset_by_csname;
+	mysql_net_realloc;
+	default_charset_info;
+	get_charset;
+	get_charset_by_csname;
+	net_realloc;
+
+  /*  PHP's mysqli.so requires this (via the ER() macro) */
+	mysql_client_errors;
+	client_errors;
+
+  local:
+	*;
+};
+
+libmysqlclient_16 {
+  global:
 
-# some stuff from Mageia, I have no idea why it is there
-# But too afraid to throw anything away
+/*
+  Some stuff from Mageia, I have no idea why it is there
+  But too afraid to throw anything away
+*/
 	_fini;
 	_init;
 	my_init;
 	my_progname;
 	myodbc_remove_escape;
 
-# These are documented in Paul DuBois' MySQL book, so we treat them as part
-# of the de-facto API.
+/*
+  These are documented in Paul DuBois' MySQL book,
+  so we treat them as part of the de-facto API.
+*/
 	free_defaults;
 	handle_options;
 	load_defaults;
 	my_print_help;
-# pure-ftpd requires this
+/*  pure-ftpd requires this */
 	my_make_scrambled_password;
-# fedora18 export
+/*  fedora18 export */
 	THR_KEY_mysys;
-# hydra requires this
+/*  hydra requires this */
 	scramble;
-# DBD::mysql requires this
+/*  DBD::mysql requires this */
 	is_prefix;
-  local:
-	*;
 };
 
-libmysqlclient_18 {
-  global:
-	@CLIENT_API_5_5_LIST@
-#
-# Ideally the following symbols wouldn't be exported, but various applications
-# require them.  Fedora limits the namespace damage by prefixing mysql_
-# (see mysql-dubious-exports.patch), which means the symbols are not present
-# in libmysqlclient_16.
-#
-# MariaDB does not do the Fedora-style function renaming via #define in headers, 
-# however it exports mysql_ prefixed symbols in addition to the "normal" ones.
-#
-# To ensure successful recompilation of affected projects, as well as drop-in replacement
-# for MySQL libraries, provided by distribution, both original symbols and their mysql_ 
-# prefixed counterparts have to be exported.
-
-# mysql-connector-odbc requires these
-	mysql_default_charset_info;
-	mysql_get_charset;
-	mysql_get_charset_by_csname;
-	mysql_net_realloc;
-	default_charset_info;
-	get_charset;
-	get_charset_by_csname;
-	net_realloc;
-# PHP's mysqli.so requires this (via the ER() macro)
-	mysql_client_errors;
-	client_errors;
-};
+}

=== removed file 'libmysql/rpm_support.cc'
--- libmysql/rpm_support.cc	2013-01-25 16:26:10 +0000
+++ libmysql/rpm_support.cc	1970-01-01 00:00:00 +0000
@@ -1,41 +0,0 @@
-/*
-  Provide aliases for several symbols, to support drop-in replacement for
-  MariaDB on Fedora and several derives distributions.
-
-  These distributions redefine several symbols (in a way that is no compatible
-  with either MySQL or MariaDB) and export it from the client library ( as seen
-  e.g from this patch)
-http://lists.fedoraproject.org/pipermail/scm-commits/2010-December/537257.html
-
-  MariaDB handles compatibility distribution by providing the same symbols from 
-  the client library if it is built with -DRPM
-
-*/
-#include <errmsg.h>
-#include <my_sys.h>
-#include <mysql.h>
-extern "C" {
-
-CHARSET_INFO *mysql_default_charset_info = default_charset_info;
-
-CHARSET_INFO *mysql_get_charset(uint cs_number, myf flags)
-{
-  return get_charset(cs_number, flags);
-}
-
-CHARSET_INFO *mysql_get_charset_by_csname(const char *cs_name,
-                                           uint cs_flags, myf my_flags)
-{
-   return get_charset_by_csname(cs_name, cs_flags, my_flags);
-}
-
-
-my_bool mysql_net_realloc(NET *net, size_t length)
-{
-   return net_realloc(net,length);
-}
-
-const char **mysql_client_errors = client_errors;
-
-} /*extern "C" */
-
