This is the mail archive of the
libc-help@sourceware.org
mailing list for the glibc project.
Re: How does dynamic loading of libnss_dns.so et al work?
- From: Arvid Brodin <arvid dot brodin at enea dot com>
- To: Petr Baudis <pasky at suse dot cz>
- Cc: libc-help at sourceware dot org
- Date: Thu, 14 May 2009 16:35:55 +0200
- Subject: Re: How does dynamic loading of libnss_dns.so et al work?
- References: <4A0AF1FC.9020607@enea.com> <20090513205553.GE14609@machine.or.cz>
On 2009-05-13 22:55, Petr Baudis wrote:
> Hello,
>
> On Wed, May 13, 2009 at 06:14:52PM +0200, Arvid Brodin wrote:
>> I need to find all dynamic libraries needed by a set of cross-built binaries. To do this, I use 'objdump -x <binary> | grep NEEDED', which gives me a list of the dynamic libraries needed by that particular binary. I then iterate the objdump on the list of libraries, until I cannot find any more dependencies.
>>
>> However, this does not work for the Name Service Switch libraries; libnss_dns.so is not listed as a NEEDED library in the objdump, but name lookup still fails with e.g.: "ping: bad address 'google.com.'" if this library and its dependencies (libresolv.so) are missing on the target system. (Using busybox ping, which calls getaddrinfo().)
>>
>> In fact, grepping on nss_dns gives no hits at all on any on the involved binaries or libs (busybox, libcrypt, libm, libc, ld-linux). Which makes me wonder: how can the executable know to load libnss_dns? What's the mechanism used to load this file (and libnss_files.so, etc.)?
>
> the executable calls libc, which will call the appropriate NSS module
> using dlopen() - applications can load additional .so libraries on the
> fly, without direct indication in any ELF section. The loading of NSS
> modules is governed by /etc/nsswitch.conf. The pthreads library and
> backtrace() can also dynamically load libgcc_s.so, while the iconv()
> function will dynamically load modules for various charsets (usually in
> /usr/lib/gconv).
>
Thanks for the detailed answer. I had a hunch that it might be a dlopen
thing, but got a bit confused by the fact that grep couldn't find the names
of the requested files in the libs that opens them, so I thought maybe it's
done differently, somehow. Anyway, I now simply tell the script to include
the extra needed libs, which solves the problem (as long as the user of the
script knows which extra libs are needed ;).
--
Arvid Brodin
Enea LCC