On 5/10/19 4:49 AM, Pádraig Brady wrote:
this file comes from blake2 upstream source on github,
so you might want to broach the change there.

I'll cc: this email to cont...@blake2.net to let them know about the problem (if you're just catching up you can see the thread at <https://bugs.gnu.org/35650>).

We shouldn't simply push this problem upstream to the BLAKE2 maintainers, as the BLAKE2 code is now in coreutils and if it breaks a build then it's our responsibility to fix it. So for now I installed the attached patch into coreutils, which I hope works around the BLAKE2 code's problem.

The underlying problem is that the reference code's definition of the BLAKE2_PACKED macro assumes that the compiler is compatible with either GCC or with Microsoft's C compiler, and HP-UX aCC is neither. As far as I can see, for blake2.h on typical current platforms, there is no need to use __attribute__ ((oacked)) or the Microsoft equivalent because the data structure is already packed well enough, so the attached patch simply skips the attribute unless we know that it will work.

I also noticed that the BLAKE2 code is not portable code according to either POSIX or to the C standard, since it assumes types like uint64_t that both standards say are optional. If that's OK with the BLAKE2 maintainers then the attached patch should suffice, as it should be "good enough" for most common platforms. If you want the code to be portable, you'll need to arrange for it to pack and unpack by hand, at least on platforms that don't support a packed attribute and/or don't support types like uint64_t.

From 6e97d361b47c981966f0bfef03659c572409bcba Mon Sep 17 00:00:00 2001
From: Paul Eggert <egg...@cs.ucla.edu>
Date: Sat, 11 May 2019 13:48:16 -0700
Subject: [PATCH] b2sum: port to HP-UX C
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

* src/blake2/blake2.h (BLAKE2_PACKED):
Don’t assume __attribute__ ((packed)) works on non-Microsoft
compilers.  Instead, assume it works only if we have good
reason to assume so, and fall back on Microsoft (or not packing)
otherwise.  In practice, not packing is good enough and the
BLAKE2_PACKED macro is mostly just for documentation.
---
 src/blake2/blake2.h | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/src/blake2/blake2.h b/src/blake2/blake2.h
index d25d5fdb9..3960bdb2d 100644
--- a/src/blake2/blake2.h
+++ b/src/blake2/blake2.h
@@ -18,10 +18,18 @@
 #include <stddef.h>
 #include <stdint.h>
 
-#if defined(_MSC_VER)
-#define BLAKE2_PACKED(x) __pragma(pack(push, 1)) x __pragma(pack(pop))
-#else
-#define BLAKE2_PACKED(x) x __attribute__((packed))
+#ifdef __has_attribute
+# if __has_attribute (packed)
+#  define BLAKE2_PACKED(x) x __attribute__ ((packed))
+# endif
+#endif
+#if !defined BLAKE2_PACKED && defined _MSC_VER
+# define BLAKE2_PACKED(x) __pragma (pack (push, 1)) x __pragma (pack (pop))
+#endif
+#ifndef BLAKE2_PACKED
+/* This should be good enough on other platforms.
+   If it's not good on yours, please file a bug report.  */
+# define BLAKE2_PACKED(x) x
 #endif
 
 #if defined(__cplusplus)
-- 
2.20.1

Reply via email to