libmnl: Failed to build with clang, incompatible EXPORT_SYMBOL(x) macro
PATCH 1/1 libmnl: Failed to build with clang, incompatible EXPORT_SYMBOL(x) macro
The EXPORT_SYMBOL(x) macro causes clang compile error and warning messges:
error, "note: previous definition is here"
warning, "warning: attribute declaration must precede definition
[-Wignored-attributes]"
See: [1]
This proposed patch has been prepared to fix this error which make the EXPORT_SYMBOL macro define a precede definition of an attribute declaration. This approach is both compatible with gcc and clang.
[1] http://clang.debian.net/logs/2014-09-03/libmnl_1.0.3-5_unstable_clang.log
--- doxygen.cfg.in | 8 +-- src/attr.c | 162 ++++++++++++++++++++++++++------------------------------- src/callback.c | 12 ++--- src/internal.h | 3 +- src/nlmsg.c | 76 +++++++++++++-------------- src/socket.c | 42 +++++++-------- 6 files changed, 138 insertions(+), 165 deletions(-)
doxygen.cfg.in +4 -4
@@ -72,7 +72,7 @@ RECURSIVE = YES EXCLUDE = EXCLUDE_SYMLINKS = NO EXCLUDE_PATTERNS = */.git/* .*.d -EXCLUDE_SYMBOLS = EXPORT_SYMBOL +EXCLUDE_SYMBOLS = EXAMPLE_PATH = EXAMPLE_PATTERNS = EXAMPLE_RECURSIVE = NO
@@ -144,12 +144,12 @@ PERLMOD_LATEX = NO PERLMOD_PRETTY = YES PERLMOD_MAKEVAR_PREFIX = ENABLE_PREPROCESSING = YES -MACRO_EXPANSION = NO -EXPAND_ONLY_PREDEF = NO +MACRO_EXPANSION = YES +EXPAND_ONLY_PREDEF = YES SEARCH_INCLUDES = YES INCLUDE_PATH = INCLUDE_FILE_PATTERNS = -PREDEFINED = +PREDEFINED = EXPORT_SYMBOL= EXPAND_AS_DEFINED = SKIP_FUNCTION_MACROS = YES TAGFILES =
src/attr.c +73 -89
516 lines not on this page · raw message
src/callback.c +5 -7
@@ -126,15 +126,14 @@ out:* to EPROTO. If the dump was interrupted, errno is set to EINTR and you should * request a new fresh dump again. */ -int +EXPORT_SYMBOL intmnl_cb_run2 (const void *buf,size_t numbytes,unsigned int seq, -unsigned int portid,mnl_cb_t cb_data,void *data, -mnl_cb_t *cb_ctl_array,unsigned int cb_ctl_array_len) +unsigned int portid,mnl_cb_t cb_data,void *data, +mnl_cb_t *cb_ctl_array,unsigned int cb_ctl_array_len) {return __mnl_cb_run (buf, numbytes, seq, portid, cb_data, data, cb_ctl_array, cb_ctl_array_len); } -EXPORT_SYMBOL (mnl_cb_run2);/** * mnl_cb_run - callback runqueue for netlink messages (simplified version)
@@ -155,13 +154,12 @@ EXPORT_SYMBOL(mnl_cb_run2);* * This function propagates the callback return value. */ -int +EXPORT_SYMBOL intmnl_cb_run (const void *buf,size_t numbytes,unsigned int seq, -unsigned int portid,mnl_cb_t cb_data,void *data) +unsigned int portid,mnl_cb_t cb_data,void *data) {return __mnl_cb_run (buf, numbytes, seq, portid, cb_data, data,NULL ,0 ); } -EXPORT_SYMBOL (mnl_cb_run);/** * @}
src/internal.h +1 -2
@@ -3,8 +3,7 @@#include "config.h" #ifdef HAVE_VISIBILITY_HIDDEN -# define __visible __attribute__((visibility("default"))) -# define EXPORT_SYMBOL (x) typeof(x) (x) __visible +# define EXPORT_SYMBOL __attribute__((visibility("default")))#else # define EXPORT_SYMBOL #endif
src/nlmsg.c +35 -41
282 lines not on this page · raw message
src/socket.c +20 -22
149 lines not on this page · raw message
Signature · 1 line
2.5.3
Pablo Neira Ayuso
maintainerQuoted 10 lines · Neutron Soutmun
The
EXPORT_SYMBOL(x)macro causes clang compile error and warning messges:
error, "note: previous definition is here"
warning, "warning: attribute declaration must precede definition
[-Wignored-attributes]"
See: [1]This proposed patch has been prepared to fix this error which make the
EXPORT_SYMBOLmacro define a precede definition of an attribute declaration. This approach is both compatible with gcc and clang.
We have more libraries using this approach, which resembles kernel coding. So we would need to update them all, which is a bit annoying.
Though this warning results in a real problem since symbols will not be exported.
Why is clang rejecting this?
Quoted 2 lines · Pablo Neira Ayuso
We have more libraries using this approach, which resembles kernel coding. So we would need to update them all, which is a bit annoying.
Ah, I see. I try to find many approaches to easy fix this but not success.
Refer to [1] which the reporter proposes the patch
== 8< ==
ifeq ($(shell $(CC) --version | grep -c "clang version"),1) CFLAGS += -fvisibility=default
endif
== 8< ==
I have tested, the symbols exported but I think It will override the visibility attributes, therefore, I have prepared my proposed patch.
Quoted 3 lines
Though this warning results in a real problem since symbols will not be exported.
Why is clang rejecting this?
I'm not sure. It seems that clang expands the EXPORT_SYMBOL() as a redefined of it's exported symbol function which is far different from gcc implementation.
I try to seek more info [2] and see the export.h source [3] but I have no idea for what's next -_-''
Best regards,
Neutron Soutmun
[1] https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=789480
[2] http://llvm.linuxfoundation.org/index.php/Main_Page
[3] http://lxr.free-electrons.com/source/include/linux/export.h
Quoted 8 lines · Pablo Neira Ayuso
Quoted 7 lines · Neutron Soutmun
The
EXPORT_SYMBOL(x)macro causes clang compile error and warning messges:
error, "note: previous definition is here"
warning, "warning: attribute declaration must precede definition
[-Wignored-attributes]"
See: [1]
Quoted 6 lines
Quoted 3 lines
This proposed patch has been prepared to fix this error which make the
EXPORT_SYMBOLmacro define a precede definition of an attribute declaration. This approach is both compatible with gcc and clang.We have more libraries using this approach, which resembles kernel coding. So we would need to update them all, which is a bit annoying.
If you use an export map (-Wl,--version-script=), you don't strictly need to have any of the EXPORT_SYMBOL tags in the C source.
Quoted 14 lines · Jan Engelhardt
Quoted 12 lines · Pablo Neira Ayuso
Quoted 10 lines · Neutron Soutmun
The
EXPORT_SYMBOL(x)macro causes clang compile error and warning messges:
error, "note: previous definition is here"
warning, "warning: attribute declaration must precede definition
[-Wignored-attributes]"
See: [1]This proposed patch has been prepared to fix this error which make the
EXPORT_SYMBOLmacro define a precede definition of an attribute declaration. This approach is both compatible with gcc and clang.
Quoted 5 lines
Quoted 2 lines
We have more libraries using this approach, which resembles kernel coding. So we would need to update them all, which is a bit annoying.
If you use an export map (-Wl,--version-script=), you don't strictly need to have any of the
EXPORT_SYMBOLtags in the C source.
+1
Cheers,
Neutron Soutmun
Pablo Neira Ayuso
maintainerQuoted 15 lines · Neutron Soutmun
Quoted 14 lines · Jan Engelhardt
Quoted 12 lines · Pablo Neira Ayuso
Quoted 10 lines · Neutron Soutmun
The
EXPORT_SYMBOL(x)macro causes clang compile error and warning messges:
error, "note: previous definition is here"
warning, "warning: attribute declaration must precede definition
[-Wignored-attributes]"
See: [1]This proposed patch has been prepared to fix this error which make the
EXPORT_SYMBOLmacro define a precede definition of an attribute declaration. This approach is both compatible with gcc and clang.
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
We have more libraries using this approach, which resembles kernel coding. So we would need to update them all, which is a bit annoying.
If you use an export map (-Wl,--version-script=), you don't strictly need to have any of the
EXPORT_SYMBOLtags in the C source.+1
That sounds as a smaller patch, please send it to me for the existing libraries that we have. Thanks.
Quoted 19 lines · Pablo Neira Ayuso
Quoted 18 lines · Neutron Soutmun
Quoted 17 lines · Jan Engelhardt
Quoted 14 lines · Pablo Neira Ayuso
Quoted 10 lines · Neutron Soutmun
The
EXPORT_SYMBOL(x)macro causes clang compile error and warning messges:
error, "note: previous definition is here"
warning, "warning: attribute declaration must precede definition
[-Wignored-attributes]"
See: [1]This proposed patch has been prepared to fix this error which make the
EXPORT_SYMBOLmacro define a precede definition of an attribute declaration. This approach is both compatible with gcc and clang.We have more libraries using this approach, which resembles kernel coding. So we would need to update them all, which is a bit annoying.
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
If you use an export map (-Wl,--version-script=), you don't strictly need to have any of the
EXPORT_SYMBOLtags in the C source.+1
That sounds as a smaller patch, please send it to me for the existing libraries that we have. Thanks.
I have tested with libipset, clang exports the symbols fine and no any warnings.
libmnl has implemented the export map already,
therefore, I'll prepare and test the patch that drop all EXPORT_SYMBOL tags.
Best regards,
Neutron Soutmun
I have prepared the patch that drop all EXPORT_SYMBOL tags Please find [1] - [PATCH] libmnl: Drop the EXPORT_SYMBOL() tags
Best regards,
Neutron Soutmun
[1] https://marc.info/?l=netfilter-devel&m=144369760923041&w=2
Quoted 35 lines · Neutron Soutmun
Quoted 19 lines · Pablo Neira Ayuso
Quoted 18 lines · Neutron Soutmun
Quoted 17 lines · Jan Engelhardt
Quoted 14 lines · Pablo Neira Ayuso
Quoted 10 lines · Neutron Soutmun
The
EXPORT_SYMBOL(x)macro causes clang compile error and warning messges:
error, "note: previous definition is here"
warning, "warning: attribute declaration must precede definition
[-Wignored-attributes]"
See: [1]This proposed patch has been prepared to fix this error which make the
EXPORT_SYMBOLmacro define a precede definition of an attribute declaration. This approach is both compatible with gcc and clang.We have more libraries using this approach, which resembles kernel coding. So we would need to update them all, which is a bit annoying.
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
If you use an export map (-Wl,--version-script=), you don't strictly need to have any of the
EXPORT_SYMBOLtags in the C source.+1
That sounds as a smaller patch, please send it to me for the existing libraries that we have. Thanks.
I have tested with libipset, clang exports the symbols fine and no any warnings.
libmnl has implemented the export map already,
therefore, I'll prepare and test the patch that drop allEXPORT_SYMBOLtags.Best regards,
Neutron Soutmun