Bug #116396 LLVM 18 UBSan errors on server bootstrap
Submitted: 17 Oct 14:09 Modified: 7 Nov 10:18
Reporter: Laurynas Biveinis (OCA) Email Updates:
Status: Not a Bug Impact on me:
None 
Category:MySQL Server Severity:S3 (Non-critical)
Version:8.0.40, 8.4.3, 9.1.0 OS:MacOS (15.0.1)
Assigned to: CPU Architecture:ARM

[17 Oct 14:09] Laurynas Biveinis
Description:
Server built with Homebrew LLVM 18 ASan + UBSan returns several UBSan errors during bootstrap:
./mtr main.1st
...
mysqld(41761,0x1f3f53240) malloc: nano zone abandoned due to inability to reserve vm space.
/Users/laurynas/vilniusdb/mysql-8.0.40/include/mysql/components/my_service.h:85:7: runtime error: call to function mysql_registry_imp::release(my_h_service_imp*) through pointer to incorrect function type 'int (*)(my_h_service_imp *)'
registry.cc:428: note: mysql_registry_imp::release(my_h_service_imp*) defined here
...
(repeated a dozen times)
...
[ 50%] main.1st                                  [ pass ]     12
...

How to repeat:
-DCMAKE_BUILD_TYPE=Debug -DWITH_DEBUG=ON -DMYSQL_MAINTAINER_MODE=ON -DWITH_SYSTEM_LIBS=ON -DWITH_NDBCLUSTER_STORAGE_ENGINE=OFF -DDOWNLOAD_BOOST=ON -DWITH_BOOST=<path> -DFORCE_COLORED_OUTPUT=ON -DCMAKE_CXX_FLAGS=-g -DCMAKE_CXX_FLAGS_DEBUG=-g -DCMAKE_CXX_FLAGS_RELEASE=-O2 -DNDEBUG -g -DWITH_ASAN=ON -DWITH_ASAN_SCOPE=ON -DWITH_UBSAN=ON
[17 Oct 14:26] Laurynas Biveinis
Does not reproduce under LLVM 17 or XCode 15 sanitizers
[17 Oct 14:59] Laurynas Biveinis
Same on 8.4.3
[17 Oct 15:02] MySQL Verification Team
Hi Mr. Biveinis,

We do not think that we support LLVM 18 yet.

However, we shall check out with our Development team first .........
[17 Oct 15:31] Laurynas Biveinis
Same on 9.1.0
[18 Oct 9:44] MySQL Verification Team
Hi Mr. Biveinis,

According to our team in charge of the builds, right now we do not support that compiler, especially due to the problems with UBSAN, but the final decision will be made in one month.

Then, we shall proceed on this bug according to the decision that will be made in one month.
[5 Nov 8:17] Tor Didriksen
Every new compiler requires adaptions/bug-fixes to cmake and/or C++ code. New UBSAN warnings from bleeding-edge clang is not surprising at all. It will be fixed once I get hold of a platform where it can be reproduced.
[5 Nov 10:15] MySQL Verification Team
Thank you, Tor.
[7 Nov 8:16] Tor Didriksen
This looks like a bug in UBSAN to me, it reports false positives.

./bin/mysqld --help

/opt/homebrew/Cellar/llvm@18/18.1.8/bin/../include/c++/v1/__type_traits/invoke.h:344:25: runtime error: call to function icu_73::umtx_init() through pointer to incorrect function type 'void (*)()'
(mysqld:arm64+0x104af05d0): note: icu_73::umtx_init() defined here
    #0 0x107280ccc in decltype(std::declval<void (&)()>()()) std::__1::__invoke[abi:ne180100]<void (&)()>(void (&)())+0x48 (mysqld:arm64+0x102e0cccc)
    #1 0x1150c8c60 in std::__1::__call_once(unsigned long volatile&, void*, void (*)(void*))+0x9c (libc++.1.0.dylib:arm64+0x10c60)
    #2 0x10727da40 in void std::__1::call_once[abi:ne180100]<void (&)()>(std::__1::once_flag&, void (&)())+0x4c (mysqld:arm64+0x102e09a40)
    #3 0x108f644d8 in icu_73::UMutex::getMutex()+0x34 (mysqld:arm64+0x104af04d8)
    #4 0x108f64854 in icu_73::UMutex::lock()+0x24 (mysqld:arm64+0x104af0854)
    #5 0x108f255c8 in u_cleanup_73 ucln_cmn.cpp:43
    #6 0x1050b7430 in clean_up(bool) mysqld.cc:2825
    #7 0x1050a71c4 in unireg_abort(int) mysqld.cc:2602
    #8 0x1050a427c in init_common_variables() mysqld.cc:6715
    #9 0x1050a8b7c in mysqld_main(int, char**) mysqld.cc:9420
    #10 0x1827d7150 in start+0x9a8 (dyld:arm64+0xfffffffffff4d150)
    #11 0x72637ffffffffffc  (<unknown module>)

./extra/icu/icu-release-73-1/source/common/umutex.cpp contains
        std::call_once(*pInitFlag, umtx_init);
and umtx_init() is a local C function. All the code involved in doing the call to umtx_init() is generated by the compiler.

BTW: we see no such UBSAN warnings when using clang-18 and libc++ on Debian Linux.
[7 Nov 10:18] MySQL Verification Team
Thank you, Tor, for your great analysis.

Hence, this is not a bug in MySQL, but in UBSAN functionality.