Hi Alberto,

 

The error you’re seeing is because the libjson-c.a static library wasn’t compiled with -fPIC, not because ClamAV wasn’t compiled with -fPIC.  The -fPIC option makes it possible for another library (like libclamav.so) to link in libjson-c.a.  The default build settings for json-c currently don’t have -fPIC enabled so many distribution’s json-c packages may not work with the --with-libjson-static option.  I recently got a pull-request merged into the json-c project to fix this in json-c’s CMake build tools (see: https://github.com/json-c/json-c/pull/634) so future versions of libjson-c.a will not have the issue you just encountered but the change is not yet in a release.

 

For now, your options are to:

  1. Build libjson-c.a manually, adding the -fPIC option to your CFLAGS for the build.
  2. Skip the --with-libjson-static option. Unless you’re providing libclamav as a package for other application developers to use, it is perfectly safe to skip the --with-libjson-static option.

 

Best,

Micah

 

From: clamav-users <clamav-users-bounces@lists.clamav.net> on behalf of Alberto Matxain via clamav-users <clamav-users@lists.clamav.net>
Reply-To: "albertomatxain@protonmail.com" <albertomatxain@protonmail.com>, ClamAV users ML <clamav-users@lists.clamav.net>
Date: Friday, June 19, 2020 at 4:53 AM
To: "clamav-users@lists.clamav.net" <clamav-users@lists.clamav.net>
Cc: "albertomatxain@protonmail.com" <albertomatxain@protonmail.com>
Subject: [clamav-users] How to recompile with -fPIC?

 

Hi.

 

I'm trying to install the latest version of clamav (0.102.3) on Ubuntu 20.04. I'm configuring clamav following the steps explained in http://www.clamav.net/documents/installation-on-debian-and-ubuntu-linux-distributions. It's the first time that I download the source code and I configure and compile a programme. I'm blocked because I don't know how to recompile with fPIC.

 

The two last steps:

 

./configure --enable-check --disable-clamav --with-libjson-static=/usr/lib/x86_64-linux-gnu/libjson-c.a

 

configure: Summary of detected features follows

              OS          : linux-gnu

              pthreads    : yes (-lpthread)

configure: Summary of miscellaneous features

              check       : -lcheck_pic -pthread -lrt -lm -lsubunit

              fanotify    : yes

              fdpassing   : 1

              IPv6        : yes

              openssl     : /usr

              libcurl     : /usr

configure: Summary of optional tools

              clamdtop    : yes (-lncurses)

              milter      : no (missing libmilter) (disabled)

              clamsubmit  : yes (libjson-c-dev found at /usr, linking=static)

              clamonacc   : yes (auto)

configure: Summary of engine performance features

              release mode: yes

              llvm        : no (disabled)

              mempool     : yes

configure: Summary of engine detection features

              iconv       : yes

              bzip2       : ok

              zlib        : yes (from system)

              unrar       : yes

              preclass    : yes (libjson-c-dev found at /usr, linking=static)

              pcre        : /usr

              libmspack   : yes (Internal)

              libxml2     : yes, from /usr

              yara        : yes

              fts         : yes (libc)

             

I think it's all right. Then, I try to compile:

 

make -j2

 

(...)

*** Warning: Linking the shared library libclamav.la against the

*** static library /usr/lib/x86_64-linux-gnu/libjson-c.a is not portable!

/usr/bin/ld: /usr/lib/x86_64-linux-gnu/libjson-c.a(json_object.o): relocation R_X86_64_TPOFF32 against `tls_serialization_float_format' can not be used when making a shared object; recompile with -fPIC

collect2: error: ld returned 1 exit status

make[4]: *** [Makefile:1547: libclamav.la] Error 1

make[4]: Leaving directory '/home/alberto/Deskargak/clamav-0.102.3/libclamav'

make[3]: *** [Makefile:4320: all-recursive] Error 1

make[3]: Leaving directory '/home/alberto/Deskargak/clamav-0.102.3/libclamav'

make[2]: *** [Makefile:1463: all] Error 2

make[2]: Leaving directory '/home/alberto/Deskargak/clamav-0.102.3/libclamav'

make[1]: *** [Makefile:853: all-recursive] Error 1

make[1]: Leaving directory '/home/alberto/Deskargak/clamav-0.102.3'

make: *** [Makefile:649: all] Error 2

 

Those are the last messages. I have to recompile with -fPIC, but I don't know how. I've spent some hours trying to find the way to do it, but... Can you help me? Thank you very much.

 

Alberto

 

 

Sent with ProtonMail Secure Email.