How do I know which "sin" function my program is executing at startup?

I am using different versions of libm.a. The one I'm playing with is fdlibm libm.a (from Sun).

The problem is that I feel like my program does not call functions in fdlibm libm.a, but calls them on glibc libm.a system.

#include "fdlibm.h"
int main(){
  double x = sin(3);
}

      

The program is compiled in C ++ programs (because it needs to be linked with other C ++ programs):

g ++ prog.cpp libm.a

where libm.a is fdlibm. (From the Sun, http://www.netlib.org/fdlibm/readme )

Question 1

How can I find out what is really calling sin

at runtime? I've heard about various tools like objdump, gdb ... Which one can I use for my case and how?

Question 2

How can fdlibm libm.a be used?

Thank.

+3


source to share


3 answers


Question 1. I have heard about various tools like objdump, gdb.

As with gdb. Create trace_sin.gdb file

$ cat trace_sin.gdb
set confirm off
b sin
commands
bt
c
end
r
quit

      

And run your program:



$ gdb -q -x trace_sin.gdb   ./a.out Reading symbols from ./a.out...(no
debugging symbols found)...done. Breakpoint 1 at 0x400498

Breakpoint 1, 0x000000314941c760 in sin () from /lib64/libm.so.6
#0  0x000000314941c760 in sin () from /lib64/libm.so.6
#1  0x0000000000400629 in main ()

      

As you can see in my case sin

comes from libm

Question 2. How can fdlibm libm.a be used?

Just make sure sin

fdlibm goes to libmsin

+5


source


I'm tired of linking / lazy loading the .so version of a library, and somewhere I found that you can achieve a link to a specific library by specifying the library path.

Perhaps this can help with your task.

example - I can change this command (and link to SDL2.so)

$(CC) $(CC_FLAGS)  $<  -o $@  -L../../bag  -lbag_i686 -lSDL2

      

and achieve the same result with



$(CC) $(CC_FLAGS)  $<  -o $@  -L../../bag  -lbag_i686 /usr/local/lib/libSDL2.so

      

Explicitly determining which library to use.


On ubuntu I can use "locate" to find the full path to the file. It turns out SDL2 (.so) ends up in / usr / local / lib and / usr / lib / x86_64-linux-gnu. I suppose x86_64 is more appropriate for my system as well as links.

+1


source


I used the following simple technique to "neatly specify" (implicit) the library needed to link. This method may be right for you.

I already created several libraries that I had to use, and they were all in one specific path: "/ home // cvs-tools / lib1". )

When it came time to use the 1 boost lib I needed, I just copied the latest libboost_chrono.a to "/ home // cvs-tools / lib1". Not. So on the way.

And touched my makefiles, so when I updated boost, instead of trying to remember all the implications, I just added a copy of chrono.a to my lib1, and my normal build, and then updated the copy of lib1.

So by "mildly specific" I mean that a) my make file copied b) the specific COTS (boost) library to c) my lib1 directory and thus got the same -L.

+1


source







All Articles