Open NickeZ opened 5 years ago
I was trying to add support for the arm gcc toolchain and hit the above bug because of endianess problems. Here is the final diff I applied which works:
From 275be759990bdfaf634df9e7c685430e278a5a9c Mon Sep 17 00:00:00 2001
From: Niklas Claesson <nicke.claesson@gmail.com>
Date: Wed, 19 Jun 2019 16:12:39 +0200
Subject: [PATCH] use byteorder from compiler
---
src/crypto/blake2/blake2-endian.h | 8 +++++++-
src/crypto/ghash/ghash.c | 9 ++++++++-
src/crypto/goldilocks/src/include/word.h | 7 ++++++-
3 files changed, 21 insertions(+), 3 deletions(-)
diff --git a/src/crypto/blake2/blake2-endian.h b/src/crypto/blake2/blake2-endian.h
index 10e40ab..25a3239 100644
--- a/src/crypto/blake2/blake2-endian.h
+++ b/src/crypto/blake2/blake2-endian.h
@@ -23,6 +23,12 @@
#ifndef __BLAKE2_ENDIAN_H__
#define __BLAKE2_ENDIAN_H__
+#if defined(__BYTE_ORDER__)
+#define __BYTE_ORDER __BYTE_ORDER__
+#define __LITTLE_ENDIAN __ORDER_LITTLE_ENDIAN__
+#define __BIG_ENDIAN __ORDER_BIG_ENDIAN__
+#endif
+
#if defined(__WIN32__) || defined(WIN32)
#ifndef __BIG_ENDIAN
#define __BIG_ENDIAN 4321
@@ -44,7 +50,7 @@
#if !defined( __LITTLE_ENDIAN) && defined(__DARWIN_LITTLE_ENDIAN)
#define __LITTLE_ENDIAN __DARWIN_LITTLE_ENDIAN
#endif
-#else
+#elif !defined(__BYTE_ORDER)
#include <endian.h>
#endif
diff --git a/src/crypto/ghash/ghash.c b/src/crypto/ghash/ghash.c
index e2bc5b2..d2c4a69 100644
--- a/src/crypto/ghash/ghash.c
+++ b/src/crypto/ghash/ghash.c
@@ -22,6 +22,13 @@
#include "ghash.h"
#include <string.h>
+
+#if defined(__BYTE_ORDER__)
+#define __BYTE_ORDER __BYTE_ORDER__
+#define __LITTLE_ENDIAN __ORDER_LITTLE_ENDIAN__
+#define __BIG_ENDIAN __ORDER_BIG_ENDIAN__
+#endif
+
#if defined(__WIN32__) || defined(WIN32)
#ifndef __BIG_ENDIAN
#define __BIG_ENDIAN 4321
@@ -43,7 +50,7 @@
#if !defined( __LITTLE_ENDIAN) && defined(__DARWIN_LITTLE_ENDIAN)
#define __LITTLE_ENDIAN __DARWIN_LITTLE_ENDIAN
#endif
-#else
+#elif !defined(__BYTE_ORDER)
#include <endian.h>
#endif
diff --git a/src/crypto/goldilocks/src/include/word.h b/src/crypto/goldilocks/src/include/word.h
index 9ad01e1..1a3c950 100644
--- a/src/crypto/goldilocks/src/include/word.h
+++ b/src/crypto/goldilocks/src/include/word.h
@@ -10,8 +10,13 @@
#include "arch_config.h"
+#if defined(__BYTE_ORDER__)
+#define __BYTE_ORDER __BYTE_ORDER__
+#define __LITTLE_ENDIAN __ORDER_LITTLE_ENDIAN__
+#define __BIG_ENDIAN __ORDER_BIG_ENDIAN__
+#endif
-#ifndef __APPLE__
+#if !defined(__APPLE__) && !defined(__BYTE_ORDER)
#if defined(__WIN32__) || defined(WIN32)
#ifndef __BIG_ENDIAN
#define __BIG_ENDIAN 4321
--
2.20.1
In this toolchain endian.h
is available in machine/
but I think it is more robust to use the gcc builtin variables.
I'm getting the following compiler error when compiling with gcc 7 or 8.
Configured with: