Question: Is there a way to get the list of all dynamic libraries needed by a given elf through API?
Baptiste Daroussin
bapt at FreeBSD.org
Tue Jul 2 07:12:02 UTC 2019
On Mon, Jul 01, 2019 at 10:27:25PM -0700, Yuri wrote:
> On 2019-07-01 20:15, Shawn Webb wrote:
> > $ ldd -f '%p\n' /bin/ls
>
>
> Hi Shawn,
>
>
> ldd doesn't do what I need. It sets one specific environment variable, then
> forks and calls execl(3).
>
> And I am looking for the API function like: char*
> find_shared_library_mapping(const char *so_lib, char *buf_out, size_t
> buf_out_sz); // or something like this.
>
Use libelf, and read the dynamic section which will give you everything you
want:
readelf -d which uses libelf, will give you this with all the NEEDED tag.
The same way you can get the runpath and rpath
Tag Type Name/Value
0x0000000000000001 NEEDED Shared library: [libutil.so.9]
0x0000000000000001 NEEDED Shared library: [libncursesw.so.8]
0x0000000000000001 NEEDED Shared library: [libc.so.7]
The good thing about it is that you will you will only get the direct
dependency.
This is through this lib that pkg extract the list of required libraries
Best rgeards,
Bapt
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <http://lists.freebsd.org/pipermail/freebsd-hackers/attachments/20190702/ea92b757/attachment.sig>
More information about the freebsd-hackers
mailing list