Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: ClamAV: devel

use system libtommath when present

 

 

ClamAV devel RSS feed   Index | Next | Previous | View Threaded


steve at lobefin

Feb 19, 2009, 4:12 PM

Post #1 of 4 (727 views)
Permalink
use system libtommath when present

Hopefully this will be a useful patch.

Cheers,

[PATCH] Modify build system to conditionally use system install of libtommath -
it will be used if it is installed, or if it is explicitly enabled in
configure
Signed-off-by: Stephen Gran <steve[at]lobefin.net>

---
configure.in | 13 +++++++++++++
libclamav/Makefile.am | 19 ++++++++++++++-----
libclamav/bignum.c | 6 ++++++
libclamav/bignum.h | 6 ++++++
libclamav/bignum_class.h | 6 ++++++
libclamav/dsig.c | 4 ++++
libclamav/dsig.h | 4 ++++
7 files changed, 53 insertions(+), 5 deletions(-)

diff --git a/configure.in b/configure.in
index 3454abf..e400644 100644
--- a/configure.in
+++ b/configure.in
@@ -505,6 +505,19 @@ fi
AC_MSG_RESULT([$ZLIB_HOME])
])

+AC_ARG_ENABLE(system_tommath,
+[ --enable-system-tommath Enable use of system libtommath (default=auto)], enable_system_tommath=$enableval, enable_system_tommath="auto" )
+if test "x$enable_system_tommath" = "xauto"; then
+ AC_CHECK_HEADER([tommath.h],[have_tommath_h=yes],)
+fi
+
+if test "x$have_tommath_h" = "xyes" || "x$enable_system_tommath" = "xyes"; then
+ AC_DEFINE([USE_SYSTEM_TOMMATH], 1, [use system lintommath])
+ TOMMATH_LIBS="-ltommath"
+ AC_SUBST([TOMMATH_LIBS])
+fi
+AM_CONDITIONAL([SYSTEM_TOMMATH], test "x$ac_cv_use_system_tommath" = "xyes")
+
AC_ARG_ENABLE([zlib-vcheck],
[ --disable-zlib-vcheck do not check for buggy zlib version ],
zlib_check=$enableval, zlib_check="yes")
diff --git a/libclamav/Makefile.am b/libclamav/Makefile.am
index dd85399..931c852 100644
--- a/libclamav/Makefile.am
+++ b/libclamav/Makefile.am
@@ -87,15 +87,24 @@ libclamav_internal_utils_la_SOURCES=str.c \
regex/cname.h \
regex/regex.h \
regex/regex2.h \
- regex/utils.h \
- bignum.c \
- bignum.h \
- bignum_class.h
+ regex/utils.h
+
+if SYSTEM_TOMMATH
+else
+libclamavtommath_la_SOURCES = \
+ bignum.c \
+ bignum.h \
+ bignum_class.h
+
+lib_LTLIBRARIES += libclamavtommath.la
+libclamavtommath_la_LDFLAGS =-static
+libclamavtommath_la_CFLAGS= -fPIC -DPIC
+endif

libclamav_internal_utils_la_LDFLAGS=-static
libclamav_internal_utils_la_CFLAGS= -fPIC -DPIC

-libclamav_la_LIBADD = @LIBLTDL@ $(IFACELIBADD) lzma/liblzma.la libclamav_internal_utils.la @LIBCLAMAV_LIBS@ @THREAD_LIBS@
+libclamav_la_LIBADD = @LIBLTDL@ $(IFACELIBADD) lzma/liblzma.la libclamav_internal_utils.la @LIBCLAMAV_LIBS@ @THREAD_LIBS@ @TOMMATH_LIBS@
libclamav_la_DEPENDENCIES = @LIBLTDL@ $(IFACEDEP) libclamav_internal_utils.la
libclamav_la_LDFLAGS = @TH_SAFE@ -version-info @LIBCLAMAV_VERSION@ -no-undefined

