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
Incorrect SHA1 hash generated on Raspberry PI #45
Comments
Hi, RPI is embedded Linux, so it is a supported platform :) I successfully used Corrade on a BeagleBoard, some Tegra chip and other embedded devices. Can you build with tests enabled ( |
Thanks for the quick reply. I've ran all tests and the results are below. There are 2 failures:
|
Hi, thanks a lot! The However, the SHA-1 is ... weird. It produces correct value only for the last 8 characters (4 bytes) and the rest is totally wrong, even for the empty case. Not sure how to debug it here, as the closest I could get to a RPI is a 64bit Android phone and there it works. Anything special with the RPI? |
The RPI is straight out of the box and I haven't done anything special with it. I was building a Release build. I've just rebuilt a Debug build and now the Sha1 tests all pass :) There are few warnings when building the Release build (pasted below):
|
Oh well, the worst kind of bugs :/ What's the GCC version? The warnings above are harmless. |
Yeah - not a nice bug :( GCC version is: 6.3.0 20170516 - 6.3.0-18+rpi1+deb9ui |
Just out of curiosity: are you able to get Clang there and try with it, if it produces the same error? Unless you want to tackle it yourself, I'm afraid that I don't have any chance of fixing this until I get a hold of some RPI board... |
I've rebuilt with Clang and the test passes in both Release/Debug. |
Okay, that's one more indication that it's really some GCC optimization bug. Some more ideas (apologies in advance if I'm explaining something you already know):
Or, well, just use Clang, if you can. As I said, I don't have access to ARM64 RPI, so the suggestions above are all I can do :) |
Thanks for the detailed response. I was experimenting with the optimisation flags. Tests pass with I installed GCC8 following these instructions and the Sha1 tests pass on all builds. I haven't tested with GCC7 so I'm not sure when the issue was fixed. I'm happy to stick with GCC8 for now so you can close this issue unless you wish to investigate further. Thanks for your help. |
Great, thanks for trying this out. I came up with the following patch that forces -O2 on GCC < 8 on ARM for the whole code. It's still the "nuclear option", but since it's already fixed in GCC 8, it doesn't affect all users and will get obsoleted over time, so I think it's okay. diff --git a/src/Corrade/Utility/Sha1.cpp b/src/Corrade/Utility/Sha1.cpp
index b6e84ea1..f3a9b5a6 100644
--- a/src/Corrade/Utility/Sha1.cpp
+++ b/src/Corrade/Utility/Sha1.cpp
@@ -52,6 +52,18 @@ unsigned int leftrotate(unsigned int data, unsigned int shift) {
Sha1::Sha1(): _dataSize(0), _digest{InitialDigest[0], InitialDigest[1], InitialDigest[2], InitialDigest[3], InitialDigest[4]} {}
+#if defined(__GNUC__) && !defined(__clang__) && defined(CORRADE_TARGET_ARM) && __GNUC__ < 8
+#pragma GCC push_options
+#pragma GCC optimize ("O2")
+#endif
+
Sha1& Sha1::operator<<(const std::string& data) {
const std::size_t dataOffset = _buffer.empty() ? 0 : 64 - _buffer.size();
@@ -154,4 +166,9 @@ void Sha1::processChunk(const char* data) {
_digest[i] += d[i];
}
+#if defined(__GNUC__) && !defined(__clang__) && defined(CORRADE_TARGET_ARM) && __GNUC__ < 8
+#pragma GCC pop_options
+#endif
+
}}
If you got some time, could you try applying it and compiling with GCC 6 again? The best would be if you could try to reduce scope of the pragma to maybe just a single function, but I abused you as a remote debugger enough already ;) Thanks a lot! |
Sorry about the long delay - I've managed to narrow down the issue to the line below in the corrade/src/Corrade/Utility/Sha1.cpp Line 99 in 279ceb4
|
Thanks a lot for getting back to this and for narrowing it down to a single line 👍 I pushed the change as 052a560, will appear in |
Device: Raspberry PI 3 Model B+
O/S: Raspbian 9 (stretch)
I realise that the Raspberry PI isn't a supported platform but I've noticed an issue and thought I would raise it anyway. The following doesn't generate a correct SHA1 hash on a Raspberry PI.
Utility::Sha1::digest("test").hexString()
I've tested the results against
echo -n test | shasum -a 1 | awk '{print $1}'
.Thanks,
Andy
The text was updated successfully, but these errors were encountered: