Skip to content

Commit a77a678

Browse files
author
Tor Didriksen
committed
Bug#35046862 Need a MYSQL_ADD_CLIENT_PLUGIN cmake macro for libmysql plugins
We already have a cmake macro MYSQL_ADD_PLUGIN, which takes an option CLIENT_ONLY. Change it to not add compile definition MYSQL_DYNAMIC_PLUGIN to CLIENT_ONLY plugins. Add a new option NO_UNDEFINED to MYSQL_ADD_PLUGIN. It will add linker flags -Wl,--no-undefined on non-sanitizer Linux builds. Turn it ON for all CLIENT_ONLY plugins to ensure there are no missing symbols. The cmake code for "custom" SASL library would previously disable KERBEROS completely if the provided SASL library was built without KERBEROS. Change this to only disable KERBEROS for the LDAP client authentication plugin. Extend the cmake option WITH_CUSTOM_LIBRARIES to also look for "custom" CURL library. This is for easier testing of custom SSL/KERBEROS/SASL/LDAP/CURL, which must all be provided together in order to have a consistent build. Change-Id: Iafd674297d459268f7bb3afa1e3140ff4cfb0478 (cherry picked from commit fa80793793f1253b5a78d5ad104d6eef835d1353)
1 parent 4ed7ac2 commit a77a678

File tree

7 files changed

+31
-54
lines changed

7 files changed

+31
-54
lines changed

CMakeLists.txt

+3-2
Original file line numberDiff line numberDiff line change
@@ -1757,10 +1757,11 @@ IF(WITH_CUSTOM_LIBRARIES)
17571757
FILE(GLOB WITH_KERBEROS "${WITH_CUSTOM_LIBRARIES}/krb5*")
17581758
FILE(GLOB WITH_SASL "${WITH_CUSTOM_LIBRARIES}/cyrus-sasl*")
17591759
FILE(GLOB WITH_LDAP "${WITH_CUSTOM_LIBRARIES}/openldap*")
1760-
FOREACH(WITH_OPT WITH_SSL WITH_KERBEROS WITH_SASL WITH_LDAP)
1760+
FILE(GLOB WITH_CURL "${WITH_CUSTOM_LIBRARIES}/curl*")
1761+
FOREACH(WITH_OPT WITH_SSL WITH_KERBEROS WITH_SASL WITH_LDAP WITH_CURL)
17611762
IF(IS_DIRECTORY ${${WITH_OPT}})
17621763
SET(${WITH_OPT} ${${WITH_OPT}} CACHE INTERNAL "" FORCE)
1763-
MESSAGE(STATUS "${WITH_OPT} ${${WITH_SSL}}")
1764+
MESSAGE(STATUS "${WITH_OPT} ${${WITH_OPT}}")
17641765
ELSE()
17651766
MESSAGE(WARNING "${WITH_OPT} not found") # This should be FATAL_ERROR
17661767
ENDIF()

cmake/plugin.cmake

+14-2
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ MACRO(MYSQL_ADD_PLUGIN plugin_arg)
2929
DEFAULT_LEGACY_ENGINE
3030
MANDATORY # not actually a plugin, always builtin
3131
MODULE_ONLY # build only as shared library
32+
NO_UNDEFINED # add -Wl,--no-undefined on Linux, relevant for MODULE_ONLY
3233
SKIP_INSTALL
3334
STATIC_ONLY
3435
STORAGE_ENGINE
@@ -190,13 +191,24 @@ MACRO(MYSQL_ADD_PLUGIN plugin_arg)
190191
MY_TARGET_LINK_OPTIONS(${target}
191192
"LINKER:--compress-debug-sections=zlib")
192193
ENDIF()
193-
SET_TARGET_PROPERTIES (${target} PROPERTIES PREFIX ""
194-
COMPILE_DEFINITIONS "MYSQL_DYNAMIC_PLUGIN")
194+
SET_TARGET_PROPERTIES (${target} PROPERTIES PREFIX "")
195+
196+
# CLIENT_ONLY plugins should have no undefined symbols.
197+
IF(ARG_CLIENT_ONLY)
198+
SET(ARG_NO_UNDEFINED ON)
199+
ENDIF()
200+
201+
IF(ARG_NO_UNDEFINED AND LINK_FLAG_NO_UNDEFINED)
202+
MY_TARGET_LINK_OPTIONS(${target} "${LINK_FLAG_NO_UNDEFINED}")
203+
ENDIF()
204+
195205
IF(WIN32_CLANG AND WITH_ASAN)
196206
TARGET_LINK_LIBRARIES(${target}
197207
"${ASAN_LIB_DIR}/clang_rt.asan_dll_thunk-x86_64.lib")
198208
ENDIF()
199209
IF(NOT ARG_CLIENT_ONLY)
210+
SET_TARGET_PROPERTIES (${target} PROPERTIES
211+
COMPILE_DEFINITIONS "MYSQL_DYNAMIC_PLUGIN")
200212
TARGET_LINK_LIBRARIES (${target} mysqlservices)
201213
ENDIF()
202214

