[syslog-ng] linking changes

Balazs Scheidler bazsi at balabit.hu
Wed Feb 23 16:09:42 CET 2011


On Wed, 2011-02-23 at 15:18 +0100, Corinna Vinschen wrote:
> On Feb 23 14:52, Balazs Scheidler wrote:
> > On Wed, 2011-02-23 at 14:31 +0100, Corinna Vinschen wrote:
> > > On Feb 23 14:11, Balazs Scheidler wrote:
> > > > Am I missing something else?
> > > 
> > > Well, yes.  As outlined in
> > > https://lists.balabit.hu/pipermail/syslog-ng/2011-February/016006.html
> > > there are two problems:
> > > 
> > > - You can't link against a static lib when creating a shared lib.  That
> > >   means, creating libdbparser.so will fail.  My patch results in
> > >   creating a shared libsyslog-ng-patterndb.so for linking libdbparser.so,
> > >   and a static libsyslog-ng-patterndb.a for linking pdbtool.
> > >   Marking both libsyslog-ng-patterndb as noinst is just to avoid that
> > >   both convenience libs are installed.
> > 
> > hmm.. not even with -fPIC ? If I have to duplicate executable code into
> > pdbtool anyway (because of static linking it), I'd rather not have a
> > separate .so which is only loaded by an .so.
> 
> -fPIC and -fpic have no effect on Windows.  The Windows loader doesn't
> support position independent code.  So, no, it won't work either.
> 
> > If that's the case, I'd include the same source files into both targets
> > (the .la one and pdbtool one)
> > 
> > > 
> > > - The link order is important when creating binaries on the Windows
> > >   platform.  Since libsyslog-ng-patterndb.a reference symbols in
> > >   ../../lib/libsyslog-ng.la, you must reorder them on the command line.
> > >   Not
> > > 
> > >     ../../lib/libsyslog-ng.la libsyslog-ng-patterndb.a
> > > 
> > >   but
> > >   
> > >     libsyslog-ng-patterndb.a ../../lib/libsyslog-ng.la
> > 
> > Ok, I've missed that, and changed my Makefile.
> > 
> > > 
> > > My patch fixes both problems.  The result should work on all platforms.
> > 
> > Thanks for your efforts, and sorry for missing the point. Hopefully we
> > can close this once and for all :)
> 
> No worries.  However, something else occured to me a couple of minutes
> ago.  If you apply my patch, you must change
> 
>   noinst_LTLIBRARIES = libsyslog-ng-patterndb.la
> 
> to
> 
>   lib_LTLIBRARIES = libsyslog-ng-patterndb.la
> 
> If you keep it in noinst_LTLIBRARIES, the libdbparse.so module will be
> broken after installtion because it requires libsyslog-ng-patterndb.so
> to run.  Sorry for forgetting that.
> 
> There are two ways to fix this.
> 
> - Move libsyslog-ng-patterndb.so to module_LTLIBRARIES and install it.
> 
> - Don't generate libsyslog-ng-patterndb.so.  Instead add the
>   patterndb source files to libdbparser_la_SOURCES, along these lines:
> 
> diff --git a/modules/dbparser/Makefile.am b/modules/dbparser/Makefile.am
> index b2ab700..f8a53f4 100644
> --- a/modules/dbparser/Makefile.am
> +++ b/modules/dbparser/Makefile.am
> @@ -21,7 +21,8 @@ libsyslog_ng_patterndb_a_CFLAGS = $(AM_CFLAGS) -fPIC
>  module_LTLIBRARIES = libdbparser.la
>  libdbparser_la_SOURCES = \
>  	dbparser.c dbparser.h \
> -	dbparser-grammar.y dbparser-parser.c dbparser-parser.h dbparser-plugin.c
> +	dbparser-grammar.y dbparser-parser.c dbparser-parser.h \
> +	dbparser-plugin.c $(libsyslog_ng_patterndb_a_SOURCES)
>  
>  libdbparser_la_CPPFLAGS = $(AM_CPPFLAGS)
>  libdbparser_la_LIBADD = ../../lib/libsyslog-ng.la libsyslog-ng-patterndb.a
> 
> I think this second solution is better.

Before making a fool from myself, can you please check if this patch is
OK, before commit & push? (against the current HEAD).

My intention was:
  * create a static lib for linking with programs (unit tests & pdbtool)
  * recompile each source files as a part of the shared library
