From eae1bbac182f9966ec652cce954f65c9046463a0 Mon Sep 17 00:00:00 2001 From: Glenn Strauss Date: Thu, 23 Feb 2023 09:38:12 -0500 Subject: [build] _WIN32 shared dll build (autotools, cmake) There are likely better and cleaner ways to do this; patches welcome. _WIN32 symbol imports and exports MS Visual Studio (_MSC_VER) does not appear to export global data symbols even when exporting all functions. Annotating any symbols with __declspec(dllexport) in any translation unit appears to change default dll symbol implict export behavior. Currently, src/Makefile.am and CMakeLists.txt take different approaches (implib versus linking against executable which has exported symbols) x-ref: (improved solutions might possibly be constructed using these docs) https://sourceware.org/binutils/docs/ld/WIN32.html https://cmake.org/cmake/help/latest/prop_tgt/WINDOWS_EXPORT_ALL_SYMBOLS.html https://stackoverflow.com/questions/225432/export-all-symbols-when-creating-a-dll --- src/CMakeLists.txt | 15 +++++++++++++++ src/Makefile.am | 2 +- src/base.h | 1 + src/configfile-glue.c | 4 ++++ src/http-header-glue.c | 7 ++++++- src/log.c | 6 ++++++ src/log.h | 2 ++ src/plugin_config.h | 1 + src/response.h | 1 + src/server.c | 5 ++++- 10 files changed, 41 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index f591a7f8..d469d75c 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -927,12 +927,23 @@ set(SERVER_SRC configparser.c ) +if(WIN32 AND NOT BUILD_STATIC) +set(COMMON_SRC ${COMMON_SRC} mod_auth_api.c mod_vhostdb_api.c) add_executable(lighttpd ${SERVER_SRC} ${COMMON_SRC} ${BUILTIN_MODS}) +SET_TARGET_PROPERTIES(lighttpd PROPERTIES ENABLE_EXPORTS ON) +SET_TARGET_PROPERTIES(lighttpd PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS TRUE) +else() +add_executable(lighttpd ${SERVER_SRC} ${COMMON_SRC} ${BUILTIN_MODS}) +endif() set(L_INSTALL_TARGETS ${L_INSTALL_TARGETS} lighttpd) add_and_install_library(mod_accesslog mod_accesslog.c) add_and_install_library(mod_ajp13 mod_ajp13.c) +if(WIN32 AND NOT BUILD_STATIC) +add_and_install_library(mod_auth "mod_auth.c") +else() add_and_install_library(mod_auth "mod_auth.c;mod_auth_api.c") +endif() add_and_install_library(mod_authn_file "mod_authn_file.c") add_and_install_library(mod_cgi mod_cgi.c) add_and_install_library(mod_deflate mod_deflate.c) @@ -945,7 +956,11 @@ add_and_install_library(mod_sockproxy mod_sockproxy.c) add_and_install_library(mod_ssi mod_ssi.c) add_and_install_library(mod_status mod_status.c) add_and_install_library(mod_userdir mod_userdir.c) +if(WIN32 AND NOT BUILD_STATIC) +add_and_install_library(mod_vhostdb "mod_vhostdb.c") +else() add_and_install_library(mod_vhostdb "mod_vhostdb.c;mod_vhostdb_api.c") +endif() add_and_install_library(mod_webdav mod_webdav.c) add_and_install_library(mod_wstunnel mod_wstunnel.c) diff --git a/src/Makefile.am b/src/Makefile.am index 4e347fa0..5006a8b7 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -108,7 +108,7 @@ common_ldflags = -avoid-version -no-undefined lib_LTLIBRARIES += liblightcomp.la liblightcomp_la_SOURCES=$(common_src) liblightcomp_la_CFLAGS=$(AM_CFLAGS) $(LIBEV_CFLAGS) -liblightcomp_la_LDFLAGS = $(common_ldflags) +liblightcomp_la_LDFLAGS = $(common_ldflags) --export-all-symbols liblightcomp_la_LIBADD = $(PCRE_LIB) $(CRYPTO_LIB) $(FAM_LIBS) $(LIBEV_LIBS) $(ATTR_LIB) $(WS2_32_LIB) common_libadd = liblightcomp.la if !LIGHTTPD_STATIC diff --git a/src/base.h b/src/base.h index e3af4282..04876742 100644 --- a/src/base.h +++ b/src/base.h @@ -78,6 +78,7 @@ struct connection { /* log_con_jqueue is in log.c to be defined in shared object */ #define joblist_append(con) connection_jq_append(con) +__declspec_dllimport__ extern connection *log_con_jqueue; static inline void connection_jq_append(connection * const restrict con); static inline void connection_jq_append(connection * const restrict con) diff --git a/src/configfile-glue.c b/src/configfile-glue.c index 46ad820e..0c2f7065 100644 --- a/src/configfile-glue.c +++ b/src/configfile-glue.c @@ -7,12 +7,16 @@ #include "http_header.h" #include "sock_addr.h" +#undef __declspec_dllimport__ +#define __declspec_dllimport__ __declspec_dllexport__ + #include "configfile.h" #include "plugin.h" #include #include /* strtol */ +__declspec_dllexport__ array plugin_stats; /* global */ /** diff --git a/src/http-header-glue.c b/src/http-header-glue.c index 3c36e1d0..e2a19c5f 100644 --- a/src/http-header-glue.c +++ b/src/http-header-glue.c @@ -13,10 +13,14 @@ #include "http_date.h" #include "http_etag.h" #include "http_header.h" -#include "response.h" #include "sock_addr.h" #include "stat_cache.h" +#undef __declspec_dllimport__ +#define __declspec_dllimport__ __declspec_dllexport__ + +#include "response.h" + #include #include #include @@ -31,6 +35,7 @@ #define MAX_HTTP_RESPONSE_FIELD_SIZE 65535 /* http_dispatch instance here to be defined in shared object (see base.h)*/ +__declspec_dllexport__ struct http_dispatch http_dispatch[4]; diff --git a/src/log.c b/src/log.c index fe49433a..841d38a4 100644 --- a/src/log.c +++ b/src/log.c @@ -5,6 +5,9 @@ #include "first.h" +#undef __declspec_dllimport__ +#define __declspec_dllimport__ __declspec_dllexport__ + #include "log.h" #include @@ -31,9 +34,12 @@ static uint32_t tlen; static char tstr[24]; /* 20 "%F %T" incl '\0' +2 ": " */ /* log_con_jqueue instance here to be defined in shared object (see base.h) */ +__declspec_dllexport__ connection *log_con_jqueue; +__declspec_dllexport__ unix_time64_t log_epoch_secs = 0; +__declspec_dllexport__ unix_time64_t log_monotonic_secs = 0; #if !defined(HAVE_CLOCK_GETTIME) || !HAS_TIME_BITS64 diff --git a/src/log.h b/src/log.h index d67ebd94..c41b2c9c 100644 --- a/src/log.h +++ b/src/log.h @@ -5,7 +5,9 @@ #include "base_decls.h" #include "buffer.h" +__declspec_dllimport__ extern unix_time64_t log_epoch_secs; +__declspec_dllimport__ extern unix_time64_t log_monotonic_secs; #if defined(HAVE_CLOCK_GETTIME) && HAS_TIME_BITS64 diff --git a/src/plugin_config.h b/src/plugin_config.h index 4a12262d..23494350 100644 --- a/src/plugin_config.h +++ b/src/plugin_config.h @@ -204,6 +204,7 @@ int32_t config_feature_int (const server *srv, const char *feature, int32_t defa * * fastcgi.backend..disconnects = ... */ +__declspec_dllimport__ extern array plugin_stats; #define plugin_stats_get_ptr(s, len) \ diff --git a/src/response.h b/src/response.h index 438ca8fc..eba48841 100644 --- a/src/response.h +++ b/src/response.h @@ -24,6 +24,7 @@ struct http_dispatch { }; /* http_dispatch is in http-header-glue.c to be defined in shared object */ +__declspec_dllimport__ extern struct http_dispatch http_dispatch[4]; /*(index by http_version_t)*/ int http_response_parse(server *srv, request_st *r); diff --git a/src/server.c b/src/server.c index f3255ed3..ac64afa5 100644 --- a/src/server.c +++ b/src/server.c @@ -2200,7 +2200,10 @@ static void server_main_loop (server * const srv) { server_load_check(srv); } - static connection * const sentinel = + #ifndef _MSC_VER + static + #endif + connection * const sentinel = (connection *)(uintptr_t)&log_con_jqueue; connection * const joblist = log_con_jqueue; log_con_jqueue = sentinel; -- cgit v1.2.1