diff --git a/libclamav/bignum.c b/libclamav/bignum.c
index b46be20..7c60f1d 100644
--- a/libclamav/bignum.c
+++ b/libclamav/bignum.c
@@ -1,3 +1,8 @@
+#if HAVE_CONFIG_H
+#include "clamav-config.h"
+#endif
+
+#ifndef USE_SYSTEM_TOMMATH
/* LibTomMath, multiple-precision integer library -- Tom St Denis
*
* LibTomMath is a library that provides multiple-precision
@@ -9514,3 +9519,4 @@ int KARATSUBA_MUL_CUTOFF = 80, /* Min. number of digits before Karatsub


/* EOF */
+#endif
diff --git a/libclamav/bignum.h b/libclamav/bignum.h
index f50ac6f..59ba109 100644
--- a/libclamav/bignum.h
+++ b/libclamav/bignum.h
@@ -1,3 +1,8 @@
+#if HAVE_CONFIG_H
+#include "clamav-config.h"
+#endif
+
+#ifndef USE_SYSTEM_TOMMATH
/* LibTomMath, multiple-precision integer library -- Tom St Denis
*
* LibTomMath is a library that provides multiple-precision
@@ -582,3 +587,4 @@ extern const char *mp_s_rmap;
/* $Source: /cvs/libtom/libtommath/tommath.h,v $ */
/* $Revision: 1.8 $ */
/* $Date: 2006/03/31 14:18:44 $ */
+#endif
diff --git a/libclamav/bignum_class.h b/libclamav/bignum_class.h
index be38efc..858d980 100644
--- a/libclamav/bignum_class.h
+++ b/libclamav/bignum_class.h
@@ -1,3 +1,8 @@
+#if HAVE_CONFIG_H
+#include "clamav-config.h"
+#endif
+
+#ifndef USE_SYSTEM_TOMMATH
/* LibTomMath, multiple-precision integer library -- Tom St Denis
*
* LibTomMath is a library that provides multiple-precision
@@ -1004,3 +1009,4 @@
/* $Revision: 1.3 $ */
/* $Date: 2005/07/28 11:59:32 $ */
#endif
+#endif
diff --git a/libclamav/dsig.c b/libclamav/dsig.c
index e1f9d46..a0bb048 100644
--- a/libclamav/dsig.c
+++ b/libclamav/dsig.c
@@ -31,7 +31,11 @@
#include "others.h"
#include "dsig.h"
#include "str.h"
+#ifdef USE_SYSTEM_TOMMATH
+#include <tommath.h>
+#else
#include "bignum.h"
+#endif

#define CLI_NSTR "118640995551645342603070001658453189751527774412027743746599405743243142607464144767361060640655844749760788890022283424922762488917565551002467771109669598189410434699034532232228621591089508178591428456220796841621637175567590476666928698770143328137383952820383197532047771780196576957695822641224262693037"

diff --git a/libclamav/dsig.h b/libclamav/dsig.h
index 8156b23..4843865 100644
--- a/libclamav/dsig.h
+++ b/libclamav/dsig.h
@@ -25,7 +25,11 @@
#include "clamav-config.h"
#endif

+#ifdef USE_SYSTEM_TOMMATH
+#include <tommath.h>
+#else
#include "bignum.h"
+#endif

int cli_versig(const char *md5, const char *dsig);
unsigned char *cli_decodesig(const char *sig, unsigned int plen, mp_int e, mp_int n);
--
1.6.0.6


--
--------------------------------------------------------------------------
| Stephen Gran | Questionable day. Ask somebody |
| steve[at]lobefin.net | something. |
| http://www.lobefin.net/~steve | |
--------------------------------------------------------------------------
_______________________________________________
http://lurker.clamav.net/list/clamav-devel.html
Please submit your patches to our Bugzilla: http://bugs.clamav.net


steve at lobefin

Feb 19, 2009, 4:57 PM

Post #2 of 4 (677 views)
Permalink
Re: use system libtommath when present [In reply to]

On Fri, Feb 20, 2009 at 12:12:11AM +0000, Stephen Gran said:
> Hopefully this will be a useful patch.

And if you add this one, it even compiles with the bundled tommath.
sorry about that - autotools after midnight is never a good idea.

[PATCH] and fix up my various errors
Signed-off-by: Stephen Gran <steve[at]lobefin.net>

---
configure.in | 4 ++--
libclamav/Makefile.am | 9 +++------
2 files changed, 5 insertions(+), 8 deletions(-)

diff --git a/configure.in b/configure.in
index e400644..3a22ff9 100644
--- a/configure.in
+++ b/configure.in
@@ -511,12 +511,12 @@ if test "x$enable_system_tommath" = "xauto"; then
AC_CHECK_HEADER([tommath.h],[have_tommath_h=yes],)
fi

-if test "x$have_tommath_h" = "xyes" || "x$enable_system_tommath" = "xyes"; then
+if test "x$have_tommath_h" = "xyes" || test "x$enable_system_tommath" = "xyes"; then
AC_DEFINE([USE_SYSTEM_TOMMATH], 1, [use system lintommath])
TOMMATH_LIBS="-ltommath"
AC_SUBST([TOMMATH_LIBS])
fi
-AM_CONDITIONAL([SYSTEM_TOMMATH], test "x$ac_cv_use_system_tommath" = "xyes")
+AM_CONDITIONAL([SYSTEM_TOMMATH], [test "x$ac_cv_use_system_tommath" = "xyes"])

