如何检查共享库中的哪些符号具有非位置无关代码(PIC)?

时间:2015-06-15 21:34:20

标签: linux gcc debian powerpc

我正在尝试使用debuild -i -us -uc -b构建一个.deb包,最后我看到了:

Now running lintian...
warning: the authors of lintian do not recommend running it with root     privileges!
W: libluajit-5.1-2: hardening-no-relro usr/lib/powerpc64le-linux-gnu/libluajit-5.1.so.2.1.0
E: libluajit-5.1-2: shlib-with-non-pic-code usr/lib/powerpc64le-linux-gnu/libluajit-5.1.so.2.1.0
W: luajit: hardening-no-relro usr/bin/luajit-2.1.0-alpha
W: luajit: binary-without-manpage usr/bin/luajit-2.1.0-alpha
Finished running lintian.

我有一种预感,我未能定义“PIC代码设置”,它必须位于每个外部函数的开头:

The following code might appear in a PIC code setup sequence to compute
the distance from a function entry point to the TOC base:
addis 2,12,.TOC.-func@ha
addi 2,2,.TOC.-func@l

ABI指定,第99页。

但是我找不到非PIC的符号。或者可能是一些未使用-fPIC编译的相关文件?

的信息:

系统架构:ppc64le

使用以下命令编译.so库:gcc -shared -fPIC

2 个答案:

答案 0 :(得分:2)

要查找哪些符号使您的精灵非PIC / PIE(位置无关代码/可执行文件),请使用scanelf包中的pax-utils(在ubuntu上,使用sudo apt-get install pax-utils安装):

$ scanelf -qT /usr/local/lib/libluajit-5.1.so.2.1.0 | head -n 3
  libluajit-5.1.so.2.1.0: buf_grow [0x7694] in (optimized out: previous lj_BC_MODVN) [0x7600]
  libluajit-5.1.so.2.1.0: buf_grow [0x769C] in (optimized out: previous lj_BC_MODVN) [0x7600]
  libluajit-5.1.so.2.1.0: buf_grow [0x76A0] in (optimized out: previous lj_BC_MODVN) [0x7600]
$ objdump -Sa /usr/local/lib/libluajit-5.1.so.2.1.0 | grep -A5 \ 7694:
    7694:       00 00 80 39     li      r12,0
    7698:       c6 07 8c 79     rldicr  r12,r12,32,31
    769c:       00 00 8c 65     oris    r12,r12,0
    76a0:       00 00 8c 61     ori     r12,r12,0
    76a4:       a6 03 89 7d     mtctr   r12
    76a8:       21 04 80 4e     bctrl

在我的情况下,绝对地址意味着加载r12,但对于动态库来说这是不可能的,因此链接器使用0作为该参数(我不得不使用@GOT运算符,但这是我案例的特定解决方案。)

luajit计划中,可以定义关于链接时间的地址,它看起来像这样:

    1003d0d4:   00 00 80 39     li      r12,0
    1003d0d8:   c6 07 8c 79     rldicr  r12,r12,32,31
    1003d0dc:   07 10 8c 65     oris    r12,r12,4103
    1003d0e0:   30 ca 8c 61     ori     r12,r12,51760
    1003d0e4:   a6 03 89 7d     mtctr   r12

完全不同吧?

可以在这个精彩的Gentoo wiki page上找到详细的解释。

答案 1 :(得分:1)

失败的林田检查是这样的:

LocalDateTime

因此,您可以通过查找包含UTC动态部分的 # Now that we're sure this is really a shared library, report on # non-PIC problems. if ($objdump->{$cur_file}->{TEXTREL}) { tag 'shlib-with-non-pic-code', $cur_file; } 来找到有问题的文件(它正在进入您的最终链接)。

为此,您可以使用.o,如下所示:

TEXTREL