-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Add cmake check for libatomic requirement when building with gcc (#980) #987
base: master
Are you sure you want to change the base?
Conversation
c544a08
to
faea2c5
Compare
…api-src#980) Signed-off-by: John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de>
faea2c5
to
c828ae4
Compare
Hi @glaubitz why such code sample is chosen? (For build check) |
Because it's a very simple code that allows us to check whether the target platform requires libatomic for atomic operations. If you have a better idea, I am open to suggestions, of course. |
To be honest, it looks like a attempt to guess missing functionality :)
Would be easier to read. Is there guarantee that compiler will not optimize this code and throw atomics away? |
I will test your code and update my PR if it works with yours. |
OK, so your suggested variant actually doesn't work:
The reason is that your code does not perform any tests with 64-bit atomics which is why the test succeeds even without |
So, the original approach seems to be a kinda guessing because this features might be implemented and we need different operation for example on 128 atomics or some RMW operation. |
So, you think this should also include a test for 128-bit atomics? Are these supported natively on most 64-bit architectures?
Doesn't seem to be the case, see: https://godbolt.org/z/7cTcxsW84 |
By that I mean we don't have specification that states which operations would be inside
There is no call in assembly how it would lead to the link error? |
Well, if you have a 32-bit processor, you usually need libatomic for 64-bit atomics. Normally, gcc would link against libatomic where needed but it doesn't because of this bug:
Well, you simply try to compile the sample code without It's a simple test that is commonly used by many open source projects in their build scripts such as mariadb. |
But which operation and types we should test? What will be minimal test? For example proposed by me test doesn't work as expected.
Compiler might optimized this test and build it successfully and later failed on library build because of different operation usage.
Could you please provide a link on such solutions? |
Well, the tests I currently suggested work for the current code. Whether it's 100% future-proof, I can't say.
I don't think it would. The code cannot be really optimized as the variables
|
It would be nice to have this merged. |
Yes, that would be nice. But I have given up hope. I don't think this will ever get merged. ¯\(ツ)/¯ |
Let's try to move with this one :) Please add comment that will state that this is a workaround because as you stated before GCC normally automatically links against libatomic on 32 bit. |
# Check whether code with full atomics can be built without libatomic | ||
# see: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81358 | ||
include(CheckCXXSourceCompiles) | ||
check_cxx_source_compiles("#include <atomic> | ||
int main() { | ||
std::atomic<uint8_t> w1; | ||
std::atomic<uint16_t> w2; | ||
std::atomic<uint32_t> w4; | ||
std::atomic<uint64_t> w8; | ||
return ++w1 + ++w2 + ++w4 + ++w8; | ||
}" TBB_BUILDS_WITHOUT_LIBATOMIC) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# Check whether code with full atomics can be built without libatomic | |
# see: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81358 | |
include(CheckCXXSourceCompiles) | |
check_cxx_source_compiles("#include <atomic> | |
int main() { | |
std::atomic<uint8_t> w1; | |
std::atomic<uint16_t> w2; | |
std::atomic<uint32_t> w4; | |
std::atomic<uint64_t> w8; | |
return ++w1 + ++w2 + ++w4 + ++w8; | |
}" TBB_BUILDS_WITHOUT_LIBATOMIC) | |
# Check whether code with full atomics can be built without libatomic | |
# Workaround for https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81358 | |
include(CheckCXXSourceCompiles) | |
check_cxx_source_compiles(" | |
#include <atomic> | |
int main() { | |
std::atomic<uint64_t> w; | |
return ++w; | |
} | |
" TBB_BUILDS_WITHOUT_LIBATOMIC) |
Can you check this code sample again?
@isaevil commented on this pull request.
In cmake/compilers/GNU.cmake:
+# Check whether code with full atomics can be built without libatomic
+# see: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81358
+include(CheckCXXSourceCompiles)
+check_cxx_source_compiles("#include <atomic>
+int main() {
+ std::atomic<uint8_t> w1;
+ std::atomic<uint16_t> w2;
+ std::atomic<uint32_t> w4;
+ std::atomic<uint64_t> w8;
+ return ++w1 + ++w2 + ++w4 + ++w8;
+}" TBB_BUILDS_WITHOUT_LIBATOMIC)
⬇️ Suggested change
-# Check whether code with full atomics can be built without libatomic
-# see: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81358
-include(CheckCXXSourceCompiles)
-check_cxx_source_compiles("#include <atomic>
-int main() {
- std::atomic<uint8_t> w1;
- std::atomic<uint16_t> w2;
- std::atomic<uint32_t> w4;
- std::atomic<uint64_t> w8;
- return ++w1 + ++w2 + ++w4 + ++w8;
-}" TBB_BUILDS_WITHOUT_LIBATOMIC)
+# Check whether code with full atomics can be built without libatomic
+# Workaround for https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81358
+include(CheckCXXSourceCompiles)
+check_cxx_source_compiles("
+ #include <atomic>
+ int main() {
+ std::atomic<uint64_t> w;
+ return ++w;
+ }
+" TBB_BUILDS_WITHOUT_LIBATOMIC)
Can you check this code sample again?Message ID: ***@***.***>
Just a second. I’m not at the computer yet.
|
Summary: RISC-V is a growing platform, and Folly and commonly used dependency. We want to make sure that any projects that relies on Folly can be ported to RISC-V. I'm verifying that everything builds and run correctly by cross-compiling it locally and passing the test suite using QEMU. Pull Request resolved: #2104 Reviewed By: yfeldblum Differential Revision: D51691588 Pulled By: Orvid fbshipit-source-id: 9c4ae6718ffbf6b55432bf6e1ffba06311c7d345
Gentoo is now applying this patch in its package. |
Signed-off-by: John Paul Adrian Glaubitz glaubitz@physik.fu-berlin.de