views:

204

answers:

3

Good afternoon,

I am having difficulties with libxml2.

I tried to build the Perl module XML-LibXML which is part of our standard runtime environment. However, this time the installation on a RHEL5 box failed, because the build process complained about missing libxml2:

$> perl Makefile.PL LIB=/foo/lib/perl PREFIX=/foo INSTALLDIRS=site
enable native perl UTF8
running xml2-config...ok (2.7.6)
looking for -lxml2... no
looking for -llibxml2... no
libxml2 not found

However, the file was available. Starting the build with

perl Makefile.PL LIB=/usr/inform/target/lib/perl PREFIX=/usr/inform/target INSTALLDIRS=site

led to more evidence of the real problem:

[...]
Can't load 'blib/arch/auto/Conftest/Conftest.so' for module Conftest: /usr/inform/target/lib/libxml2.so.2: cannot restore segment prot after reloc: Permission denied at /usr/lib/perl5/5.8.8/i386-linux-thread-multi/DynaLoader.pm line 230.
 at test.pl line 2
[...]

After some investigations I found that the problem appears to be that libxml2.so is created with text relocation:

[tess91@INF-AW] lib$ eu-findtextrel libxml2.so.2.7.6
the file containing the function 'get_crc_table' is not compiled with -fpic/-fPIC
the file containing the function 'crc32' is not compiled with -fpic/-fPIC
the file containing the function 'gzerror' is not compiled with -fpic/-fPIC
[...]

Ans since we have SElinux active on the target machine, linking against libxml.2 failed!

Is there any possibility to create libxml2 properly, or do I have to ask the admin to twist SElinux to allow relocations?

I really can't believe I am the olny one having this problem on Linux with SElinux active. What am I missing?

Any help apprecitated!

Regards, Stefan

+1  A: 

The simplest way is to have your administrator yum install libxml2-devel or even yum install perl-XML-LibXML. Otherwise, see if you can add -fPIC to the CFLAGS in the Makefile.PL.

I assume you are on 32-bit x86, any other architecture wouldn't work without -fPIC.

Adam Goode
As I understood relocation the -fPIC needs to go to the Makefile of libxml2, or am I wrong here?
struppi
Yes, or you can try to do `export CFLAGS=-fPIC` first, though that might wipe out existing important CFLAGS.
Adam Goode
A: 

I just found a possible explanation:

During the build of libxml2 the compiler flag -fPIC is indeed used, so the code is created position independant, BUT:

When creating the shared library, the static libz is linked against it. Is that the source of my problem? That including a static lib in a shared executable taints the library by introducing non-relocatable code?

The fact that the symbols eu-findtextrel should already have pointed me in that direction, since crc32, get_crc_table, etc. look like encryption centered code...

struppi
Yes! The fact that I had only a static libz has caused all my hassle. Once a dynamic libz.so was available, the problem was gone! :-)
struppi
A: 

I have both static and dynamic libz and have the same problem ???

VT
Where did you get the libxml2.so from? Did you bild it yourself or was ist part of a system install? Was the dynamic version of libz available (and visible to the loader) at the time you created the libxml2.so?
struppi