问题描述
正如标题所述,ltrace在我的系统上无法正常工作.在大多数情况下,它不显示任何输出,例如
As the title says, ltrace does not work properly on my system.It shows no output in most cases, like
$ltrace ls
[usual ls output]
+++ exited (status 0) +++
$gcc hello.c
$ltrace ./a.out
Hello world!
+++ exited (status 0) +++
我使用的是最新的ltrace版本(来自软件包0.7.3-5.1ubuntu4
),我什至尝试从源代码重新编译而没有任何区别.我正在使用Ubuntu 16.10
,内核4.8.0-42-generic
. gcc版本是6.2.0
.
I'm using the latest ltrace version (from package 0.7.3-5.1ubuntu4
), I even tried recompiling from source with no difference.I'm using Ubuntu 16.10
, kernel 4.8.0-42-generic
. gcc version is 6.2.0
.
奇怪的是,从Internet下载的二进制文件似乎可以正常显示库调用.
Weird thing is, binaries downloaded from the Internet seem to work, correctly displaying the library calls.
我想念什么?有人能够重现该问题吗?
What am I missing? Is anyone able to reproduce the issue?
推荐答案
这可能与使用-z now
编译的二进制文件有关.我创建了一个快速测试程序(我正在使用Ubuntu 16.04):
This may have to do with binaries being compiled with -z now
. I created a quick test program (I'm using Ubuntu 16.04):
int main() {
write(0, "hello\n", 6);
return 0;
}
如果我使用gcc -O2 test.c -o test
进行编译,则ltrace可以工作:
If I compile it with gcc -O2 test.c -o test
then ltrace works:
$ ltrace ./test
__libc_start_main(0x400430, 1, 0x7ffc12326528, 0x400550 <unfinished ...>
write(0, "hello\n", 6hello
) = 6
+++ exited (status 0) +++
但是,当我使用gcc -O2 test.c -Wl,-z,relro -Wl,-z,now -o test2
进行编译时,却没有:
However when I compile with gcc -O2 test.c -Wl,-z,relro -Wl,-z,now -o test2
then it doesn't:
$ ltrace ./test2
hello
+++ exited (status 0) +++
您可以使用Ubuntu上pax-utils
包中的scanelf
检查二进制文件是否像这样编译:
You can check if a binary was compiled like so using scanelf
from the pax-utils
package on Ubuntu:
$ scanelf -a test*
TYPE PAX PERM ENDIAN STK/REL/PTL TEXTREL RPATH BIND FILE
ET_EXEC PeMRxS 0775 LE RW- R-- RW- - - LAZY test
ET_EXEC PeMRxS 0775 LE RW- R-- RW- - - NOW test2
请注意LAZY
(ltrace可以工作)与NOW
(ltrace不能).
Note the LAZY
(ltrace works) versus NOW
(ltrace doesn't).
这里还有更多讨论(但没有解决方案):
There is a little bit more discussion (but no resolution) here:
https://bugzilla.redhat.com/show_bug.cgi?id=1333481
这篇关于运行ltrace时无输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!