Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No output when running 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) +++

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.

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?

like image 522
scristalli Avatar asked Apr 04 '17 17:04

scristalli


People also ask

What is ltrace command?

ltrace is a program that simply runs the specified command until it exits. It intercepts and records the dynamic library calls which are called by the executed process and the signals which are received by that process. It can also intercept and print the system calls executed by the program.

What is the function of Strace and ltrace?

Both strace and ltrace are powerful command-line tools for debugging and troubleshooting programs on Linux: Strace captures and records all system calls made by a process as well as the signals received, while ltrace does the same for library calls.


1 Answers

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;
}

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) +++

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) +++

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

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

like image 88
Doug Hoyte Avatar answered Oct 14 '22 14:10

Doug Hoyte