Skip to contentSkip to conversation

dibbler: Fix build with c++17 and newer std

PATCH New Khem Raj 1 participant 1 message Jan 16, 2023

lore
Share & tools
lore

Khem Raj

author
#0 lore raw

PATCH 1/1 dibbler: Fix build with c++17 and newer std

Clang also warns about offsetof use to emulate _Alignof register keyword is no longer available so pre-empt it

---
 ...sing-_Alignof-when-using-C11-or-newe.patch | 125 ++++++++++++++++++
 .../0002-make-Do-not-enforce-c99.patch        |  50 +++++++
 .../dibbler/dibbler_git.bb                    |   4 +-
 3 files changed, 178 insertions(+), 1 deletion(-)
 create mode 100644 meta-networking/recipes-connectivity/dibbler/dibbler/0001-Define-alignof-using-_Alignof-when-using-C11-or-newe.patch
 create mode 100644 meta-networking/recipes-connectivity/dibbler/dibbler/0002-make-Do-not-enforce-c99.patch
meta-networking/recipes-connectivity/dibbler/dibbler/0001-Define-alignof-using-_Alignof-when-using-C11-or-newe.patch new file +125 -0
new file mode 100644
index 0000000000..d48d7265d4
@@ -0,0 +1,125 @@
+From 9e9d94566d39eef3e4606f806aa418bf5534fab9 Mon Sep 17 00:00:00 2001
+From: Khem Raj <[email protected]>
+Date: Sun, 15 Jan 2023 22:04:31 -0800
+Subject: [PATCH 1/2] Define alignof using _Alignof when using C11 or newer
+
+WG14 N2350 made very clear that it is an UB having type definitions
+within "offsetof" [1]. This patch enhances the implementation of macro
+alignof to use builtin "_Alignof" to avoid undefined behavior on
+when using std=c11 or newer
+
+clang 16+ has started to flag this [2]
+
+Fixes build when using -std >= gnu11 and using clang16+
+
+Older compilers gcc < 4.9 or clang < 8 has buggy _Alignof even though it
+may support C11, exclude those compilers too
+
+[1] https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2350.htm
+[2] https://reviews.llvm.org/D133574
+
+Upstream-Status: Pending
+
+Signed-off-by: Khem Raj <[email protected]>
+---
+ Misc/md5-coreutils.c | 12 +++++++++++-
+ Misc/sha1.c          | 12 +++++++++++-
+ Misc/sha256.c        | 12 +++++++++++-
+ Misc/sha512.c        | 12 +++++++++++-
+ 4 files changed, 44 insertions(+), 4 deletions(-)
+
+diff --git a/Misc/md5-coreutils.c b/Misc/md5-coreutils.c
+index d6503e02..2ffb6050 100644
+--- a/Misc/md5-coreutils.c
++++ b/Misc/md5-coreutils.c
+@@ -154,7 +154,17 @@ md5_process_bytes (const void *buffer, size_t len, struct md5_ctx *ctx)
+   if (len >= 64)
+     {
+ #if !_STRING_ARCH_unaligned
+-# define alignof(type) offsetof (struct { char c; type x; }, x)
++/* GCC releases before GCC 4.9 had a bug in _Alignof.  See GCC bug 52023
++   <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=52023>.
++   clang versions < 8.0.0 have the same bug.  */
++# if (!defined __STDC_VERSION__ || __STDC_VERSION__ < 201112 \
++        || (defined __GNUC__ && __GNUC__ < 4 + (__GNUC_MINOR__ < 9) \
++     && !defined __clang__) \
++        || (defined __clang__ && __clang_major__ < 8))
++#    define alignof(type) offsetof (struct { char c; type x; }, x)
++# else
++#    define alignof(type) _Alignof(type)
++# endif
+ # define UNALIGNED_P(p) (((size_t) p) % alignof (uint32_t) != 0)
+       if (UNALIGNED_P (buffer))
+ 	while (len > 64)
+diff --git a/Misc/sha1.c b/Misc/sha1.c
+index 18ceb845..a170efe3 100644
+--- a/Misc/sha1.c
++++ b/Misc/sha1.c
+@@ -149,7 +149,17 @@ sha1_process_bytes (const void *buffer, size_t len, struct sha1_ctx *ctx)
+   if (len >= 64)
+     {
+ #if !_STRING_ARCH_unaligned
+-# define alignof(type) offsetof (struct { char c; type x; }, x)
++/* GCC releases before GCC 4.9 had a bug in _Alignof.  See GCC bug 52023
++   <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=52023>.
++   clang versions < 8.0.0 have the same bug.  */
++# if (!defined __STDC_VERSION__ || __STDC_VERSION__ < 201112 \
++        || (defined __GNUC__ && __GNUC__ < 4 + (__GNUC_MINOR__ < 9) \
++     && !defined __clang__) \
++        || (defined __clang__ && __clang_major__ < 8))
++#    define alignof(type) offsetof (struct { char c; type x; }, x)
++# else
++#    define alignof(type) _Alignof(type)
++# endif
+ # define UNALIGNED_P(p) (((size_t) p) % alignof (uint32_t) != 0)
+       if (UNALIGNED_P (buffer))
+ 	while (len > 64)
+diff --git a/Misc/sha256.c b/Misc/sha256.c
+index 68292326..da59e81d 100644
+--- a/Misc/sha256.c
++++ b/Misc/sha256.c
+@@ -372,7 +372,17 @@ sha256_process_bytes (const void *buffer, size_t len, struct sha256_ctx *ctx)
+   if (len >= 64)
+     {
+ #if !_STRING_ARCH_unaligned
+-# define alignof(type) offsetof (struct { char c; type x; }, x)
++/* GCC releases before GCC 4.9 had a bug in _Alignof.  See GCC bug 52023
++   <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=52023>.
++   clang versions < 8.0.0 have the same bug.  */
++# if (!defined __STDC_VERSION__ || __STDC_VERSION__ < 201112 \
++        || (defined __GNUC__ && __GNUC__ < 4 + (__GNUC_MINOR__ < 9) \
++     && !defined __clang__) \
++        || (defined __clang__ && __clang_major__ < 8))
++#    define alignof(type) offsetof (struct { char c; type x; }, x)
++# else
++#    define alignof(type) _Alignof(type)
++# endif
+ # define UNALIGNED_P(p) (((size_t) p) % alignof (uint32_t) != 0)
+       if (UNALIGNED_P (buffer))
+         while (len > 64)
+diff --git a/Misc/sha512.c b/Misc/sha512.c
+index db86c659..38e162fc 100644
+--- a/Misc/sha512.c
++++ b/Misc/sha512.c
+@@ -190,7 +190,17 @@ sha512_process_bytes (const void *buffer, size_t len, struct sha512_ctx *ctx)
+   if (len >= 128)
+     {
+ #if !_STRING_ARCH_unaligned
+-# define alignof(type) offsetof (struct { char c; type x; }, x)
++/* GCC releases before GCC 4.9 had a bug in _Alignof.  See GCC bug 52023
++   <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=52023>.
++   clang versions < 8.0.0 have the same bug.  */
++# if (!defined __STDC_VERSION__ || __STDC_VERSION__ < 201112 \
++        || (defined __GNUC__ && __GNUC__ < 4 + (__GNUC_MINOR__ < 9) \
++     && !defined __clang__) \
++        || (defined __clang__ && __clang_major__ < 8))
++#    define alignof(type) offsetof (struct { char c; type x; }, x)
++# else
++#    define alignof(type) _Alignof(type)
++# endif
+ # define UNALIGNED_P(p) (((size_t) p) % alignof (uint64_t) != 0)
+       if (UNALIGNED_P (buffer))
+ 	while (len > 128)
+-- 
+2.39.0
+
meta-networking/recipes-connectivity/dibbler/dibbler/0002-make-Do-not-enforce-c99.patch new file +50 -0

50 lines not on this page · raw message

meta-networking/recipes-connectivity/dibbler/dibbler_git.bb +3 -1
index f57767e9b8..34f8a7e3e5 100644
@@ -10,6 +10,8 @@ SRCREV = "a7c6cf58a88a510cb00841351e75030ce78d36bf"
 SRC_URI = "git://github.com/tomaszmrugalski/dibbler;branch=master;protocol=https \
            file://dibbler_fix_getSize_crash.patch \
            file://0001-port-linux-Re-order-header-includes.patch \
+           file://0001-Define-alignof-using-_Alignof-when-using-C11-or-newe.patch \
+           file://0002-make-Do-not-enforce-c99.patch \
            "
 PV = "1.0.1+1.0.2RC1+git${SRCREV}"
 
@@ -30,7 +32,7 @@ inherit autotools
 
 DEPENDS += "flex-native"
 
-CFLAGS += "-D_GNU_SOURCE"
+CPPFLAGS += "-D_GNU_SOURCE -Dregister=''"
 LDFLAGS += "-pthread"
 
 PACKAGES =+ "${PN}-requestor ${PN}-client ${PN}-relay ${PN}-server"
Signature · 1 line
2.39.0