Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: How to get all shared libs of a path?

by shmem (Chancellor)
on Jun 20, 2021 at 20:48 UTC ( [id://11134093]=note: print w/replies, xml ) Need Help??


in reply to How to get all shared libs of a path?

I'm using Linux env. I'm looking for a way to get all shared libraries of path.

First question: why? for what purpose?
Second question: in what context? do you mean system context, or your own?

In my insane $HOME I not only have a ~/bin directory with strange things, setting LD_LIBRARY_PATH and LD_PRELOAD but also other funny places where libs are stuffed away, e.g. perlbrew things and custom XS perl packages which sport their own *.so files.

I would go the other way round. The linker already knows where to look for shared libraries. That's in /ec/ld.so.conf and /etc/ld.so.conf.d/*. I'd read these files, get the shared libraries living in these directories (excluding symlinks of course). These are the libs you probably want, for the system. For my own lumber-room I'd include my LD_LIBRARY_PATH values in the directory list.

To get any shared libraries I'd use locate, e.g. locate .so | perl -lnE 'next if -l or !/\.so$/;say' which gets them all.

Depending on what you want to do, you could ask the package manager about the owning package of each lib, using dpkg -S $lib or rpm -qf $lib. Having those packages, you can do a "reverse depends" for these packages and query the resulting packages for binaries in $PATH.

I'm just guessing that you want to do some sort of an inventory, in the posted code you are just getting usage count for each lib. There are other reasons to look up libs, e.g. identify suspicious libs which don't pertain to any package. Hence the first question above.

perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'

Replies are listed 'Best First'.
Re^2: How to get all shared libs of a path?
by ovedpo15 (Pilgrim) on Jun 21, 2021 at 20:43 UTC
    Hi, thanks for your suggestions. I think that my mistake is that I didn't explain the big picture. I have a file of paths that define my tool (all the needed paths to run my tool). I want to create a Dockerfile/Podman-file/Sing-file based on those dependencies so the container will be able to run the tool inside it. I want to find all the RPM packages of those paths. For that I use:
    rpm -qf --queryformat "[%{NAME}]" [path]
    But this command does not give me all the packages I need. I noticed that if I use ldd [path] to get all shared libs and then for each lib, run the above RPM command, then I'll get all the needed packages.

    Now that I have explained the big picture, I'll talk about your suggestions. The locate is a good suggestion. I'll have to combine it with the objdump that was mentioned here. The ldd was working pretty well, but is objdump -p /path/to/program | grep NEEDED and then locate (and then rpm find) is a better approach?
    Now that I have explained the big picture (sorry again that it was not in the main post), is it possible to suggest a better approach? Ideally I would want the rpm command to be able to get a path and return the packages of both the path and the shared libs of the path. This way I won't have to use the ldd command.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11134093]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (1)
As of 2024-04-25 01:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found