Dynamically linked libraries..
Hey anyone knows which function loads the dynamically linked libraries required by executables?
Or is there really such function in linux kernel? I want to k @ runtime which shared library is required by the executable..? your replies are always welcome!! |
If you want to know what shared libraries a program uses, try "ldd".
If you wonder what C functions do that, have a look at "man dlopen". Can't help you with those though. |
thanks for the reply..
I want the function in the kernel code which loads the dynamically linked libraries..? |
The kernel doesn't load libraries (exception: kernel modules). What you probably mean is dlopen or its internals. Is it correct?
|
yes you got the point..
If kernel comes to know that the currently executing executable requires some dynamically linked library the what it does? |
I did a fair amount of grepping and munging around to get a partial answer to this question. It seems part of the answer is in fs/binfmt_elf.c; load_elf_binary() calls load_elf_interp(), which in turn sets up /lib/ld-linux.so.2 to do the actual work. I suspect that the code for ld-linux is in glibc-2.4.tar.gz which you can get here: http://directory.fsf.org/GNU/glibc.html , but I haven't pinned down where yet.
The reason I know that the interpreter is /lib/ld-linux.so.2 is this: Code:
$ objdump -p hw | grep -A1 INTERP Code:
if (elf_ppnt->p_type == PT_INTERP) { Code:
$ strace ./hw I would feel a lot more confident of everything I just wrote if I had disected ld-linux. I haven't, so take it all with several grains of salt... |
of course all that assumes that you're concerned with normal shared libraries which are loaded by the loader at runtime but before your program starts executing. If you mean to load a library later, use dlopen() or such
|
All times are GMT -5. The time now is 10:12 PM. |