Bug #86029 MySQL ODBC connector not working on tegra-ubuntu, aarch64 architecture
Submitted: 20 Apr 2017 21:05 Modified: 24 Apr 2017 14:07
Reporter: Doug Turner Email Updates:
Status: Duplicate Impact on me:
None 
Category:Connector / ODBC Severity:S1 (Critical)
Version:5.3.7 OS:Ubuntu (tegra-ubuntu, aarch64)
Assigned to: CPU Architecture:Any

[20 Apr 2017 21:05] Doug Turner
Description:
Attempted to build mysql-connector-odbc-5.3.7 from source on tegra-ubuntu on aarch64 architecture.  Build created *.so libs in lib directory but failed when linking installer (see errors below).

Then, configured odbc.ini and odbcinst.ini to point to libmyodbc5w.so as driver, and got the following error from isql (permissions were open and ldd run on all *.so files involved did not show any missing dependencies:

[01000][unixODBC][Driver Manager]Can't open lib '/home/dturner/mysql/lib/libmyodbc5w.so' : file not found
[ISQL]ERROR: Could not SQLConnect

Here are the link errors:
[ 49%] Linking CXX executable ../bin/myodbc-installer
CMakeFiles/myodbc-installer.dir/myodbc-installer.c.o: In function `SQLInstallDriverExW':
myodbc-installer.c:(.text+0x57c): undefined reference to `my_malloc'
myodbc-installer.c:(.text+0x610): undefined reference to `my_free'
myodbc-installer.c:(.text+0x62c): undefined reference to `my_free'
myodbc-installer.c:(.text+0x648): undefined reference to `my_free'
CMakeFiles/myodbc-installer.dir/myodbc-installer.c.o: In function `SQLRemoveDriverW':
myodbc-installer.c:(.text+0x6e8): undefined reference to `my_free'
CMakeFiles/myodbc-installer.dir/myodbc-installer.c.o: In function `main':
myodbc-installer.c:(.text+0x1be4): undefined reference to `get_charset_by_csname'
myodbc-installer.c:(.text+0x1c14): undefined reference to `default_charset_info'
myodbc-installer.c:(.text+0x1c18): undefined reference to `default_charset_info'
myodbc-installer.c:(.text+0x1cb0): undefined reference to `default_charset_info'
myodbc-installer.c:(.text+0x1cb4): undefined reference to `default_charset_info'
../lib/libmyodbc-util.a(stringutil.c.o): In function `sqlchar_as_sqlwchar':
stringutil.c:(.text+0x164): undefined reference to `my_malloc'
stringutil.c:(.text+0x234): undefined reference to `my_malloc'
stringutil.c:(.text+0x348): undefined reference to `my_free'
../lib/libmyodbc-util.a(stringutil.c.o): In function `sqlwchar_as_sqlchar':
stringutil.c:(.text+0x4d4): undefined reference to `my_malloc'
../lib/libmyodbc-util.a(stringutil.c.o): In function `sqlwchar_as_utf8_ext':
stringutil.c:(.text+0x704): undefined reference to `my_malloc'
../lib/libmyodbc-util.a(stringutil.c.o): In function `sqlchar_as_sqlchar':
stringutil.c:(.text+0xae8): undefined reference to `my_malloc'
../lib/libmyodbc-util.a(stringutil.c.o): In function `sqlwchardup':
stringutil.c:(.text+0x1158): undefined reference to `my_malloc'
../lib/libmyodbc-util.a(stringutil.c.o): In function `my_os_charset_to_mysql_charset':
stringutil.c:(.text+0x1584): undefined reference to `my_charset_latin1'
stringutil.c:(.text+0x1588): undefined reference to `my_charset_latin1'
stringutil.c:(.text+0x159c): undefined reference to `my_charset_latin1'
stringutil.c:(.text+0x15a0): undefined reference to `my_charset_latin1'
../lib/libmyodbc-util.a(installer.c.o): In function `driver_new':
installer.c:(.text+0x14c): undefined reference to `my_malloc'
installer.c:(.text+0x174): undefined reference to `my_malloc'
installer.c:(.text+0x1ac): undefined reference to `my_free'
installer.c:(.text+0x1c4): undefined reference to `my_malloc'
installer.c:(.text+0x200): undefined reference to `my_free'
installer.c:(.text+0x21c): undefined reference to `my_free'
installer.c:(.text+0x234): undefined reference to `my_malloc'
installer.c:(.text+0x270): undefined reference to `my_free'
installer.c:(.text+0x290): undefined reference to `my_free'
installer.c:(.text+0x2ac): undefined reference to `my_free'
../lib/libmyodbc-util.a(installer.c.o): In function `driver_delete':
installer.c:(.text+0x328): undefined reference to `my_free'
installer.c:(.text+0x348): undefined reference to `my_free'
../lib/libmyodbc-util.a(installer.c.o):installer.c:(.text+0x368): more undefined references to `my_free' follow
../lib/libmyodbc-util.a(installer.c.o): In function `ds_new':
installer.c:(.text+0xbcc): undefined reference to `my_malloc'
../lib/libmyodbc-util.a(installer.c.o): In function `ds_delete':
installer.c:(.text+0xc38): undefined reference to `my_free'
installer.c:(.text+0xc58): undefined reference to `my_free'
installer.c:(.text+0xc78): undefined reference to `my_free'
installer.c:(.text+0xc98): undefined reference to `my_free'
installer.c:(.text+0xcb8): undefined reference to `my_free'
../lib/libmyodbc-util.a(installer.c.o):installer.c:(.text+0xcd8): more undefined references to `my_free' follow
../lib/libmyodbc-util.a(installer.c.o): In function `ds_setattr_from_utf8':
installer.c:(.text+0x3d6c): undefined reference to `my_malloc'
../lib/libmyodbc-util.a(odbcinstw.c.o): In function `MySQLGetPrivateProfileStringW':
odbcinstw.c:(.text+0x1e8): undefined reference to `my_free'
odbcinstw.c:(.text+0x204): undefined reference to `my_free'
odbcinstw.c:(.text+0x220): undefined reference to `my_free'
odbcinstw.c:(.text+0x244): undefined reference to `my_free'
../lib/libmyodbc-util.a(odbcinstw.c.o): In function `SQLValidDSNW':
odbcinstw.c:(.text+0x318): undefined reference to `my_free'
../lib/libmyodbc-util.a(odbcinstw.c.o):odbcinstw.c:(.text+0x3a8): more undefined references to `my_free' follow
collect2: error: ld returned 1 exit status
installer/CMakeFiles/myodbc-installer.dir/build.make:96: recipe for target 'bin/myodbc-installer' failed
make[2]: *** [bin/myodbc-installer] Error 1
CMakeFiles/Makefile2:344: recipe for target 'installer/CMakeFiles/myodbc-installer.dir/all' failed
make[1]: *** [installer/CMakeFiles/myodbc-installer.dir/all] Error 2
Makefile:149: recipe for target 'all' failed
make: *** [all] Error 2

How to repeat:
Steps to reproduce link errors:
>cd <source directory for mysql-connector-odbc-5.3.7>
>cmake -G "Unix Makefiles" -DWITH_UNIXODBC=1
>make

Steps to reproduce isql error:
isql -v <dsn> <user> <password>

Suggested fix:
I'm not sure why the driver libraries are not working in isql, I have never seen that before on other architectures (such as RHEL 6).  The following executables and libraries have the listed architectures when "file" is run on them:
/usr/bin/isql: ELF 64-bit LSB executable, ARM aarch64, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-aarch64.so.1, for GNU/Linux 3.7.0
/usr/lib/aarch64-linux-gnu/libodbc.so.2.0.0: ELF 64-bit LSB shared object, ARM aarch64, version 1 (SYSV), dynamically linked
/home/dturner/mysql/lib/libmyodbc5w.so: ELF 64-bit LSB shared object, ARM aarch64, version 1 (SYSV), dynamically linked

For the link problems, it's possible that gcc 5.4.0 is more strict about checking for symbols in libraries that are used directly but also indirectly used.  We have seen this problem when building our applications.  The libraries containing the missing symbols may need to be linked explicitly for the executable.
[24 Apr 2017 12:07] Bogdan Degtyariov
Hi Doug,

Usually the errors like this "Can't open lib '/home/dturner/mysql/lib/libmyodbc5w.so' : file not found" indicate a missing dependent library or one of these libraries could not be loaded.

There could be a mismatch between the UnixODBC version and Connector/ODBC driver. Which version of UnixODBC are you using?

Can you send us the output from ldd?

Another thing to check would be to use a dltest tool from UnixODBC on each library listed by ldd. For instance check the UnixODBC shared lib as follows:

dltest /usr/lib/aarch64-linux-gnu/libodbc.so.2.0.0

What it does is try loading a library using dlopen() and show success or error.

Thanks.
[24 Apr 2017 13:47] Doug Turner
unixodbc (and unixodbc-dev) version is 2.3.1-4.1.

Here is the result of ldd on isql:
 ldd /usr/bin/isql
        linux-vdso.so.1 =>  (0x0000007fae3c4000)
        libodbc.so.2 => /usr/lib/aarch64-linux-gnu/libodbc.so.2 (0x0000007fae333000)
        libreadline.so.6 => /lib/aarch64-linux-gnu/libreadline.so.6 (0x0000007fae2e1000)
        libpthread.so.0 => /lib/aarch64-linux-gnu/libpthread.so.0 (0x0000007fae2b4000)
        libc.so.6 => /lib/aarch64-linux-gnu/libc.so.6 (0x0000007fae16d000)
        /lib/ld-linux-aarch64.so.1 (0x0000005575e36000)
        libltdl.so.7 => /usr/lib/aarch64-linux-gnu/libltdl.so.7 (0x0000007fae154000)
        libtinfo.so.5 => /lib/aarch64-linux-gnu/libtinfo.so.5 (0x0000007fae11d000)
        libdl.so.2 => /lib/aarch64-linux-gnu/libdl.so.2 (0x0000007fae10a000)

Here is the result of ldd on libodbc:
 ldd /usr/lib/aarch64-linux-gnu/libodbc.so.2.0.0
        linux-vdso.so.1 =>  (0x0000007fa6804000)
        libltdl.so.7 => /usr/lib/aarch64-linux-gnu/libltdl.so.7 (0x0000007fa675a000)
        libpthread.so.0 => /lib/aarch64-linux-gnu/libpthread.so.0 (0x0000007fa672e000)
        libc.so.6 => /lib/aarch64-linux-gnu/libc.so.6 (0x0000007fa65e6000)
        /lib/ld-linux-aarch64.so.1 (0x000000558c794000)
        libdl.so.2 => /lib/aarch64-linux-gnu/libdl.so.2 (0x0000007fa65d3000)

Here is the result of dltest:
~/mysql-connector-odbc-5.3.7-src/bin/dltest /usr/lib/aarch64-linux-gnu/libodbc.so.2.0.0
[/home/dturner/mysql-connector-odbc-5.3.7-src/dltest/dltest.c][170] SUCCESS: Loaded /usr/lib/aarch64-linux-gnu/libodbc.so.2.0.0

So, I don't see any obvious problems with loading libraries.  Have you ever successfully used the connector on tegra-ubuntu before?  Also, are you able to reproduce the problems with the build that I am seeing?
[24 Apr 2017 14:07] Doug Turner
I resolved the problem I was having.

I ran dltest on the myodbc library, and got the following error:
~/mysql-connector-odbc-5.3.7-src/bin/dltest  ~/mysql/lib/libmyodbc5w.so
[/home/dturner/mysql-connector-odbc-5.3.7-src/dltest/dltest.c][165] ERROR dlopen(): /home/dturner/mysql/lib/libmyodbc5w.so: undefined symbol: my_charset_latin1

When I looked this up online, I found the following bug:
https://bugs.mysql.com/bug.php?id=82202

It turns out that the connector cannot be built against the dynamic libmysqlclient library, or there will be missing symbols (this might only be true with GCC 5).  However, the default for the connector build is to use the dynamic library instead of the static one, for some reason.  

So, I changed the cmake call for the mysql-connector to the following:
cmake -G "Unix Makefiles" -DWITH_UNIXODBC=1 -DMYSQLCLIENT_STATIC_LINKING=ON

Now, the build completes and isql works with the library.

I would recommend making this cmake flag the default for the build (or at least for GCC 5 and later) so other people do not have this problem.