cmake/sasl.cmake

+2-9
Original file line numberDiff line numberDiff line change
@@ -281,18 +281,11 @@ MACRO(MYSQL_CHECK_SASL_DLLS)
281281
STRING(REPLACE ";" " " SASL_DEPENDS_ON "${SASL_DEPENDS_ON}")
282282
IF(NOT SASL_DEPENDS_ON MATCHES "libkrb5")
283283
MESSAGE(WARNING "This SASL library is built without KERBEROS")
284+
MESSAGE(WARNING "DEPENDENCIES are ${SASL_DEPENDS_ON}")
285+
# Disable KERBEROS for LDAP client authentication plugin.
284286
SET(SASL_WITHOUT_KERBEROS 1)
285-
UNSET(KERBEROS_CUSTOM_LIBRARY CACHE)
286-
UNSET(KERBEROS_CUSTOM_LIBRARY)
287-
UNSET(KERBEROS_FOUND CACHE)
288-
UNSET(KERBEROS_FOUND)
289-
UNSET(KERBEROS_LIBRARIES CACHE)
290-
UNSET(KERBEROS_LIBRARIES)
291287
UNSET(KERBEROS_LIB_CONFIGURED CACHE)
292288
UNSET(KERBEROS_LIB_CONFIGURED)
293-
UNSET(KERBEROS_SYSTEM_LIBRARY CACHE)
294-
UNSET(KERBEROS_SYSTEM_LIBRARY)
295-
SET(WITH_KERBEROS "none" CACHE STRING "" FORCE)
296289
ENDIF()
297290

