Search code examples
pythonluashared-librarieslibrariesinterpreted-language

How to check what shared libraries are linked when I run a interpreted language binary and its script?


I am trying to find every library that is actually needed to run a lua script that requires torch libraries

test.lua:

#!/usr/bin/env lua

print "Welcome to LUA"
print('_VERSION = ' .. _VERSION)
require("nn") -- this loads torch nn libraries to be further used in the code
print "Load pass"

Output:

Welcome to LUA
_VERSION = Lua 5.1
Load pass

When I use

lld ./lua
# or
lld ./lua test.lua

I get the following output:

ldd ./lua ../../../bin/test.lua
    linux-vdso.so.1 =>  (0x00007ffdba77d000)
    libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f160dd3e000)
    libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f160db3a000)
    libreadline.so.6 => /lib/x86_64-linux-gnu/libreadline.so.6 (0x00007f160d8f3000)
    libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f160d52a000)
    /lib64/ld-linux-x86-64.so.2 (0x00005580e2ebd000)
    libtinfo.so.5 => /lib/x86_64-linux-gnu/libtinfo.so.5 (0x00007f160d301000)
../../../bin/test.lua:
    not a dynamic executable

Obviously the libraries used by torch nn are not displayed here. We only see the necessary libraries to the "lua" program

If make the test.lua an executable file and I run ldd ./test.lua, I get the following output

ldd ./test.lua 
    not a dynamic executable

How to check what libraries (or .so) are linked when I run a interpreted language binary and its script? (in Lua and in Python)


Solution

  • You can use LD_DEBUG:

    $ LD_DEBUG=all python tmp.py 2>&1 | grep 'generating link map'
    3358:   file=libpthread.so.0 [0];  generating link map
    3358:   file=libc.so.6 [0];  generating link map
    3358:   file=libdl.so.2 [0];  generating link map
    3358:   file=libutil.so.1 [0];  generating link map
    3358:   file=libz.so.1 [0];  generating link map
    3358:   file=libm.so.6 [0];  generating link map
    

    Keep in mind that if your app only loads library on particular event, you may not see it during default run.