0

I am compiling a big project. This project is using shared libraries, especially lapack ones.

I would want to be sure, for a given function, in which shared library the system finds it.

Here the nm output:

$ nm -DC ~/bin/app | grep potrf
                 U dpotrf_

As expected, dpotrf_ is undifined.

Here the result with objdump:

$ objdump -TR  ~bin/app | grep potrf
0000000000925428 R_X86_64_JUMP_SLOT  dpotrf_

So objdump find something! Is there any option to show in which shared lib it finds it? Or another program to do that?

Jérôme
  • 2,640
  • 3
  • 26
  • 39

1 Answers1

3

ldd is definitely a starting point to find the candidate libraries. Here's what I have in my .bashrc for such purposes (not beautiful, but serves my purposes).

Basically, I do nm on all libraries (.a, .so) in a subdirectory. If nm produces an output for the searched symbol, I print the library name and the relevant lines from nm. Your last step would then be to search for lines starting with "T" as these are the ones defining your symbol as program code (text).

# run nm on a set of objects (ending with the 1st parameter) and
# grep the output for the 2nd parameter
function nmgrep ()
{
    for i in $( find \. -name \*$1 ); do
        if [[ ! -e $i ]]; then
            continue;
        fi  
        nm $i | grep $2 > /tmp/foo.tmp;
        if [[ -s /tmp/foo.tmp ]]; then
            echo $i; 
            cat /tmp/foo.tmp | grep $2
        fi  
        rm /tmp/foo.tmp
    done  
}

# find symbols definied/referenced in libs
function libgrep ()
{
    nmgrep .a $@
    nmgrep .so $@
}
BjoernD
  • 4,720
  • 27
  • 32