From owner-freebsd-hackers@freebsd.org Tue Jul 2 07:12:02 2019 Return-Path: Delivered-To: freebsd-hackers@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 8176F15C9E47 for ; Tue, 2 Jul 2019 07:12:02 +0000 (UTC) (envelope-from bapt@FreeBSD.org) Received: from smtp.freebsd.org (smtp.freebsd.org [IPv6:2610:1c1:1:606c::24b:4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "smtp.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 27A48713AC; Tue, 2 Jul 2019 07:12:02 +0000 (UTC) (envelope-from bapt@FreeBSD.org) Received: from ivaldir.etoilebsd.net (etoilebsd.net [178.32.217.76]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) (Authenticated sender: bapt) by smtp.freebsd.org (Postfix) with ESMTPSA id E39B01A6B2; Tue, 2 Jul 2019 07:12:01 +0000 (UTC) (envelope-from bapt@FreeBSD.org) Received: by ivaldir.etoilebsd.net (Postfix, from userid 1001) id 84A24B9457; Tue, 2 Jul 2019 09:12:00 +0200 (CEST) Date: Tue, 2 Jul 2019 09:12:00 +0200 From: Baptiste Daroussin To: Yuri Cc: Shawn Webb , Freebsd hackers list 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> References: <20190702031523.lhlrqnlo7pxccl42@mutt-hbsd> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="df4rgdc7uqp7e5tj" Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20180716 X-Rspamd-Queue-Id: 27A48713AC X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-2.95 / 15.00]; local_wl_from(0.00)[FreeBSD.org]; NEURAL_HAM_MEDIUM(-1.00)[-0.999,0]; NEURAL_HAM_SHORT(-0.95)[-0.947,0]; ASN(0.00)[asn:11403, ipnet:2610:1c1:1::/48, country:US]; NEURAL_HAM_LONG(-1.00)[-1.000,0] X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 02 Jul 2019 07:12:02 -0000 --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--