AC_ARG_ENABLE([zlib-vcheck],
[ --disable-zlib-vcheck do not check for buggy zlib version ],
diff --git a/libclamav/Makefile.am b/libclamav/Makefile.am
index 931c852..73d836a 100644
--- a/libclamav/Makefile.am
+++ b/libclamav/Makefile.am
@@ -89,23 +89,20 @@ libclamav_internal_utils_la_SOURCES=str.c \
regex/regex2.h \
regex/utils.h

-if SYSTEM_TOMMATH
-else
+lib_LTLIBRARIES += libclamavtommath.la
libclamavtommath_la_SOURCES = \
bignum.c \
bignum.h \
bignum_class.h

-lib_LTLIBRARIES += libclamavtommath.la
libclamavtommath_la_LDFLAGS =-static
libclamavtommath_la_CFLAGS= -fPIC -DPIC
-endif

libclamav_internal_utils_la_LDFLAGS=-static
libclamav_internal_utils_la_CFLAGS= -fPIC -DPIC

-libclamav_la_LIBADD = @LIBLTDL@ $(IFACELIBADD) lzma/liblzma.la libclamav_internal_utils.la @LIBCLAMAV_LIBS@ @THREAD_LIBS@ @TOMMATH_LIBS@
-libclamav_la_DEPENDENCIES = @LIBLTDL@ $(IFACEDEP) libclamav_internal_utils.la
+libclamav_la_LIBADD = @LIBLTDL@ $(IFACELIBADD) lzma/liblzma.la libclamavtommath.la libclamav_internal_utils.la @LIBCLAMAV_LIBS@ @THREAD_LIBS@ @TOMMATH_LIBS@
+libclamav_la_DEPENDENCIES = @LIBLTDL@ $(IFACEDEP) libclamav_internal_utils.la libclamavtommath.la
libclamav_la_LDFLAGS = @TH_SAFE@ -version-info @LIBCLAMAV_VERSION@ -no-undefined

if VERSIONSCRIPT
--
1.6.0.6

--
--------------------------------------------------------------------------
| Stephen Gran | Beer -- it's not just for breakfast |
| steve[at]lobefin.net | anymore. |
| http://www.lobefin.net/~steve | |
--------------------------------------------------------------------------
Attachments: signature.asc (0.18 KB)


edwintorok at gmail

Feb 20, 2009, 1:56 AM

Post #3 of 4 (674 views)
Permalink
Re: use system libtommath when present [In reply to]

On 2009-02-20 02:12, Stephen Gran wrote:
> Hopefully this will be a useful patch.
>
> Cheers,
>
> [PATCH] Modify build system to conditionally use system install of libtommath -
> it will be used if it is installed, or if it is explicitly enabled in
> configure
> Signed-off-by: Stephen Gran <steve[at]lobefin.net>
>
>

Does this prefer the included tommath over the system one?

Using the system one by default would be bad, because we had to make
some changes to workaround compiler problems.

For example OpenBSD 4.3 comes with gcc3.3, that has a broken __udivti3
in libgcc2 on amd64 (see
https://wwws.clamav.net/bugzilla/show_bug.cgi?id=1409),
so MP64_BIT is turned off, to avoid using __attribute__((mode(TI))).

Best regards,
--Edwin
_______________________________________________
http://lurker.clamav.net/list/clamav-devel.html
Please submit your patches to our Bugzilla: http://bugs.clamav.net


steve at lobefin

Feb 20, 2009, 3:03 AM

Post #4 of 4 (675 views)
Permalink
Re: use system libtommath when present [In reply to]

On Fri, Feb 20, 2009 at 11:56:30AM +0200, Török Edwin said:
> On 2009-02-20 02:12, Stephen Gran wrote:
> > Hopefully this will be a useful patch.
> >
> > Cheers,
> >
> > [PATCH] Modify build system to conditionally use system install of libtommath -
> > it will be used if it is installed, or if it is explicitly enabled in
> > configure
> > Signed-off-by: Stephen Gran <steve[at]lobefin.net>
> >
> >
>
> Does this prefer the included tommath over the system one?

This patch prefers the system one (since that's generally my preference
:), but it's easy to reverse the order of the logic. I won't be able to
look at the issue until late tonight or tomorrow sometime, but if you'd
prefer it that way around, I'm happy to send a patch for that behavior.

Cheers,
--
--------------------------------------------------------------------------
| Stephen Gran | He's just a politician trying to save |
| steve[at]lobefin.net | both his faces... |
| http://www.lobefin.net/~steve | |
--------------------------------------------------------------------------
Attachments: signature.asc (0.18 KB)

ClamAV devel RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact lists@gossamer-threads.com
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.