changeset 1106:5facd2f604b6

irccd: fix various glibc warnings and build
author David Demelier <markand@malikania.fr>
date Wed, 20 Oct 2021 14:55:20 +0200
parents 96c5f34247d2
children 02c1b78b9b58
files irccd/CMakeLists.txt irccd/dl-plugin.c lib/CMakeLists.txt
diffstat 3 files changed, 62 insertions(+), 32 deletions(-) [+]
line wrap: on
line diff
--- a/irccd/CMakeLists.txt	Wed Oct 20 14:15:23 2021 +0200
+++ b/irccd/CMakeLists.txt	Wed Oct 20 14:55:20 2021 +0200
@@ -16,6 +16,19 @@
 # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 #
 
+#
+# Overview of projects and targets here. Irccd is a host program that loads C
+# native plugins, to do so it exports the public API by its own and plugins
+# must not link to the library code itself. But for unit testing the project
+# we don't want to compile over and over the same files that *must* link
+# against the library code so we split:
+#
+# - libirccd-static (static library): contains the public API for C plugins.
+# - irccd-static (static library): contains all irccd(1) code *without* the
+#   main entry point. This code isn't publicly exposed to the plugins.
+# - irccd (executable): contains main and config parser code.
+#
+
 project(irccd)
 
 set(
@@ -69,7 +82,10 @@
 flex_target(lex ${irccd_SOURCE_DIR}/lex.l ${irccd_BINARY_DIR}/lex.c)
 add_flex_bison_dependency(lex yacc)
 
-# Intermediate library (for unit tests purposes).
+#
+# irccd-static
+# -------------------------------------------------------------------
+#
 add_library(
 	irccd-static OBJECT
 	${SOURCES}
@@ -81,10 +97,18 @@
 	PRIVATE $<BUILD_INTERFACE:${irccd_SOURCE_DIR}>
 	PUBLIC $<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}>
 )
-target_link_libraries(irccd-static libirccd-static Threads::Threads)
+target_link_libraries(
+	irccd-static
+	${CMAKE_DL_LIBS}
+	Threads::Threads
+	libirccd-static
+)
 set_target_properties(irccd-static PROPERTIES PREFIX "")
 
-# Final irccd executable.
+#
+# irccd(1)
+# -------------------------------------------------------------------
+#
 add_executable(irccd ${irccd_SOURCE_DIR}/main.c)
 target_link_libraries(irccd irccd-static)
 set_target_properties(irccd PROPERTIES ENABLE_EXPORTS On)
--- a/irccd/dl-plugin.c	Wed Oct 20 14:15:23 2021 +0200
+++ b/irccd/dl-plugin.c	Wed Oct 20 14:55:20 2021 +0200
@@ -32,44 +32,50 @@
 
 #include "dl-plugin.h"
 
+#if defined(__GNUC__)
+#       define SYM(sig, f) (__extension__ (sig)(f))
+#else
+#       define SYM(sig, f) ((sig)(f))
+#endif
+
 /* Invoke with arguments and return value. */
-#define INVOKE(pg, name, sig, ...)                                              \
-do {                                                                            \
-        struct self *self = pg->data;                                           \
-        sig fn;                                                                 \
-                                                                                \
-        if (self->handle && (fn = (sig)dlsym(self->handle, symbol(self, name))))\
-                return fn(__VA_ARGS__);                                         \
+#define INVOKE(pg, name, sig, ...)                                                      \
+do {                                                                                    \
+        struct self *self = pg->data;                                                   \
+        sig fn;                                                                         \
+                                                                                        \
+        if (self->handle && (fn = SYM(sig, dlsym(self->handle, symbol(self, name)))))   \
+                return fn(__VA_ARGS__);                                                 \
 } while (0)
 
 /* Invoke with argument and without return value. */
-#define INVOKE_NR(pg, name, sig, ...)                                           \
-do {                                                                            \
-        struct self *self = pg->data;                                           \
-        sig fn;                                                                 \
-                                                                                \
-        if (self->handle && (fn = (sig)dlsym(self->handle, symbol(self, name))))\
-                fn(__VA_ARGS__);                                                \
+#define INVOKE_NR(pg, name, sig, ...)                                                   \
+do {                                                                                    \
+        struct self *self = pg->data;                                                   \
+        sig fn;                                                                         \
+                                                                                        \
+        if (self->handle && (fn = SYM(sig, dlsym(self->handle, symbol(self, name)))))   \
+                fn(__VA_ARGS__);                                                        \
 } while (0)
 
 /* Invoke without arguments and with return value. */
-#define INVOKE_NA(pg, name, sig)                                                \
-do {                                                                            \
-        struct self *self = pg->data;                                           \
-        sig fn;                                                                 \
-                                                                                \
-        if (self->handle && (fn = (sig)dlsym(self->handle, symbol(self, name))))\
-                return fn();                                                    \
+#define INVOKE_NA(pg, name, sig)                                                        \
+do {                                                                                    \
+        struct self *self = pg->data;                                                   \
+        sig fn;                                                                         \
+                                                                                        \
+        if (self->handle && (fn = SYM(sig, dlsym(self->handle, symbol(self, name)))))   \
+                return fn();                                                            \
 } while (0)
 
 /* Invoke without arguments and without return value. */
-#define INVOKE_NA_NR(pg, name, sig)                                             \
-do {                                                                            \
-        struct self *self = pg->data;                                           \
-        sig fn;                                                                 \
-                                                                                \
-        if (self->handle && (fn = (sig)dlsym(self->handle, symbol(self, name))))\
-                fn();                                                           \
+#define INVOKE_NA_NR(pg, name, sig)                                                     \
+do {                                                                                    \
+        struct self *self = pg->data;                                                   \
+        sig fn;                                                                         \
+                                                                                        \
+        if (self->handle && (fn = SYM(sig, dlsym(self->handle, symbol(self, name)))))   \
+                fn();                                                                   \
 } while (0)
 
 struct self {
--- a/lib/CMakeLists.txt	Wed Oct 20 14:15:23 2021 +0200
+++ b/lib/CMakeLists.txt	Wed Oct 20 14:55:20 2021 +0200
@@ -59,7 +59,7 @@
 
 add_library(libirccd-static STATIC ${LIBBSD_SOURCES} ${SOURCES})
 target_link_libraries(libirccd-static PUBLIC libirccd-utlist)
-target_compile_definitions(libirccd-static PUBLIC _XOPEN_SOURCE=0700)
+target_compile_definitions(libirccd-static PUBLIC _XOPEN_SOURCE=700)
 target_include_directories(
 	libirccd-static
 	PUBLIC