Dynamic Linker design and the role of ld.so
Posted: Mon Feb 03, 2025 12:13 pm
I'm at the point in which I can start to contemplate a dynamic linker, which I find quite exciting as its the furthest I've ever gotten before.
The design, however, seems to elude me slightly - there's a lot of conflicting information out there, and much of it is quite sparse.
AIUI there's two steps to dynamic linking, which makes sense - load the libraries, parse them, and put them in address space being step 1, and populating the addresses in the relocation table/GOT being step 2. So far, so good.
This can be done statically by the kernel at load time (I think), which is quite possibly the simplest way to go about it, but (1) advice all suggests move step 2 to runtime, not load time, but never elaborates why, and (2) existing systems make use of ld.so, and nowhere online do I see elaborated which of the 2 steps ld.so is responsible for, nor what the interface for it is, and how (and, for that matter, why) to use it.
Ergo, some clarifying questions:
1.) why not do step 2 at load time? Why is conventional advice "install a helper stub that can go pull the information from the relocation table"? Realistically I could see it as a latency optimisation, but right now that's the only use I can conceive.
2.) what does ld.so do? Resolve symbols, or load libraries *and* resolve symobls? `man ld.so` suggests both, but information is contradictory elsewhere.
3.) what is the ld.so interface? This is documented nowhere that I've found thus far - if I want to use it, how? There is, perhaps, a nonzero chance this would be overkill for hobby OS, but it must surely serve some purpose or the larger *NIXen wouldn't go down that path.
4.) see above, por que ld.so over putting it in the kernel?
For now I'll probably just do everything at load time, until it doesn't work, but I would like to get a better understanding of why this isn't typically done in order to aid my design.
Thanks all,
Venos :3
The design, however, seems to elude me slightly - there's a lot of conflicting information out there, and much of it is quite sparse.
AIUI there's two steps to dynamic linking, which makes sense - load the libraries, parse them, and put them in address space being step 1, and populating the addresses in the relocation table/GOT being step 2. So far, so good.
This can be done statically by the kernel at load time (I think), which is quite possibly the simplest way to go about it, but (1) advice all suggests move step 2 to runtime, not load time, but never elaborates why, and (2) existing systems make use of ld.so, and nowhere online do I see elaborated which of the 2 steps ld.so is responsible for, nor what the interface for it is, and how (and, for that matter, why) to use it.
Ergo, some clarifying questions:
1.) why not do step 2 at load time? Why is conventional advice "install a helper stub that can go pull the information from the relocation table"? Realistically I could see it as a latency optimisation, but right now that's the only use I can conceive.
2.) what does ld.so do? Resolve symbols, or load libraries *and* resolve symobls? `man ld.so` suggests both, but information is contradictory elsewhere.
3.) what is the ld.so interface? This is documented nowhere that I've found thus far - if I want to use it, how? There is, perhaps, a nonzero chance this would be overkill for hobby OS, but it must surely serve some purpose or the larger *NIXen wouldn't go down that path.
4.) see above, por que ld.so over putting it in the kernel?
For now I'll probably just do everything at load time, until it doesn't work, but I would like to get a better understanding of why this isn't typically done in order to aid my design.
Thanks all,
Venos :3