Use __builtin_bswap64 in crypto_primitives.h
Categories
(NSS :: Libraries, enhancement)
Tracking
(Not tracked)
People
(Reporter: m_kato, Assigned: m_kato)
References
Details
Attachments
(1 file)
FREEBL_HTONLL dones't use builtin function when using gcc/clang on non-x86_64.
https://treeherder.mozilla.org/#/jobs?repo=nss-try&revision=768ef2cdd422c5d95c943852311719f3a958325c
Assignee | ||
Updated•6 years ago
|
Assignee | ||
Comment 1•6 years ago
|
||
FREEBL_HTONLL dones't use builtin function when using gcc/clang on non-x86_64.
If __builtin_bswap64 is available, we should use it.
Comment 2•6 years ago
|
||
Though I've set Bug 15356734 as blocking this, I've landed these changes. They are an improvement and you aren't really responsible for the other bug.
https://hg.mozilla.org/projects/nss/rev/ca1e52ef02de3551713bd5cde0514580699248d5
Comment 3•6 years ago
|
||
This change broke GCC build (on SPARC). GCC doesn't implement __has_builtin yet (see: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66970). But it still supports __builtin_bswap64. For now I have workaround it with:
-#define __has_builtin(x) 0
+#define __has_builtin(x) 1
Any suggestion for proper fix?
Comment 4•6 years ago
|
||
Oh yeah, that's unfortunate. We should be using the builtin with GCC too. The fix I can think of is to check for GCC version explicitly:
-#elif __has_builtin(__builtin_bswap64)
+#elif __has_builtin(__builtin_bswap64) || defined(GNUC) && GNUC > 4 || (GNUC == 4 && GNUC_MINOR >= 3)
According to the gcc docs, this builtin was added in GCC 4.3.
m_kato, does that look right to you?
Assignee | ||
Comment 5•6 years ago
|
||
(In reply to Martin Thomson [:mt:] from comment #4)
Oh yeah, that's unfortunate. We should be using the builtin with GCC too. The fix I can think of is to check for GCC version explicitly:
-#elif __has_builtin(__builtin_bswap64)
+#elif __has_builtin(__builtin_bswap64) || defined(GNUC) && GNUC > 4 || (GNUC == 4 && GNUC_MINOR >= 3)According to the gcc docs, this builtin was added in GCC 4.3.
m_kato, does that look right to you?
Yes, right. GCC 4.3+ supports __builtin_bswap64
.
Comment 6•6 years ago
|
||
Comment 7•6 years ago
|
||
There is actually one more occurrence here:
https://searchfox.org/mozilla-central/source/security/nss/lib/freebl/crypto_primitives.c#25
Description
•