298291
COPY_CUSTOM_SHARED_LIBRARY("${SASL_CUSTOM_LIBRARY}" ""

libmysql/authentication_kerberos/CMakeLists.txt

+2-4
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ IF((KERBEROS_INCLUDE_DIR AND GSSAPI_INCLUDE_DIR))
5151
SET(AUTH_CLIENT "gssapi_authentication_client.cc")
5252
SET(UTILITY "gssapi_utility.cc")
5353
SET(CORE "kerberos_core.cc")
54-
SET(KERBEROS_LIB "${GSSAPI_LIBRARIES}")
55-
LIST(APPEND KERBEROS_LIB "${KERBEROS_LIBRARIES}")
54+
SET(KERBEROS_LIB ${GSSAPI_LIBRARIES})
55+
LIST(APPEND KERBEROS_LIB ${KERBEROS_LIBRARIES})
5656
MESSAGE(STATUS "Using Kerberos libraries: ${KERBEROS_LIB}")
5757
ELSE()
5858
MESSAGE(WARNING
@@ -78,8 +78,6 @@ MYSQL_ADD_PLUGIN(authentication_kerberos_client
7878
${CORE}
7979
${UTILITY}
8080
LINK_LIBRARIES
81-
# Uncomment to verify that all symbols are found.
82-
# ${LINK_FLAG_NO_UNDEFINED}
8381
${KERBEROS_LIB}
8482
${SSL_LIBRARIES}
8583
${LIBDL}

libmysql/authentication_kerberos/auth_kerberos_client_plugin.cc

+2-17
Original file line numberDiff line numberDiff line change
@@ -23,25 +23,10 @@
2323
#include "my_config.h"
2424

2525
/*
26-
In case of kerberos authentication we need to fill user name as kerberos user
27-
name if it is empty. We need to fill user name inside mysql->user, clients
28-
uses my_strdup directly to create new string. To use MySQL alloc functions we
29-
need to include "/mysql/service_mysql_alloc.h". Inside service_mysql_alloc.h
30-
there is #define which forces all dynamic plugins to use MySQL malloc function
31-
via services. Client side plugin cannot use any services as of now. Code
32-
check in service_mysql_alloc.h #ifdef MYSQL_DYNAMIC_PLUGIN #define my_strdup
33-
mysql_malloc_service->my_strdup #else extern char *my_strdup(PSI_memory_key
34-
key, const char *from, myf_t flags); #endif Client authentication plugin
35-
defines MYSQL_DYNAMIC_PLUGIN. And this forces to use always my_strdup via
36-
services. To use native direct my_strdup, we need to undefine
37-
MYSQL_DYNAMIC_PLUGIN. And again define MYSQL_DYNAMIC_PLUGIN once correct
38-
my_strdup are declared. service_mysql_alloc.h should provide proper fix like
39-
Instead of #ifdef MYSQL_DYNAMIC_PLUGIN
40-
#ifdef MYSQL_DYNAMIC_PLUGIN && ! MYSQL_CLIENT_PLUGIN
26+
This is a CLIENT_ONLY plugin, so allocation functions are my_malloc,
27+
my_free etc.
4128
*/
42-
#undef MYSQL_DYNAMIC_PLUGIN
4329
#include <mysql/service_mysql_alloc.h>
44-
#define MYSQL_DYNAMIC_PLUGIN
4530

4631
#include "auth_kerberos_client_plugin.h"
4732

libmysql/authentication_ldap/CMakeLists.txt

+6-3
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,12 @@ ENDIF()
5454

5555
DISABLE_MISSING_PROFILE_WARNING()
5656

57-
IF(KERBEROS_FOUND AND (NOT WIN32))
57+
IF(SASL_WITHOUT_KERBEROS)
58+
MESSAGE(WARNING "Bad custom SASL library")
59+
MESSAGE(STATUS
60+
"Building authentication_ldap_sasl_client WITHOUT Kerberos")
61+
UNSET(LDAP_KERBEROS_LIBS)
62+
ELSEIF(KERBEROS_FOUND AND (NOT WIN32))
5863
MESSAGE(STATUS
5964
"Building authentication_ldap_sasl_client with Kerberos")
6065
IF(KERBEROS_INCLUDE_DIR)
@@ -79,8 +84,6 @@ MYSQL_ADD_PLUGIN(authentication_ldap_sasl_client
7984
log_client.cc
8085
LINK_LIBRARIES
8186
${SASL_LIBRARY}
82-
# Uncomment to verify that all symbols are found.
83-
# ${LINK_FLAG_NO_UNDEFINED}
8487
${LDAP_KERBEROS_LIBS}
8588
${SSL_LIBRARIES}
8689
${LIBDL}

libmysql/authentication_ldap/auth_ldap_sasl_client.cc

+2-17
Original file line numberDiff line numberDiff line change
@@ -23,26 +23,11 @@
2323
#include "my_config.h"
2424

2525
/*
26-
In case of Kerberos authentication we need to fill user name as Kerberos user
27-
name if it is empty. We need to fill user name inside mysql->user, clients
28-
uses my_strdup directly to create new string. To use MySQL alloc functions we
29-
need to include "/mysql/service_mysql_alloc.h". Inside service_mysql_alloc.h
30-
there is #define which forces all dynamic plugins to use MySQL malloc function
31-
via services. Client side plugin cannot use any services as of now. Code
32-
check in service_mysql_alloc.h #ifdef MYSQL_DYNAMIC_PLUGIN #define my_strdup
33-
mysql_malloc_service->my_strdup #else extern char *my_strdup(PSI_memory_key
34-
key, const char *from, myf_t flags); #endif Client authentication plugin
35-
defines MYSQL_DYNAMIC_PLUGIN. And this forces to use always my_strdup via
36-
services. To use native direct my_strdup, we need to undefine
37-
MYSQL_DYNAMIC_PLUGIN. And again define MYSQL_DYNAMIC_PLUGIN once correct
38-
my_strdup are declared. service_mysql_alloc.h should provide proper fix like
39-
Instead of #ifdef MYSQL_DYNAMIC_PLUGIN
40-
#ifdef MYSQL_DYNAMIC_PLUGIN && ! MYSQL_CLIENT_PLUGIN
26+
This is a CLIENT_ONLY plugin, so allocation functions are my_malloc,
27+
my_free etc.
4128
*/
4229
#if defined(KERBEROS_LIB_CONFIGURED)
43-
#undef MYSQL_DYNAMIC_PLUGIN
4430
#include <mysql/service_mysql_alloc.h>
45-
#define MYSQL_DYNAMIC_PLUGIN
4631
#endif
4732

4833
#include <stdio.h>

0 commit comments

Comments
 (0)