Add plugin constructor registration for all libraries that provide plugins

Unfortunately, we can't just add the generated C file to the sources in
Makefile.am as the linker would remove that object file when it notices
that no symbol in it is ever referenced.  So we include it in the file
that contains the library initialization, which will definitely be
referenced by the executable.

This allows building an almost stand-alone static version of e.g. charon
when building with `--enable-monolithic --enable-static --disable-shared`
(without `--disable-shared` libtool will only build a version that links
the libraries dynamically).  External libraries (e.g. gmp or openssl) are
not linked statically this way, though.
This commit is contained in:
Tobias Brunner 2017-04-28 17:49:50 +02:00
parent 8699275ed6
commit 4a0b6d659d
9 changed files with 65 additions and 0 deletions

1
.gitignore vendored
View File

@ -27,6 +27,7 @@ libtool
y.tab.[ch]
lex.yy.c
*keywords.c
plugin_constructors.c
Doxyfile
apidoc/
*~

View File

@ -184,6 +184,15 @@ if USE_ME
sa/ikev2/tasks/ike_me.c sa/ikev2/tasks/ike_me.h
endif
if STATIC_PLUGIN_CONSTRUCTORS
BUILT_SOURCES = $(srcdir)/plugin_constructors.c
CLEANFILES = $(srcdir)/plugin_constructors.c
$(srcdir)/plugin_constructors.c: $(top_srcdir)/src/libstrongswan/plugins/plugin_constructors.py
$(AM_V_GEN) \
$(PYTHON) $(top_srcdir)/src/libstrongswan/plugins/plugin_constructors.py ${c_plugins} > $@
endif
# build optional plugins
########################

View File

@ -117,6 +117,13 @@ struct private_daemon_t {
refcount_t ref;
};
/**
* Register plugins if built statically
*/
#ifdef STATIC_PLUGIN_CONSTRUCTORS
#include "plugin_constructors.c"
#endif
/**
* One and only instance of the daemon.
*/

View File

@ -221,6 +221,15 @@ $(srcdir)/crypto/proposal/proposal_keywords_static.c: $(srcdir)/crypto/proposal/
$(GPERF) -N proposal_get_token_static -m 10 -C -G -c -t -D < \
$(srcdir)/crypto/proposal/proposal_keywords_static.txt > $@
if STATIC_PLUGIN_CONSTRUCTORS
BUILT_SOURCES += $(srcdir)/plugin_constructors.c
CLEANFILES = $(srcdir)/plugin_constructors.c
$(srcdir)/plugin_constructors.c: $(srcdir)/plugins/plugin_constructors.py
$(AM_V_GEN) \
$(PYTHON) $(srcdir)/plugins/plugin_constructors.py ${s_plugins} > $@
endif
if MONOLITHIC
SUBDIRS =
else

View File

@ -93,6 +93,13 @@ void library_add_namespace(char *ns)
}
}
/**
* Register plugins if built statically
*/
#ifdef STATIC_PLUGIN_CONSTRUCTORS
#include "plugin_constructors.c"
#endif
/**
* library instance
*/

View File

@ -26,6 +26,15 @@ tnc/tnccs/tnccs_manager.h tnc/tnccs/tnccs_manager.c
EXTRA_DIST = Android.mk
if STATIC_PLUGIN_CONSTRUCTORS
BUILT_SOURCES = $(srcdir)/plugin_constructors.c
CLEANFILES = $(srcdir)/plugin_constructors.c
$(srcdir)/plugin_constructors.c: $(top_srcdir)/src/libstrongswan/plugins/plugin_constructors.py
$(AM_V_GEN) \
$(PYTHON) $(top_srcdir)/src/libstrongswan/plugins/plugin_constructors.py ${t_plugins} > $@
endif
# build optional plugins
########################

View File

@ -54,6 +54,13 @@ struct private_tnc_t {
refcount_t ref;
};
/**
* Register plugins if built statically
*/
#ifdef STATIC_PLUGIN_CONSTRUCTORS
#include "plugin_constructors.c"
#endif
/**
* Single instance of tnc_t.
*/

View File

@ -33,6 +33,15 @@ else
SUBDIRS = .
endif
if STATIC_PLUGIN_CONSTRUCTORS
BUILT_SOURCES = $(srcdir)/plugin_constructors.c
CLEANFILES = $(srcdir)/plugin_constructors.c
$(srcdir)/plugin_constructors.c: $(top_srcdir)/src/libstrongswan/plugins/plugin_constructors.py
$(AM_V_GEN) \
$(PYTHON) $(top_srcdir)/src/libstrongswan/plugins/plugin_constructors.py ${p_plugins} > $@
endif
if USE_TPM
SUBDIRS += plugins/tpm
if MONOLITHIC

View File

@ -17,6 +17,13 @@
#include "tpm_tss_tss2.h"
#include "tpm_tss_trousers.h"
/**
* Register plugins if built statically
*/
#ifdef STATIC_PLUGIN_CONSTRUCTORS
#include "plugin_constructors.c"
#endif
/**
* Described in header.
*/