Bug #79701 Compilation failure for certain 32bit archs due to some missing 64bit atomics
Submitted: 18 Dec 2015 11:49 Modified: 7 Feb 2020 13:31
Reporter: Alex Potapenko Email Updates:
Status: Not a Bug Impact on me:
None 
Category:MySQL Server: Compiling Severity:S3 (Non-critical)
Version:5.7.5 -- 5.7.x OS:Linux
Assigned to: CPU Architecture:Any

[18 Dec 2015 11:49] Alex Potapenko
Description:
MySQL Server, starting from version 5.7.5, fails with "Native atomics support not found!" error on some archs (at least, mips32, armv5 and ppc32) when using gcc-5.2.0. For mips, adding '-DHAVE_GCC_ATOMIC_BUILTINS' flag manually leads to these compilation errors (mysql-server 5.7.9):

base/libclient_base.a(mysql_query_runner.cc.o): In function `Mysql::Tools::Base::Mysql_query_runner::Mysql_query_runner(st_mysql*)':
/home/alex/optware/buildroot-mipsel-ng/builds/mysql/include/atomic/gcc_builtins.h:96: undefined reference to `__sync_lock_test_and_set_8'
/home/alex/optware/buildroot-mipsel-ng/builds/mysql/include/atomic/gcc_builtins.h:96: undefined reference to `__sync_lock_test_and_set_8'
base/libclient_base.a(mysql_query_runner.cc.o): In function `Mysql::Tools::Base::Mysql_query_runner::run_query(std::string)':
/home/alex/optware/buildroot-mipsel-ng/builds/mysql/include/atomic/gcc_builtins.h:32: undefined reference to `__sync_val_compare_and_swap_8'
/home/alex/optware/buildroot-mipsel-ng/builds/mysql/include/atomic/gcc_builtins.h:32: undefined reference to `__sync_val_compare_and_swap_8'
/home/alex/optware/buildroot-mipsel-ng/builds/mysql/include/atomic/gcc_builtins.h:96: undefined reference to `__sync_lock_test_and_set_8'
/home/alex/optware/buildroot-mipsel-ng/builds/mysql/include/atomic/gcc_builtins.h:96: undefined reference to `__sync_lock_test_and_set_8'

This means that 64bit __sync_val_compare_and_swap and __sync_lock_test_and_set aren't implemented for this arch. Some other 64bit atomics can be missing too. Similarly, with armv5 and ppc32.

Due to this issue, the latest mysql-server 5.7 version I was able to port to the aforementioned archs is 5.7.4-m14. I know these archs are old, but they're still widely used (especially mips32), so I thought I should let you know about this, whether you consider it a bug or not.

How to repeat:
Try to compile mysql-server 5.7.5 or newer for one of the aforementioned archs using gcc.

Suggested fix:
If you chose to support those archs, the ideal fix, in my mind, would be to test for each gcc builtin atomic (32bit and 64bit) individually and use rwlocks instead the missing ones.
[19 Dec 2015 15:13] Alex Potapenko
From what I recently learnt, atomic 64-bit operations aren't possible for MIPS32 (O32). Does this mean that in order to support this (and other similar) arch MY_ATOMIC_MODE_RWLOCKS removed in https://github.com/mysql/mysql-server/commit/e58dae0017887faea62bc465d2eeb62f20ef18b2 has to be reimplemented? Or is there a simpler/better way? Is 64-bit operations atomicity crucial?
[7 Feb 2020 13:31] MySQL Verification Team
Hello Mr. Potapenko,

Thank you for your bug report.

However, the CPUs that you are mentioning in your report are not supported any more. 

Hence, we are closing your report.