Program Loader and Runtime linker are the same in linux?
I mean ld-linux.so
acts as both loader during a program start time, and also as dynamic linker when dlopen()
is called?
Asked
Active
Viewed 1,952 times
0

Lunar Mushrooms
- 8,358
- 18
- 66
- 88
2 Answers
3
I think there are very related, but not exactly the same.
The /lib/libdl.so
(or /lib/x86_64-linux-gnu/libdl.so.2
on my system) library (containing dlopen
and dlsym
) is a sort of stub or glue code or wrapper using some part of /lib/ld-linux.so.2
(or /lib64/ld-linux-x86-64.so.2
) but it does not contain the same symbols, as you can check with nm -D
.
Definitely dlopen
and the dynamic loader do very similar things: mmap-ing segments and interpreting relocation orders. See this link and levine's linkers and loaders book
Look into Gnu Libc source code like dl-runtime.c etc

Basile Starynkevitch
- 223,805
- 18
- 296
- 547
2
Program Loader and Runtime linker are the same in linux?
Yes, they are. This is also true for every other ELF platform.

Employed Russian
- 199,314
- 34
- 295
- 362
-
Thanks. The program loader and run time linker could be different for any non-ELF platforms? Any examples? – Lunar Mushrooms Dec 11 '11 at 09:27
-
1On AIX, the program loader is part of the kernel, and the runtime linker is in a user-level library. http://publib.boulder.ibm.com/infocenter/aix/v6r1/index.jsp?topic=%2Fcom.ibm.aix.genprogc%2Fdoc%2Fgenprogc%2Fshared_object_runtime_linking.htm – Employed Russian Dec 11 '11 at 15:52
-
Not exactly, see my reply. But they are related. – Basile Starynkevitch Dec 11 '11 at 21:29
-
1@BasileStarynkevitch Your answer is incorrect. While `dlopen` in fact is contained in `libdl.so`, that library doesn't perform the *actual* work; instead it just calls on `ld-linux` to do that. In particular, `dl-runtime.c` that you referenced is linked into `ld-linux`, and not into `libdl`. – Employed Russian Dec 11 '11 at 23:09
-
This is exactly what I said: dlopen inside libdl is just a wrapper or a glue to some code in ld-linux. The real work is done inside ld-linux, libdl is just some glue code. – Basile Starynkevitch Dec 12 '11 at 05:44
-
On Linux the program loading is part of the kernel (`execve`) while loading is done by ld-linux.so (`man ld.so`). See http://stackoverflow.com/questions/26876247/how-does-execve-call-dynamic-linker-loader-ld-linux-so-2 I think this answer is not really correct and omits quite a lot of details about the loading of a program on Linux. Another answer about loaders on Linux can be found here: http://programmers.stackexchange.com/a/95740/92774 – lanoxx Jan 30 '15 at 22:27