I am writing a small x86-64 OS. I am trying to make sense of how Linux loads modules at runtime by linking them into the kernel.
I understand that Linux builds a symbol lookup table. Basically, a module is compiled with a special utility which keeps all the symbols intact. Then, the Linux kernel will read the symbols and compare these to the symbol lookup table. Once it has got the address for the symbol, it links the symbol in the module to the actual address of the function in the virtual address space.
This seems quite easy to implement but I wonder how, in C++, you can implement such a symbol lookup table. I know that you can easily get the address of a function with &function
. How do you get the symbol of the function in the form of ASCII letters?
Basically, how does Linux build its symbol lookup table? Is it during compilation or at boot? Also, I know that C++ is not the best tool for this because it mangles function names a lot.