separately

This way:
  * no linking of static lib into shared lib happens

Also, a heads up: this will be a problem again in syslog-ng OSE 3.3,
where I started to embed dependent libraries into the syslog-ng tree
(ivykis, libmongo-client) because those are not yet in widespread use.
That's implemented using static libraries and -fPIC, and I don't see an
easy solution for that problem, unless of course one obtains and
installs those libraries separately.

thanks.

$ git diff
diff --git a/modules/dbparser/Makefile.am b/modules/dbparser/Makefile.am
index b2ab700..7e4c366 100644
--- a/modules/dbparser/Makefile.am
+++ b/modules/dbparser/Makefile.am
@@ -11,26 +11,30 @@ AM_CPPFLAGS = -I$(top_srcdir)/lib -I../../lib
 AM_CFLAGS = @CFLAGS_NOWARN_POINTER_SIGN@
 export top_srcdir
 
-lib_LIBRARIES = libsyslog-ng-patterndb.a
+noinst_LIBRARIES = libsyslog-ng-patterndb.a
 libsyslog_ng_patterndb_a_SOURCES = radix.c radix.h \
        patterndb.c patterndb.h patterndb-int.h \
        timerwheel.c timerwheel.h \
        patternize.c patternize.h
-libsyslog_ng_patterndb_a_CFLAGS = $(AM_CFLAGS) -fPIC
 
+# we're not linking against the .a file as this is not supported on Cygwin,
+# even if we compile it using -fPIC.  Therefore the .a file is only used to
+# link programs, and the dbparser.so gets those files as source files,
+# thereby recompiling them twice.
 module_LTLIBRARIES = libdbparser.la
 libdbparser_la_SOURCES = \
        dbparser.c dbparser.h \
-       dbparser-grammar.y dbparser-parser.c dbparser-parser.h dbparser-plugin.c
+       dbparser-grammar.y dbparser-parser.c dbparser-parser.h dbparser-plugin.c \
+       $(libsyslog_ng_patterndb_a_SOURCES)
 
 libdbparser_la_CPPFLAGS = $(AM_CPPFLAGS)
-libdbparser_la_LIBADD = ../../lib/libsyslog-ng.la libsyslog-ng-patterndb.a
+libdbparser_la_LIBADD = ../../lib/libsyslog-ng.la
 libdbparser_la_LDFLAGS = -avoid-version -module -no-undefined
 
 bin_PROGRAMS = pdbtool
 pdbtool_SOURCES = pdbtool.c
 pdbtool_CPPFLAGS = $(AM_CPPFLAGS) @OPENSSL_CFLAGS@
-pdbtool_LDADD = ../../lib/libsyslog-ng.la libsyslog-ng-patterndb.a @TOOL_DEPS_LIBS@ @OPENSSL_LIBS@
+pdbtool_LDADD =  libsyslog-ng-patterndb.a ../../lib/libsyslog-ng.la @TOOL_DEPS_LIBS@ @OPENSSL_LIBS@
 
 BUILT_SOURCES = dbparser-grammar.y dbparser-grammar.c dbparser-grammar.h
 EXTRA_DIST = $(BUILT_SOURCES) radix-find.c dbparser-grammar.ym
diff --git a/modules/dbparser/tests/Makefile.am b/modules/dbparser/tests/Makefile.am
index 8d3a970..6726121 100644
--- a/modules/dbparser/tests/Makefile.am
+++ b/modules/dbparser/tests/Makefile.am
@@ -1,6 +1,6 @@
 AM_CFLAGS = -I$(top_srcdir)/lib -I../../../lib -I$(top_srcdir)/modules/dbparser -I.. @CFLAGS_NOWARN_POINTER_SIGN@
 AM_LDFLAGS = -dlpreopen ../../syslogformat/libsyslogformat.la
-LDADD = $(top_builddir)/lib/libsyslog-ng.la ../libsyslog-ng-patterndb.a  ../patternize.lo @TOOL_DEPS_LIBS@ @OPENSSL_LIBS@
+LDADD = $(top_builddir)/lib/libsyslog-ng.la ../libsyslog-ng-patterndb.a @TOOL_DEPS_LIBS@ @OPENSSL_LIBS@
 
 check_PROGRAMS = test_timer_wheel test_patternize test_patterndb test_radix
 



-- 
Bazsi




More information about the syslog-ng mailing list