Uploaded image for project: 'MariaDB Server'
  1. MariaDB Server
  2. MDEV-26541

Undefined symbol: _ZTI12ha_partition when attempting to use ha_spider.so in UBSAN builds

Details

    Description

      This bug blocks ASAN/UBSAN testing of the Spider Engine.

      Steps to reproduce:
      Build server as ASAN/UBSAN build. Attempt to load Spider engine.

      10.7.0 1bc82aaf0a7746c0921a94034aff2d51f0d75cd0 (Debug)

      10.7.0-dbg>INSTALL PLUGIN spider SONAME 'ha_spider.so';
      ERROR 1126 (HY000): Can't open shared library '/test/UBASAN_MD060921-mariadb-10.7.0-linux-x86_64-dbg/lib/plugin/ha_spider.so' (errno: 2, undefined symbol: _ZTI12ha_partition)
      

      The file is there:

      $ ls -lh /test/UBASAN_MD060921-mariadb-10.7.0-linux-x86_64-dbg/lib/plugin/ha_spider.so
      -rw-r--r-- 1 roel roel 39M Sep  6 06:00 /test/UBASAN_MD060921-mariadb-10.7.0-linux-x86_64-dbg/lib/plugin/ha_spider.so
      

      $ cat BUILD_CMD_CMAKE 
      cmake . -DWITH_SSL=bundled -DCMAKE_BUILD_TYPE=Debug -DBUILD_CONFIG=mysql_release -DWITH_TOKUDB=0 -DWITH_JEMALLOC=no -DFEATURE_SET=community -DDEBUG_EXTNAME=OFF -DWITH_EMBEDDED_SERVER=0 -DENABLE_DOWNLOADS=1 -DDOWNLOAD_BOOST=1 -DWITH_BOOST=/tmp/boost_805116 -DENABLED_LOCAL_INFILE=1 -DENABLE_DTRACE=0 -DWITH_PERFSCHEMA_STORAGE_ENGINE=1 -DWITH_ZLIB=bundled -DWITH_ROCKSDB=1 -DWITH_PAM=ON -DFORCE_INSOURCE_BUILD=1 -DWITH_ASAN=ON -DWITH_ASAN_SCOPE=ON -DWITH_UBSAN=ON -DWSREP_LIB_WITH_ASAN=ON -DCMAKE_CXX_FLAGS=-static-libasan -DMYSQL_MAINTAINER_MODE=OFF
      

      Present in 10.5 and 10.7. Likely same in older versions also.

      Attachments

        Issue Links

          Activity

            ycp Yuchen Pei added a comment - - edited

            It seems this issue cannot be directly analysed by a debugger, as the traces are identical with or without ubsan.

            The server binary is built with rtti, which can be verified using the method mentioned in <https://stackoverflow.com/questions/22150806/how-can-i-check-if-a-library-was-compiled-with-fno-rtti>.

            Without -fno-rtti for spider, we get

            $ nm /home/ycp/source/mariadb-server/mdev-26541/build/mysql-test/var/plugins/ha_spider.so
            ...
            0000000000b4a488 V _ZTI10Item_const
                             U _ZTI10Item_field
                             U _ZTI10Item_ident
                             U _ZTI11Item_string
                             U _ZTI11Query_arena
                             U _ZTI12ha_partition
            ...
            $ nm -C /home/ycp/source/mariadb-server/mdev-26541/build/mysql-test/var/plugins/ha_spider.so
            ...
            0000000000b4a488 V typeinfo for Item_const
                             U typeinfo for Item_field
                             U typeinfo for Item_ident
                             U typeinfo for Item_string
                             U typeinfo for Query_arena
                             U typeinfo for ha_partition
            ...
            $ nm -C /home/ycp/source/mariadb-server/mdev-26541/build/sql/mysqld
            ...
            0000000007beb3d8 d typeinfo for ha_partition
            ...
            $ nm sql/mysqld | grep 0000000007beb3d8
            0000000007beb3d8 d _ZTI12ha_partition
            

            With -fno-rtti for spider, as with the stackoverflow post, there's no typeinfo for ha_partition, or anything for ha_partition:

            $ nm /home/ycp/source/mariadb-server/mdev-26541/build/mysql-test/var/plugins/ha_spider.so | grep ha_partition
            0000000000782488 W _ZN12ha_partition18get_child_handlersEv
             
            $ nm -C /home/ycp/source/mariadb-server/mdev-26541/build/mysql-test/var/plugins/ha_spider.so | grep ha_partition
            0000000000782488 W ha_partition::get_child_handlers()
            

            Furthermore, with the -fno-rtti and ubsan build for spider, we get test failures which
            disappears with the --nowarnings mtr flag:

            $ ./mysql-test/mtr spider.basic_sql
            ...
            worker[1] Using MTR_BUILD_THREAD 300, with reserved ports 16000..16019
            spider.basic_sql                         [ fail ]  Found warnings/errors in server log file!
                    Test ended at 2022-12-21 18:56:23
            line
            /home/ycp/source/mariadb-server/mdev-26541/src/sql/handler.cc:320:17: runtime error: member call on address 0x7f54e8016ce8 which does not point to an object of type 'handler'
            /home/ycp/source/mariadb-server/mdev-26541/src/sql/handler.h:3168:36: runtime error: member call on address 0x7f54e8016ce8 which does not point to an object of type 'handler'
            /home/ycp/source/mariadb-server/mdev-26541/src/sql/handler.h:3168:5: runtime error: member access within address 0x7f54e8016ce8 which does not point to an object of type 'handler'
            /home/ycp/source/mariadb-server/mdev-26541/src/sql/sql_table.cc:3463:39: runtime error: member call on address 0x7f54e8016ce8 which does not point to an object of type 'handler'
            /home/ycp/source/mariadb-server/mdev-26541/src/sql/handler.h:3922:12: runtime error: member call on address 0x7f54e8016ce8 which does not point to an object of type 'handler'
            /home/ycp/source/mariadb-server/mdev-26541/src/sql/sql_table.cc:3497:61: runtime error: member call on address 0x7f54e8016ce8 which does not point to an object of type 'handler'
            ...
            

            These seem to be errors produced by ubsan, cf <https://jira.mariadb.org/browse/MDEV-20923>. If we use Nayuta's patch, we will need to fix these errors. OTOH I wonder whether the tests will pass if we can find a fix for this issue without disabling rtti.

            ycp Yuchen Pei added a comment - - edited It seems this issue cannot be directly analysed by a debugger, as the traces are identical with or without ubsan. The server binary is built with rtti, which can be verified using the method mentioned in < https://stackoverflow.com/questions/22150806/how-can-i-check-if-a-library-was-compiled-with-fno-rtti >. Without -fno-rtti for spider, we get $ nm /home/ycp/source/mariadb-server/mdev-26541/build/mysql-test/var/plugins/ha_spider.so ... 0000000000b4a488 V _ZTI10Item_const U _ZTI10Item_field U _ZTI10Item_ident U _ZTI11Item_string U _ZTI11Query_arena U _ZTI12ha_partition ... $ nm -C /home/ycp/source/mariadb-server/mdev-26541/build/mysql-test/var/plugins/ha_spider.so ... 0000000000b4a488 V typeinfo for Item_const U typeinfo for Item_field U typeinfo for Item_ident U typeinfo for Item_string U typeinfo for Query_arena U typeinfo for ha_partition ... $ nm -C /home/ycp/source/mariadb-server/mdev-26541/build/sql/mysqld ... 0000000007beb3d8 d typeinfo for ha_partition ... $ nm sql/mysqld | grep 0000000007beb3d8 0000000007beb3d8 d _ZTI12ha_partition With -fno-rtti for spider, as with the stackoverflow post, there's no typeinfo for ha_partition, or anything for ha_partition: $ nm /home/ycp/source/mariadb-server/mdev-26541/build/mysql-test/var/plugins/ha_spider.so | grep ha_partition 0000000000782488 W _ZN12ha_partition18get_child_handlersEv   $ nm -C /home/ycp/source/mariadb-server/mdev-26541/build/mysql-test/var/plugins/ha_spider.so | grep ha_partition 0000000000782488 W ha_partition::get_child_handlers() Furthermore, with the -fno-rtti and ubsan build for spider, we get test failures which disappears with the --nowarnings mtr flag: $ ./mysql-test/mtr spider.basic_sql ... worker[1] Using MTR_BUILD_THREAD 300, with reserved ports 16000..16019 spider.basic_sql [ fail ] Found warnings/errors in server log file! Test ended at 2022-12-21 18:56:23 line /home/ycp/source/mariadb-server/mdev-26541/src/sql/handler.cc:320:17: runtime error: member call on address 0x7f54e8016ce8 which does not point to an object of type 'handler' /home/ycp/source/mariadb-server/mdev-26541/src/sql/handler.h:3168:36: runtime error: member call on address 0x7f54e8016ce8 which does not point to an object of type 'handler' /home/ycp/source/mariadb-server/mdev-26541/src/sql/handler.h:3168:5: runtime error: member access within address 0x7f54e8016ce8 which does not point to an object of type 'handler' /home/ycp/source/mariadb-server/mdev-26541/src/sql/sql_table.cc:3463:39: runtime error: member call on address 0x7f54e8016ce8 which does not point to an object of type 'handler' /home/ycp/source/mariadb-server/mdev-26541/src/sql/handler.h:3922:12: runtime error: member call on address 0x7f54e8016ce8 which does not point to an object of type 'handler' /home/ycp/source/mariadb-server/mdev-26541/src/sql/sql_table.cc:3497:61: runtime error: member call on address 0x7f54e8016ce8 which does not point to an object of type 'handler' ... These seem to be errors produced by ubsan, cf < https://jira.mariadb.org/browse/MDEV-20923 >. If we use Nayuta's patch, we will need to fix these errors. OTOH I wonder whether the tests will pass if we can find a fix for this issue without disabling rtti.
            marko Marko Mäkelä added a comment - - edited

            The following change allows the _ZTI12ha_partition to be exported as a global symbol in mariadbd:

            diff --git a/cmake/libutils.cmake b/cmake/libutils.cmake
            index 74853c36a74..a6d2628fffc 100644
            --- a/cmake/libutils.cmake
            +++ b/cmake/libutils.cmake
            @@ -344,11 +344,6 @@ SET(VISIBILITY_HIDDEN_FLAG)
             
             IF(CMAKE_C_COMPILER_ID MATCHES "SunPro")
               SET(VISIBILITY_HIDDEN_FLAG "-xldscope=hidden")
            -ELSEIF(UNIX)
            -  CHECK_C_COMPILER_FLAG("-fvisibility=hidden" HAVE_VISIBILITY_HIDDEN)
            -  IF(HAVE_VISIBILITY_HIDDEN)
            -    SET(VISIBILITY_HIDDEN_FLAG "-fvisibility=hidden")
            -  ENDIF()
             ENDIF()
             
             # We try to hide the symbols in bundled libraries to avoid name clashes with
            

            The proper way to fix this would be to apply something like the

              IF(VISIBILITY_HIDDEN_FLAG AND TARGET wsrep)
            

            tweak in sql/CMakeLists.txt to other files.

            With that sorted out, several Spider tests would fail due to one error:

            diff --git a/storage/spider/spd_conn.cc b/storage/spider/spd_conn.cc
            index 80d2489185b..a0b36dbe0b6 100644
            --- a/storage/spider/spd_conn.cc
            +++ b/storage/spider/spd_conn.cc
            @@ -648,8 +648,8 @@ SPIDER_CONN *spider_create_conn(
                   share->tgt_usernames_lengths[link_idx]);
                 conn->tgt_password_length = share->tgt_passwords_lengths[link_idx];
                 conn->tgt_password = tmp_password;
            -    memcpy(conn->tgt_password, share->tgt_passwords[link_idx],
            -      share->tgt_passwords_lengths[link_idx]);
            +    if (size_t s= share->tgt_passwords_lengths[link_idx])
            +      memcpy(conn->tgt_password, share->tgt_passwords[link_idx], s);
                 conn->tgt_socket_length = share->tgt_sockets_lengths[link_idx];
                 conn->tgt_socket = tmp_socket;
                 memcpy(conn->tgt_socket, share->tgt_sockets[link_idx],
            

            A number of tests still fail with that patch due to other nonnull violations in storage/spider/spd_trx.cc:

            10.6 56c9b0bca0576985c31f20b46dcb060a01e81a2b with the above patch

            Completed: Failed 3/40 tests, 92.50% were successful.
             
            Failing test(s): spider.ha_part spider.auto_increment spider.ha
            

            marko Marko Mäkelä added a comment - - edited The following change allows the _ZTI12ha_partition to be exported as a global symbol in mariadbd : diff --git a/cmake/libutils.cmake b/cmake/libutils.cmake index 74853c36a74..a6d2628fffc 100644 --- a/cmake/libutils.cmake +++ b/cmake/libutils.cmake @@ -344,11 +344,6 @@ SET(VISIBILITY_HIDDEN_FLAG) IF(CMAKE_C_COMPILER_ID MATCHES "SunPro") SET(VISIBILITY_HIDDEN_FLAG "-xldscope=hidden") -ELSEIF(UNIX) - CHECK_C_COMPILER_FLAG("-fvisibility=hidden" HAVE_VISIBILITY_HIDDEN) - IF(HAVE_VISIBILITY_HIDDEN) - SET(VISIBILITY_HIDDEN_FLAG "-fvisibility=hidden") - ENDIF() ENDIF() # We try to hide the symbols in bundled libraries to avoid name clashes with The proper way to fix this would be to apply something like the IF(VISIBILITY_HIDDEN_FLAG AND TARGET wsrep) tweak in sql/CMakeLists.txt to other files. With that sorted out, several Spider tests would fail due to one error: diff --git a/storage/spider/spd_conn.cc b/storage/spider/spd_conn.cc index 80d2489185b..a0b36dbe0b6 100644 --- a/storage/spider/spd_conn.cc +++ b/storage/spider/spd_conn.cc @@ -648,8 +648,8 @@ SPIDER_CONN *spider_create_conn( share->tgt_usernames_lengths[link_idx]); conn->tgt_password_length = share->tgt_passwords_lengths[link_idx]; conn->tgt_password = tmp_password; - memcpy(conn->tgt_password, share->tgt_passwords[link_idx], - share->tgt_passwords_lengths[link_idx]); + if (size_t s= share->tgt_passwords_lengths[link_idx]) + memcpy(conn->tgt_password, share->tgt_passwords[link_idx], s); conn->tgt_socket_length = share->tgt_sockets_lengths[link_idx]; conn->tgt_socket = tmp_socket; memcpy(conn->tgt_socket, share->tgt_sockets[link_idx], A number of tests still fail with that patch due to other nonnull violations in storage/spider/spd_trx.cc : 10.6 56c9b0bca0576985c31f20b46dcb060a01e81a2b with the above patch Completed: Failed 3/40 tests, 92.50% were successful.   Failing test(s): spider.ha_part spider.auto_increment spider.ha
            ycp Yuchen Pei added a comment - - edited

            Thanks marko very much for unblocking this ticket.

            holyfoot: I've created a patch at https://github.com/MariaDB/server/commit/b4d5a4f46c2, PTAL thanks.

            ycp Yuchen Pei added a comment - - edited Thanks marko very much for unblocking this ticket. holyfoot : I've created a patch at https://github.com/MariaDB/server/commit/b4d5a4f46c2 , PTAL thanks.
            ycp Yuchen Pei added a comment -
            ycp Yuchen Pei added a comment - marko holyfoot updated patch incorporating marko 's comment at https://github.com/MariaDB/server/commit/af2de138303

            Ok to push.
            Minor comment on Slack.

            holyfoot Alexey Botchkov added a comment - Ok to push. Minor comment on Slack.

            People

              ycp Yuchen Pei
              Roel Roel Van de Paar
              Votes:
              0 Vote for this issue
              Watchers:
              8 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Git Integration

                  Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.