-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FreeBSD/Clang++38: AlgorithmParameters/MakeParameters throws when used #562
Comments
Thanks @anonimal and @coneiric. I've seen this before on OS X while watching In Korvi's case I think it is a similar situation with two or three items contributing to it. Give me some time to sort them out so we can remediate them in turn. I don't think we have a self test for swapping in an new alphabet. I should probably get one added. |
I responded this Saturday but apparently never pressed the Surprisingly, no, I'm not seeing this issue with the latest release. Which commit was the fix? |
In 6.0 we moved to unrolling the decode table. Previously it was built on the fly but it suffered a race in multi-threaded environments. The unrolling also removed the code to build the decode table, and I believe some code of that code showed up in I think the commit of interest is/was 0dc97f1d3a801c33. |
@noloader I'm sorry, I was a very tired buffoon when I tested this at the end of last week and now realize that I was working in the wrong branch. I can confirmed that the issue is not resolved. https://build.getmonero.org/builders/kovri-all-freebsd64/builds/778/steps/test/logs/stdio Sorry about that; I've been overworked |
This may have something to do with monero-project/kovri#788
I got to look at this a little more. My FreeBSD 11 VM did not experience the crash, and neither did my new FreeBSD 10.3 VM. However I am seeing a failure in aligned allocations with This is the assert from
I checked the FreeBSD I'm trying to locate a function that really provides aligned memory. In the meantime would you try Commit c4392c40e052b1bb. |
No observable differences, and backtrace looks the same. |
I cloned your GitHub. I can't duplicate this with :
I'm testing on FreeBSD 10.3 x86_64 (unpatched, original ISO). I'm also testing on FreeBSD 11 x86_64 (fully patched). I'm using both
Is there anything I seem to be missing here? |
Which compiler and which branch/revision? |
Both the default |
Which branch/revision? We have the patch still in master. |
Yeah, I am on master. Let me ask you... when you run If it is another program, then do you have instructions for building it? |
I hope I'm answering your question: https://github.com/monero-project/kovri/blob/master/tests/unit_tests/CMakeLists.txt#L41. We simply link the unit-test executable to |
I'll go ahead and pull in a fresh image locally. If I can't reproduce there then I'm assuming there's a problem with our build machine. |
I'm running different tests than you. I'm running the According to:
I'm having trouble determining where
What I am wondering is, is the compiler making a copy of |
We use a form of static CRTP: https://github.com/monero-project/kovri/blob/master/src/core/crypto/impl/cryptopp/radix.cc#L63-L85: std::vector<std::uint8_t> Base32::Decode(
const char* in,
const std::uint64_t len)
{
// Prepare decoder
int lookup[256];
CryptoPP::Base32Decoder::InitializeDecodingLookupArray(
lookup,
reinterpret_cast<const CryptoPP::byte*>(GetAlphabet().c_str()),
GetAlphabet().size(),
true);
CryptoPP::AlgorithmParameters const params(CryptoPP::MakeParameters(
CryptoPP::Name::DecodingLookupArray(),
#if defined(__FreeBSD__) // See #788
reinterpret_cast<const int*>(lookup), false));
#else
reinterpret_cast<const int*>(lookup)));
#endif
// Decode
return Radix::Decode<CryptoPP::Base32Decoder>(params, in, len);
}
Good question. I don't have an answer now but can look further this week. |
Behind a pimpl pattern no-less 😏 monero-project/kovri#785 (the CRTP I like, the pimpl I don't). |
OK, so this looks like a small issue. From
The comments say
Instead I would use something like this. It may need a cast.
And if the compiler is doing clever things and causing an exception, then I would use this on all code paths:
|
Thanks, I will make the changes though I'm having build issues with a few of them right now. I'll need to look at the lib.
Is this for building kovri? We use a cpp-netlib submodule, so no need to install separately as long as you FreeBSD build instructions here (see to the end of doc for the recursive clone note, that should probably be moved to the beginning), also noted in Quickstart. |
Yes, I cloned your Github recursively. |
JFTR: I can reproduce this issue (#562) on a fresh FreeBSD 11.1-RELEASE image against master without any patches (old or new). I have yet to test the new patches. |
I was looking at the Kovri's failed OpenBSD build. The Build 323 failure is due to Crypto++. It was tracked under Issue 579 and this should fix it: Commit 0de445b56a5d. Confirmed fixed when building Crypto++ with |
Doing so produces failed kovri test cases where they weren't failing before. On linux, gcc 7.2.1: diff --git a/src/core/crypto/impl/cryptopp/radix.cc b/src/core/crypto/impl/cryptopp/radix.cc
index 50fdfd73..bbfba68e 100644
--- a/src/core/crypto/impl/cryptopp/radix.cc
+++ b/src/core/crypto/impl/cryptopp/radix.cc
@@ -74,11 +74,7 @@ std::vector<std::uint8_t> Base32::Decode(
CryptoPP::AlgorithmParameters const params(CryptoPP::MakeParameters(
CryptoPP::Name::DecodingLookupArray(),
-#if defined(__FreeBSD__) // See #788
- reinterpret_cast<const int*>(lookup), false));
-#else
- reinterpret_cast<const int*>(lookup)));
-#endif
+ reinterpret_cast<const CryptoPP::byte *>(lookup)));
// Decode
return Radix::Decode<CryptoPP::Base32Decoder>(params, in, len); Error:
diff --git a/src/core/crypto/impl/cryptopp/radix.cc b/src/core/crypto/impl/cryptopp/radix.cc
index 50fdfd73..bc2ed9ad 100644
--- a/src/core/crypto/impl/cryptopp/radix.cc
+++ b/src/core/crypto/impl/cryptopp/radix.cc
@@ -65,20 +65,16 @@ std::vector<std::uint8_t> Base32::Decode(
const std::uint64_t len)
{
// Prepare decoder
- int lookup[256];
+ CryptoPP::byte lookup[256];
CryptoPP::Base32Decoder::InitializeDecodingLookupArray(
- lookup,
+ reinterpret_cast<int*>(lookup),
reinterpret_cast<const CryptoPP::byte*>(GetAlphabet().c_str()),
GetAlphabet().size(),
true);
CryptoPP::AlgorithmParameters const params(CryptoPP::MakeParameters(
CryptoPP::Name::DecodingLookupArray(),
-#if defined(__FreeBSD__) // See #788
- reinterpret_cast<const int*>(lookup), false));
-#else
- reinterpret_cast<const int*>(lookup)));
-#endif
+ reinterpret_cast<const CryptoPP::byte*>(lookup)));
// Decode
return Radix::Decode<CryptoPP::Base32Decoder>(params, in, len); Error:
Then how would you advise to cast? Or re-implement without an int array? diff --git a/src/core/crypto/impl/cryptopp/radix.cc b/src/core/crypto/impl/cryptopp/radix.cc
index 50fdfd73..23f0c690 100644
--- a/src/core/crypto/impl/cryptopp/radix.cc
+++ b/src/core/crypto/impl/cryptopp/radix.cc
@@ -74,11 +74,7 @@ std::vector<std::uint8_t> Base32::Decode(
CryptoPP::AlgorithmParameters const params(CryptoPP::MakeParameters(
CryptoPP::Name::DecodingLookupArray(),
-#if defined(__FreeBSD__) // See #788
- reinterpret_cast<const int*>(lookup), false));
-#else
- reinterpret_cast<const int*>(lookup)));
-#endif
+ CryptoPP::ConstByteArrayParameter(lookup)));
// Decode
return Radix::Decode<CryptoPP::Base32Decoder>(params, in, len);
|
I went ahead and made a PR showing how I would handle it. I hope you don't mind. Sorry it took three tries. I don't have a Kovri test machine at the moment. Also see Kovri | PR 804. The |
Thank you very much @noloader. Referencing monero-project/kovri#804 (comment) so we don't get lost.
IMHO, that actually sounds very plausible. Would you treat that as a possible clang bug or something that crypto++ should redesign? |
ac06218 Fix compile error due to T = int [256] ...again. static_cast the array, switch back to 'static const' AlgorithmParameters. (Jeffrey Walton) 75f8ca1 Fix compile error due to T = int [256] (Jeffrey Walton) 32cfb4b Unroll DecodingLookupArray for Base32 and Base64 decoders This is a time/space tradeoff, but it also provides 1-time intialization while avoiding a race. It should also clear weidai11/cryptopp#562 and #788 once and for all (famous last words) (Jeffrey Walton)
Yes, I think it is a bug we should work around. I don't think we need a redesign in this area (and I would not want to be the guy to have to do it :) I think this issue is a FreeBSD-ism. Consider, you are seeing it on FreeBSD, and the other platform I witnessed it on was OS X. The OS X Darwin kernel is XNU, and XNU borrows a lot of code from FreeBSD. This is one of those low priority bugs for me. It happens infrequently, and when it surfaces we know how to contain it. The pain point for me is, reproducing it under a debugger. Right now I can't reproduce it even on OS X. Based on your observation that it happens with a 0-byte array I am thinking it is closer to the first case - aggressive optimizations. The compiler sees there is nothing to process so it starts short circuiting computation, even the ones with side effects like setting I don't recall the circumstances when I witnessed the issue, so I can't really say more about it on OS X. |
I'm closing this out for the moment. If I duplicate the issue in the future we will definitely cite this issue. |
Ok, thanks for the collaboration. |
FreeBSD freebsd 10.3-RELEASE-p11 FreeBSD 10.3-RELEASE-p11 #0: Mon Oct 24 18:49:24 UTC 2016 root@amd64-builder.daemonology.net:/usr/obj/usr/src/sys/GENERIC amd64
Tested against f1a80e6 and 591d70f
cd deps/cryptopp/ && gmake CXXFLAGS="-march=native -DCRYPTOPP_NO_CPU_FEATURE_PROBES=1" static
as noted here. Note: also reproducible with clang++39.I don't think this applies but noting in case I've overlooked another caveat.
The text was updated successfully, but these errors were encountered: