[MDEV-28162] clang compiler emits atomic library calls on x86/32bit Created: 2022-03-23 Updated: 2023-12-22 |
|
| Status: | Open |
| Project: | MariaDB Server |
| Component/s: | Performance Schema |
| Affects Version/s: | 10.2, 10.3, 10.4, 10.5, 10.6, 10.7, 10.8, 10.9 |
| Fix Version/s: | 10.4, 10.5, 10.6 |
| Type: | Bug | Priority: | Minor |
| Reporter: | KHEM RAJ | Assignee: | Nikita Malyavin |
| Resolution: | Unresolved | Votes: | 0 |
| Labels: | alignment, beginner-friendly, c++ | ||
| Attachments: |
|
| Description |
|
Clang expects 8-byte alignment for some 64-bit atomic operations As a result laterst maridb fails to build with clang on 32bit/x86 architecture because it undefined reference to `__atomic_fetch_or_8' here is a shortened testcase that can reproduce the problem with clang
compiles ok with `gcc -m32` or `clang -m32` fine but interesting thing happens with `gcc -DBUGGY -m32` or `clang -DBUGGY -m32` and you see the difference. Clang says
but gcc sails along. so I guess we need to make sure that any data being accessed atomically is aligned to 64bit as well to |
| Comments |
| Comment by KHEM RAJ [ 2022-03-23 ] | ||||||||||||||||||||||||||||
|
I have attached a patch which fixes it. | ||||||||||||||||||||||||||||
| Comment by Marko Mäkelä [ 2022-03-24 ] | ||||||||||||||||||||||||||||
|
Thank you. Starting with MariaDB Server 10.4, the my_atomic wrappers should not be used in C++ code, but the C++11 std::atomic should be used instead. I am curious about the claim that the Intel Pentium lock cmpxchg8b (infamous of the f00f bug) would only require 4-byte alignment. Is that really so? The external data bus of the Pentium is 64 bits wide. How would a misaligned lock cmpxchg8b work in a multiprocessor environment? I found a claim that the Pentium 75 would support multiprocessing with up to 2 CPUs. Also, the suggested patch is checking for the preprocessor symbol _GNUC. All clang versions that I have used (I think, between versions 4 and 14) predefine GNUC_ as 4. So, the patch would affect both gcc and clang. If I understood the patch correctly, it would explicitly declare 8-byte alignment for the 64-bit atomic types. As far as I can tell by executing the following:
the macros are unused in MariaDB Server 10.4 and later. In MariaDB Server 10.2 and 10.3 (which are still not EOL) some of those macros are invoked by InnoDB. I do not think that it is necessary to touch those old versions, unless someone can demonstrate a failure. I think that the easiest fix of this is to remove the unused macros for 64-bit atomics. | ||||||||||||||||||||||||||||
| Comment by Marko Mäkelä [ 2022-03-24 ] | ||||||||||||||||||||||||||||
|
The following definitions became unused in
The 64-bit atomic wrappers that these macros refer to are only being invoked by static member functions of class PFS_atomic, defined in the header file storage/perfschema/pfs_atomic.h. That file should be removed and the PFS_atomic replaced with something based on C++11 std::atomic, perhaps Atomic_relaxed. That should allow all matches of
to be removed. khem, can you please submit a GitHub pull request for replacing the PFS_atomic and removing all 64-bit my_atomic functions? The 32-bit atomic wrappers are being used much more, and also they could be replaced with std::atomic in C++ code (but not C). That should be done in a separate ticket. | ||||||||||||||||||||||||||||
| Comment by Marko Mäkelä [ 2022-03-24 ] | ||||||||||||||||||||||||||||
|
I removed the unused definitions. This bug must remain open until the PFS_atomic has been replaced. |