English 中文(简体)
Is there a way to build a libxml2 without text relocations on Linux?
原标题:

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

最佳回答

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...

问题回答

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.





相关问题
Signed executables under Linux

For security reasons, it is desirable to check the integrity of code before execution, avoiding tampered software by an attacker. So, my question is How to sign executable code and run only trusted ...

encoding of file shell script

How can I check the file encoding in a shell script? I need to know if a file is encoded in utf-8 or iso-8859-1. Thanks

How to write a Remote DataModule to run on a linux server?

i would like to know if there are any solution to do this. Does anyone? The big picture: I want to access data over the web, using my delphi thin clients. But i´would like to keep my server/service ...

How can I use exit codes to run shell scripts sequentially?

Since cruise control is full of bugs that have wasted my entire week, I have decided the existing shell scripts I have are simpler and thus better. Here is what I have so far svn update /var/www/...

Good, free, easy-to-use C graphics libraries? [closed]

I was wondering if there were any good free graphics libraries for C that are easy to use? It s for plotting 2d and 3d graphs and then saving to a file. It s on a Linux system and there s no gnuplot ...

热门标签