I wanted to list the functions used in my application program using ltrace. It works but does not list "sin()" in the output.
#include<stdio.h>
#include<math.h>
int main()
{
float x=0;
printf("Hello World!!\n");
x=sin(2);
printf("sin(2)=%f\n",x);
return 0;
}
Output:
[kashi@localhost TestPrgms]$ gcc -o ltrace_test ltrace_test.c -lm
[kashi@localhost TestPrgms]$ ltrace ./ltrace_test
__libc_start_main(0x80484e0, 1, 0xbfddbfd4, 0x8048530 <unfinished ...>
puts("Hello World!!"Hello World!!
) = 14
printf("sin(2)=%f\n", 0.909297sin(2)=0.909297
) = 16
+++ exited (status 0) +++
This is because your
sin
call is a constant value andgcc
optimizes it out (even when compiling with-O0
and without-lm
). This is the result of runningdisass main
ingdb
:There is no call for
sin
here.Changing your code to read:
will make you need
-lm
when compiling:and now you'll see this disassembled output:
and the call in
ltrace
: