0

CSAPP says

Linux systems provide a simple interface to the dynamic linker that allows application programs to load and link shared libraries at run time.

#include <dlfcn.h>
void *dlopen(const char *filename, int flag);

Returns: pointer to handle if OK, NULL on error

Does dlopen() performs dynamic linking by invoking dynamic linker ld-linux.so?

Is ld-linux.so the dynamic linker which dlopen() invokes to perform dynamic linking?

Thanks.

3

dlopen is provided by libdl, but behind the scenes, with the GNU C library implementation at least, the latter relies on symbols provided by ld-linux.so to perform the dynamic linking. If dlopen is called from a dynamically-linked program, ld-linux.so is already loaded, so it uses those symbols directly; if it’s called from a statically-linked program, it tries to load ld-linux.so.

9
  • Admitted the question was very poor, but this answer could still be a little more precise. dlopen does not "invoke" ld-linux.so in any way -- if you call dlopen from a static executable, it will (try to) open and load ld-linux.so (as yet another dynamic object) in order to use the functions defined within it. With a dynamic executable, ld-linux.so is already in the memory of the process -- dlopen doesn't even have to load it, it just calls into it.
    – user414777
    Sep 28 '20 at 0:43
  • @user414777 thanks for the extra information. I don’t think I wrote that dlopen “invokes” ld-linux.so, did I? I wrote that it relies on dl-linux.so, which is true in either case. I’ll rephrase to make it clearer. Sep 28 '20 at 4:47
  • The OP did, suggesting that dlopen somehow executes ld.so. Maybe it was just awkward phrasing, but my impression was that the OP's question (and other question of the same series) are somehow leading, trying to extract ridiculous generalities. I hope I'm wrong. Wrt another answer of yours, notice that an ELF executable does not need an entry point; Linux will ignore its entry point if its program header table has a PT_INTERP entry.
    – user414777
    Sep 28 '20 at 10:05
  • Right, I take it you’re not familiar with Tim’s style of questions ;-). AIUI Linux doesn’t ignore the entry point, it passes it to the interpreter in the execution attributes, doesn’t it? Sep 28 '20 at 10:37
  • Yes, by "ignore" I was meaning that the Linux kernel would not care about it, it can have any value as long as the ELF points to an interpreter. And then the interpreter may not care about it either.
    – user414777
    Sep 28 '20 at 10:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.