Description:
In the Connector/ODBC,many function symbos are global.
For example, executed command "nm" (notice uppercase *T*) :
~~~bash
$> nm libmyodbc5a.so | grep " my_malloc"
00000000000c2030 T my_malloc
00000000000bc500 t my_malloc_c
~~~
U can find out that the function my_malloc is a *global* symbol. So if my project has a function named my_malloc, the odbc SQL* function may call my_malloc with wrong localtion.
# C API
Refer to libmysqlclient, the function my_malloc is a *local* symbol.
~~~bash
> nm libmysqlclient.so | grep my_malloc
00000000000643b0 t my_malloc
000000000005e790 t my_malloc_c
~~~
How to repeat:
Just use command : nm libmyodbc5a.so | grep " my_malloc" | grep " T "
Suggested fix:
1. Modified: driver/CMakeLists.txt
+
+SET(libmyodbc_link_flags
+ " -Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/myodbc5.ver")
+
+SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${libmyodbc_link_flags}")
+
2. add file: driver/myodbc5.ver
@@ -0,0 +1,7 @@
+{
+ global: SQL*;
+ local: *;
+ };
3. compile, then execute command: nm libmyodbc5a.so | grep " T "
U will just find that the global functions are all started with "SQL".
See the whole diff:
diff --git a/driver/CMakeLists.txt b/driver/CMakeLists.txt
index 7bf2486..a5a9bbb 100644
--- a/driver/CMakeLists.txt
+++ b/driver/CMakeLists.txt
@@ -40,6 +40,12 @@ SET(DRIVER_LOCATION2 "")
SET(CONNECTOR_DRIVER_TYPE2 "")
SET(CONNECTOR_DRIVER_TYPE_SHORT2 "")
+
+SET(libmyodbc_link_flags
+ " -Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/myodbc5.ver")
+
+SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${libmyodbc_link_flags}")
+
WHILE(${DRIVER_INDEX} LESS ${DRIVERS_COUNT})
LIST(GET IS_UNICODE_DRIVER ${DRIVER_INDEX} UNICODE)
@@ -119,12 +125,16 @@ ENDIF()
ENDIF()
SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${ODBC_DRIVER_LINK_FLAGS}")
+
+
TARGET_LINK_LIBRARIES(${DRIVER_NAME}
${MYSQL_CLIENT_LIBS} ${CMAKE_THREAD_LIBS_INIT} m)
TARGET_LINK_LIBRARIES(${DRIVER_NAME} myodbc-util)
INCLUDE_DIRECTORIES(${DL_INCLUDES})
+
+
ENDIF(WIN32)
IF (MYSQL_CXX_LINKAGE)
diff --git a/driver/myodbc5.ver b/driver/myodbc5.ver
new file mode 100644
index 0000000..6fd7d59
--- /dev/null
+++ b/driver/myodbc5.ver
@@ -0,0 +1,7 @@
+{
+ global: SQL*;
+ local: *;
+ };