Date: Tue, 2 Jul 2019 09:12:00 +0200 From: Baptiste Daroussin <bapt@FreeBSD.org> To: Yuri <yuri@rawbw.com> Cc: Shawn Webb <shawn.webb@hardenedbsd.org>, Freebsd hackers list <freebsd-hackers@freebsd.org> Subject: Re: Question: Is there a way to get the list of all dynamic libraries needed by a given elf through API? Message-ID: <20190702071200.qy6hr5yhaczhj6wx@ivaldir.net> In-Reply-To: <c04b30b9-8f1f-15dc-f93d-e3d8cd1f5fa0@rawbw.com> References: <dfac779f-fa4f-a292-1a76-a9e7db5e024a@rawbw.com> <20190702031523.lhlrqnlo7pxccl42@mutt-hbsd> <c04b30b9-8f1f-15dc-f93d-e3d8cd1f5fa0@rawbw.com>
next in thread | previous in thread | raw e-mail | index | archive | help
--df4rgdc7uqp7e5tj Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable 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 >=20 >=20 > Hi Shawn, >=20 >=20 > ldd doesn't do what I need. It sets one specific environment variable, th= en > forks and calls execl(3). >=20 > 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. >=20 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 --df4rgdc7uqp7e5tj Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCAAdFiEEgOTj3suS2urGXVU3Y4mL3PG3PloFAl0bA70ACgkQY4mL3PG3 PlpCAw//be6QYmWWMP6BkQVLAOTXem2vEeBHevYTiJBi7IcXaArXVLeI26Ba2hCP 9sFK+hy6tkW11m6AgkzwBKyHdxpZxhqP0usCFWu8iOGSWZT4s5SEVzvcnMYne4uv pdcdZNrG5NliPleuhXM0WsRQi8WAdcf26mMKjkckKk1usd7QOKoZD3ZqVEKtzyjP V9DiOC9Rz8qWrkmTJDkStZxGW9it0EyxiacwuH2+8JeL1DOcVfAOpGI3hgvxRYim g2oZ9hTpEFkidd4aZJxIDCAZKjzxB95ch0XQdC3VVXeisypl+jKQO5C72cWyvsJz arTmiYA5jyAtLpcAXlHPyUc70NJrE8g8XM1u+XRd2fuHw03CKORlYegZadEhW8+e 79heS2UNuZnQixkff5UVLkmXwOQN4JKeSu9eCkNHS6+wdQ0+aYuUs33S5EZwH956 6V1IE9e5BHwySe3PjRjRuh9pqz8/2k8v3LUWsRC+oM2fnoK/vBbsBOYw4icx/dJp Z14inqyI20nKiese8KhspxBlhCGgbbzsOpaJeW8jzTKweO2LNMPDIeexj91THSYt GTHjpYNhyNhMxZdV28ZFQCN+zC8h/qyAdwivKMfpNIvGfSjGf7Pml0UB3CMAMQn+ AelPN9oEDJ4BDhCNHABBPoMob0J4AtkUuRFP1yOgXZ/wR9tnlK8= =HqEs -----END PGP SIGNATURE----- --df4rgdc7uqp7e5tj--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20190702071200.qy6hr5yhaczhj6wx>