Interface to resolve SONAMES, ld.so.cache format

Álvaro Acción Montes alvaroaccionmontes@gmail.com
Sun Apr 27 09:12:00 GMT 2014


Hello,

This is a question I asked in the #glibc channel, but someone kindly 
pointed me to ask it here. I'll try to be as clear as I can with my 
explanation, provided I'm not really that fluent in either English, or 
explaining myself.

I'm working in a academic project, that has to do with monitoring 
executables in terms of address space usage, etc. Similar to what 
Valgrind does, but I was not the one who proposed it :)

For a series of reasons, I need to know what objects are going to be 
mapped into the process adress space, similar to what ldd does, but it 
needs to be programmatically determined (not a requirement, but it would 
cost me points). I've of course had a look to ldd's source, but it uses 
enviroment variables to tell the loader to print "debug" information. I 
was wondering if there was a well defined interface to obtain that 
information without having to rely in the method ldd uses, but it seems 
the simplest answer is the correct one, and there is no such method.

So my current approach is as follows. I get a list of required 
dependencies by iterating the .dynamic section of the executable and 
getting all the entries that are tagged as DT_NEEDED. The next step 
would be to find the shared objects with SONAME's matching the previous 
list. At this point, I was left wondering if there was a way to obtain 
them other than parsing ld.so.cache, but I had not luck. Correct me if 
I'm wrong, but it seems that the linker is a completely isolated entity, 
and the only functionality exported is via ldopen() function family.

Now, I need to parse ld.so.cache, but it seems I'm not able to figure 
it's format. There are 2 versions, and there is a note that says that 
for Glibc2.2 there is a new format added in a compatible way, but I'm 
inclined to think that a normal file would rely only in one of those, 
even if the second is kept for compatibility's sake.

So now my questions are (answering the outermost would render the 
remaining ones irrelevant):

- Is there a clean way to get the functionality of ldd programmatically. 
I.E. without having to call ldd with pipes?

- Is there a clean way to resolve SONAMES with the corresponding shared 
object in the system

- How can I parse ld.so.cache? More precissely, is it safe? Is it worth 
doing? What's the format it uses in glic-2.19 (that's not a real issue, 
it can be 2.XX)? There's a macro in glibc's source code that ues a 
binary search IIRC, but I'm not limited to that (in the sense I can use 
some less efficient alternatives if I'm able to figure the format in 
order to progress faster*)

Thank you very much for your time, and I'm really sorry for the lengthy 
email.

* For an undergraduate assignment I think this is more than enough, 
considering this mail makes for a tenth of the whole thing.



More information about the Libc-help mailing list