有没有办法在 Linux 上构建 libxml2 而不需要文本重定位?

发布于 2024-08-11 16:34:11 字数 1348 浏览 5 评论 0原文

下午好,

我在使用 libxml2 时遇到了困难。

我尝试构建 Perl 模块 XML-LibXML,它是我们标准运行时环境的一部分。然而,这次在 RHEL5 机器上的安装失败了,因为构建过程抱怨缺少 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

但是,该文件可用。开始构建

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

导致了真正问题的更多证据:

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

经过一些调查,我发现问题似乎是通过文本重定位创建的 libxml2.so

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

回答,因为我们在目标上激活了 SElinux机器,链接 libxml.2 失败!

是否有可能正确创建libxml2,或者我是否必须要求管理员扭转SElinux以允许重新定位?

我真的不敢相信我是第一个在 SElinux 处于活动状态的 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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

扎心 2024-08-18 16:34:11

最简单的方法是让管理员 yum install libxml2-devel 甚至 yum install perl-XML-LibXML。否则,请查看是否可以将 -fPIC 添加到 Makefile.PL 中的 CFLAGS。

我假设您使用的是 32 位 x86,如果没有 -fPIC,任何其他架构都无法工作。

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.

对你再特殊 2024-08-18 16:34:11

我刚刚找到了一个可能的解释:

在 libxml2 的构建过程中,确实使用了编译器标志 -fPIC,因此代码的创建与位置无关,但是

创建共享库时,静态 libz 被链接到它。这是我的问题的根源吗?在共享可执行文件中包含静态库会通过引入不可重定位代码来污染库吗?

事实上,符号 eu-findtextrel 应该已经向我指出了这个方向,因为 crc32get_crc_table 等看起来像以加密为中心的代码......

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文