* [PATCH] Restore support for clang and other non-GCC compilers
@ 2021-09-19 7:07 Charlotte Delenk
0 siblings, 0 replies; 3+ messages in thread
From: Charlotte Delenk @ 2021-09-19 7:07 UTC (permalink / raw)
To: ell
[-- Attachment #1: Type: text/plain, Size: 3656 bytes --]
The _auto_-macro used in cert.c and tls.c uses a GCC extension that
allows for nested functions. This is not supported by other compilers,
including clang.
Compiling ell with these compilers will result error messages such as:
../ell-0.44/ell/tls.c:1895:2: error: function definition is not allowed here
_auto_(l_certchain_free) struct l_certchain *certchain = NULL;
^
../ell-0.44/ell/useful.h:71:2: note: expanded from macro '_auto_'
_AUTODESTRUCT(__COUNTER__, func)
^
../ell-0.44/ell/useful.h:68:2: note: expanded from macro '_AUTODESTRUCT'
__AUTODESTRUCT(var, func)
^
../ell-0.44/ell/useful.h:64:2: note: expanded from macro '__AUTODESTRUCT'
{ func(*(void **) ptr); } \
^
../ell-0.44/ell/tls.c:1895:2: error: use of undeclared identifier 'cleanup_0'
../ell-0.44/ell/useful.h:71:2: note: expanded from macro '_auto_'
_AUTODESTRUCT(__COUNTER__, func)
^
../ell-0.44/ell/useful.h:68:2: note: expanded from macro '_AUTODESTRUCT'
__AUTODESTRUCT(var, func)
^
../ell-0.44/ell/useful.h:65:23: note: expanded from macro '__AUTODESTRUCT'
__attribute((cleanup(cleanup_ ## var)))
^
This patch will removes the _auto_ macro and implement its functionality
manually in the two locations it is used.
It does not appear to be possible to replace this macro with a more
compatible alternative that does not involve C++.
Signed-off-by: Charlotte Delenk <darkkirb(a)darkkirb.de>
---
ell/cert.c | 6 +++++-
ell/tls.c | 6 +++++-
ell/useful.h | 11 -----------
3 files changed, 10 insertions(+), 13 deletions(-)
diff --git a/ell/cert.c b/ell/cert.c
index 141ea1c..13a89e0 100644
--- a/ell/cert.c
+++ b/ell/cert.c
@@ -446,12 +446,16 @@ static struct l_key *cert_try_link(struct l_cert *cert, struct l_keyring *ring)
return false; \
} while (0)
+static void cleanup_keyring(void * ptr) {
+ l_keyring_free(*(void **)ptr);
+}
+
LIB_EXPORT bool l_certchain_verify(struct l_certchain *chain,
struct l_queue *ca_certs,
const char **error)
{
struct l_keyring *ca_ring = NULL;
- _auto_(l_keyring_free) struct l_keyring *verify_ring = NULL;
+ __attribute__((cleanup(cleanup_keyring))) struct l_keyring *verify_ring = NULL;
struct l_cert *cert;
struct l_key *prev_key = NULL;
int verified = 0;
diff --git a/ell/tls.c b/ell/tls.c
index c246f1f..1d0e91d 100644
--- a/ell/tls.c
+++ b/ell/tls.c
@@ -1888,11 +1888,15 @@ decode_error:
"ServerHello decode error");
}
+static void cleanup_certchain(void * ptr) {
+ l_certchain_free(*(void **)ptr);
+}
+
static void tls_handle_certificate(struct l_tls *tls,
const uint8_t *buf, size_t len)
{
size_t total;
- _auto_(l_certchain_free) struct l_certchain *certchain = NULL;
+ __attribute__((cleanup(cleanup_certchain))) struct l_certchain *certchain = NULL;
struct l_cert *leaf;
size_t der_len;
const uint8_t *der;
diff --git a/ell/useful.h b/ell/useful.h
index b4783ce..cd7ec0f 100644
--- a/ell/useful.h
+++ b/ell/useful.h
@@ -59,17 +59,6 @@ static inline unsigned char bit_field(const unsigned char oct,
_x / _d; \
})
-#define __AUTODESTRUCT(var, func) \
- void cleanup_ ## var(void *ptr) \
- { func(*(void **) ptr); } \
- __attribute((cleanup(cleanup_ ## var)))
-
-#define _AUTODESTRUCT(var, func) \
- __AUTODESTRUCT(var, func)
-
-#define _auto_(func) \
- _AUTODESTRUCT(__COUNTER__, func)
-
/*
* Trick the compiler into thinking that var might be changed somehow by
* the asm
--
2.33.0
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] Restore support for clang and other non-GCC compilers
@ 2021-09-22 6:28 Charlotte Delenk
0 siblings, 0 replies; 3+ messages in thread
From: Charlotte Delenk @ 2021-09-22 6:28 UTC (permalink / raw)
To: ell
[-- Attachment #1: Type: text/plain, Size: 478 bytes --]
Hi Denis,
On 9/22/21 00:36, Denis Kenzior wrote:
> So what about doing something like this (attached). This approach is
> a bit less flexible than our current version since we have to declare
> extra destructors, but maybe clang doesn't hate it?
This patch is working fine with clang.
>
>> Signed-off-by: Charlotte Delenk <darkkirb(a)darkkirb.de>
>
> Just FYI, we do not use S-o-b tags here.
I think I added them on accident anyways.
Regards,
Charlotte
[-- Attachment #2: OpenPGP_0x3CEF5DDA915AECB0.asc --]
[-- Type: application/pgp-keys, Size: 4261 bytes --]
[-- Attachment #3: OpenPGP_signature.sig --]
[-- Type: application/pgp-signature, Size: 236 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] Restore support for clang and other non-GCC compilers
@ 2021-09-21 22:36 Denis Kenzior
0 siblings, 0 replies; 3+ messages in thread
From: Denis Kenzior @ 2021-09-21 22:36 UTC (permalink / raw)
To: ell
[-- Attachment #1: Type: text/plain, Size: 2234 bytes --]
Hi Charlotte,
On 9/19/21 2:07 AM, Charlotte Delenk wrote:
> The _auto_-macro used in cert.c and tls.c uses a GCC extension that
> allows for nested functions. This is not supported by other compilers,
> including clang.
>
> Compiling ell with these compilers will result error messages such as:
>
> ../ell-0.44/ell/tls.c:1895:2: error: function definition is not allowed here
> _auto_(l_certchain_free) struct l_certchain *certchain = NULL;
> ^
> ../ell-0.44/ell/useful.h:71:2: note: expanded from macro '_auto_'
> _AUTODESTRUCT(__COUNTER__, func)
> ^
> ../ell-0.44/ell/useful.h:68:2: note: expanded from macro '_AUTODESTRUCT'
> __AUTODESTRUCT(var, func)
> ^
> ../ell-0.44/ell/useful.h:64:2: note: expanded from macro '__AUTODESTRUCT'
> { func(*(void **) ptr); } \
> ^
> ../ell-0.44/ell/tls.c:1895:2: error: use of undeclared identifier 'cleanup_0'
> ../ell-0.44/ell/useful.h:71:2: note: expanded from macro '_auto_'
> _AUTODESTRUCT(__COUNTER__, func)
> ^
> ../ell-0.44/ell/useful.h:68:2: note: expanded from macro '_AUTODESTRUCT'
> __AUTODESTRUCT(var, func)
> ^
> ../ell-0.44/ell/useful.h:65:23: note: expanded from macro '__AUTODESTRUCT'
> __attribute((cleanup(cleanup_ ## var)))
> ^
>
> This patch will removes the _auto_ macro and implement its functionality
> manually in the two locations it is used.
The problem is that we like the _auto_ macro ;) And getting rid of it in iwd
isn't as easy.
>
> It does not appear to be possible to replace this macro with a more
> compatible alternative that does not involve C++.
>
So what about doing something like this (attached). This approach is a bit less
flexible than our current version since we have to declare extra destructors,
but maybe clang doesn't hate it?
> Signed-off-by: Charlotte Delenk <darkkirb(a)darkkirb.de>
Just FYI, we do not use S-o-b tags here.
> ---
> ell/cert.c | 6 +++++-
> ell/tls.c | 6 +++++-
> ell/useful.h | 11 -----------
> 3 files changed, 10 insertions(+), 13 deletions(-)
>
Regards,
-Denis
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-RFC-useful-Remove-nested-function-use.patch --]
[-- Type: text/x-patch, Size: 3562 bytes --]
From 8aa2b2b58e58ce8e3a951602867a37aa33097a34 Mon Sep 17 00:00:00 2001
From: Denis Kenzior <denkenz@gmail.com>
Date: Tue, 21 Sep 2021 17:32:06 -0500
Subject: [PATCH] RFC: useful: Remove nested function use
---
ell/cert.h | 2 ++
ell/cleanup.h | 27 +++++++++++++++++++++++++++
ell/key.h | 3 +++
ell/useful.h | 11 +++--------
4 files changed, 35 insertions(+), 8 deletions(-)
create mode 100644 ell/cleanup.h
diff --git a/ell/cert.h b/ell/cert.h
index f3910bb33895..8dcd8e6415aa 100644
--- a/ell/cert.h
+++ b/ell/cert.h
@@ -28,6 +28,7 @@ extern "C" {
#endif
#include <stddef.h>
+#include <ell/cleanup.h>
struct l_queue;
struct l_cert;
@@ -49,6 +50,7 @@ enum l_cert_key_type l_cert_get_pubkey_type(struct l_cert *cert);
struct l_key *l_cert_get_pubkey(struct l_cert *cert);
void l_certchain_free(struct l_certchain *chain);
+DEFINE_CLEANUP_FUNC(l_certchain_free)
struct l_cert *l_certchain_get_leaf(struct l_certchain *chain);
void l_certchain_walk_from_leaf(struct l_certchain *chain,
diff --git a/ell/cleanup.h b/ell/cleanup.h
new file mode 100644
index 000000000000..89b19816016f
--- /dev/null
+++ b/ell/cleanup.h
@@ -0,0 +1,27 @@
+/*
+ *
+ * Embedded Linux library
+ *
+ * Copyright (C) 2021 Intel Corporation. All rights reserved.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+#pragma once
+
+#define DEFINE_CLEANUP_FUNC(func) \
+ inline __attribute__((always_inline)) \
+ void func ## _cleanup(void *p) { func(*(void **) p); }
diff --git a/ell/key.h b/ell/key.h
index f1f95e11173a..ff3d9abbda4c 100644
--- a/ell/key.h
+++ b/ell/key.h
@@ -30,6 +30,7 @@ extern "C" {
#include <stddef.h>
#include <stdbool.h>
+#include <ell/cleanup.h>
#include <ell/checksum.h>
struct l_key;
@@ -108,7 +109,9 @@ bool l_keyring_restrict(struct l_keyring *keyring, enum l_keyring_restriction re
const struct l_keyring *trust);
void l_keyring_free(struct l_keyring *keyring);
+DEFINE_CLEANUP_FUNC(l_keyring_free)
void l_keyring_free_norevoke(struct l_keyring *keyring);
+DEFINE_CLEANUP_FUNC(l_keyring_free_norevoke)
bool l_keyring_link(struct l_keyring *keyring, const struct l_key *key);
diff --git a/ell/useful.h b/ell/useful.h
index b4783ce366cb..4c8b23eaa2d9 100644
--- a/ell/useful.h
+++ b/ell/useful.h
@@ -59,16 +59,11 @@ static inline unsigned char bit_field(const unsigned char oct,
_x / _d; \
})
-#define __AUTODESTRUCT(var, func) \
- void cleanup_ ## var(void *ptr) \
- { func(*(void **) ptr); } \
- __attribute((cleanup(cleanup_ ## var)))
-
-#define _AUTODESTRUCT(var, func) \
- __AUTODESTRUCT(var, func)
+#define __AUTODESTRUCT(func) \
+ __attribute((cleanup(func ## _cleanup)))
#define _auto_(func) \
- _AUTODESTRUCT(__COUNTER__, func)
+ __AUTODESTRUCT(func)
/*
* Trick the compiler into thinking that var might be changed somehow by
--
2.26.3
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2021-09-22 6:28 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-19 7:07 [PATCH] Restore support for clang and other non-GCC compilers Charlotte Delenk
2021-09-21 22:36 Denis Kenzior
2021-09-22 6:28 Charlotte Delenk
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.