Skip to content

Commit 4a0b6d6

Browse files
committed
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.
1 parent 8699275 commit 4a0b6d6

File tree

9 files changed

+65
-0
lines changed

9 files changed

+65
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ libtool
2727
y.tab.[ch]
2828
lex.yy.c
2929
*keywords.c
30+
plugin_constructors.c
3031
Doxyfile
3132
apidoc/
3233
*~

src/libcharon/Makefile.am

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,15 @@ if USE_ME
184184
sa/ikev2/tasks/ike_me.c sa/ikev2/tasks/ike_me.h
185185
endif
186186

187+
if STATIC_PLUGIN_CONSTRUCTORS
188+
BUILT_SOURCES = $(srcdir)/plugin_constructors.c
189+
CLEANFILES = $(srcdir)/plugin_constructors.c
190+
191+
$(srcdir)/plugin_constructors.c: $(top_srcdir)/src/libstrongswan/plugins/plugin_constructors.py
192+
$(AM_V_GEN) \
193+
$(PYTHON) $(top_srcdir)/src/libstrongswan/plugins/plugin_constructors.py ${c_plugins} > $@
194+
endif
195+
187196
# build optional plugins
188197
########################
189198

src/libcharon/daemon.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,13 @@ struct private_daemon_t {
117117
refcount_t ref;
118118
};
119119

120+
/**
121+
* Register plugins if built statically
122+
*/
123+
#ifdef STATIC_PLUGIN_CONSTRUCTORS
124+
#include "plugin_constructors.c"
125+
#endif
126+
120127
/**
121128
* One and only instance of the daemon.
122129
*/

src/libstrongswan/Makefile.am

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,15 @@ $(srcdir)/crypto/proposal/proposal_keywords_static.c: $(srcdir)/crypto/proposal/
221221
$(GPERF) -N proposal_get_token_static -m 10 -C -G -c -t -D < \
222222
$(srcdir)/crypto/proposal/proposal_keywords_static.txt > $@
223223

224+
if STATIC_PLUGIN_CONSTRUCTORS
225+
BUILT_SOURCES += $(srcdir)/plugin_constructors.c
226+
CLEANFILES = $(srcdir)/plugin_constructors.c
227+
228+
$(srcdir)/plugin_constructors.c: $(srcdir)/plugins/plugin_constructors.py
229+
$(AM_V_GEN) \
230+
$(PYTHON) $(srcdir)/plugins/plugin_constructors.py ${s_plugins} > $@
231+
endif
232+
224233
if MONOLITHIC
225234
SUBDIRS =
226235
else

src/libstrongswan/library.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,13 @@ void library_add_namespace(char *ns)
9393
}
9494
}
9595

96+
/**
97+
* Register plugins if built statically
98+
*/
99+
#ifdef STATIC_PLUGIN_CONSTRUCTORS
100+
#include "plugin_constructors.c"
101+
#endif
102+
96103
/**
97104
* library instance
98105
*/

src/libtnccs/Makefile.am

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,15 @@ tnc/tnccs/tnccs_manager.h tnc/tnccs/tnccs_manager.c
2626

2727
EXTRA_DIST = Android.mk
2828

29+
if STATIC_PLUGIN_CONSTRUCTORS
30+
BUILT_SOURCES = $(srcdir)/plugin_constructors.c
31+
CLEANFILES = $(srcdir)/plugin_constructors.c
32+
33+
$(srcdir)/plugin_constructors.c: $(top_srcdir)/src/libstrongswan/plugins/plugin_constructors.py
34+
$(AM_V_GEN) \
35+
$(PYTHON) $(top_srcdir)/src/libstrongswan/plugins/plugin_constructors.py ${t_plugins} > $@
36+
endif
37+
2938
# build optional plugins
3039
########################
3140

src/libtnccs/tnc/tnc.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,13 @@ struct private_tnc_t {
5454
refcount_t ref;
5555
};
5656

57+
/**
58+
* Register plugins if built statically
59+
*/
60+
#ifdef STATIC_PLUGIN_CONSTRUCTORS
61+
#include "plugin_constructors.c"
62+
#endif
63+
5764
/**
5865
* Single instance of tnc_t.
5966
*/

src/libtpmtss/Makefile.am

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,15 @@ else
3333
SUBDIRS = .
3434
endif
3535

36+
if STATIC_PLUGIN_CONSTRUCTORS
37+
BUILT_SOURCES = $(srcdir)/plugin_constructors.c
38+
CLEANFILES = $(srcdir)/plugin_constructors.c
39+
40+
$(srcdir)/plugin_constructors.c: $(top_srcdir)/src/libstrongswan/plugins/plugin_constructors.py
41+
$(AM_V_GEN) \
42+
$(PYTHON) $(top_srcdir)/src/libstrongswan/plugins/plugin_constructors.py ${p_plugins} > $@
43+
endif
44+
3645
if USE_TPM
3746
SUBDIRS += plugins/tpm
3847
if MONOLITHIC

src/libtpmtss/tpm_tss.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@
1717
#include "tpm_tss_tss2.h"
1818
#include "tpm_tss_trousers.h"
1919

20+
/**
21+
* Register plugins if built statically
22+
*/
23+
#ifdef STATIC_PLUGIN_CONSTRUCTORS
24+
#include "plugin_constructors.c"
25+
#endif
26+
2027
/**
2128
* Described in header.
2229
*/

0 commit comments

Comments
 (0)