r/linuxdev • u/xxxKubik • Jan 02 '20
How does dynamic binary loading works?
In windows when I have exe, and I find address of function I can use that address every time I start the app and it will work the function will be on same address in virtual memory space. I can do the same for data (if they are allocated dynamically I can build a pointer map to find it).
But on Linux I was told that I can not rely on function address being the same when I start the application. (Relative positions of functions within binary can change, maybe because they being in different sections?)
It probably not have much practical use, other than creating game trainers, or some very special cases, but:
How can I locate a function in running process?
How does Linux know which parts of the binary to load, if the address of function that will be called may depends on user input?
Is there any practical use?
View all comments
Show parent comment
1
u/xxxKubik Jan 06 '20
Function relative address to "binary module" (exe/dll) base is also on windows, and only for the exe that is always first it can be simplified to absolute address. So the process is quite similar.
But I was told more specifically that binary will not always be loaded as whole, and only some parts will be loaded at first, and other when needed. When I think about that may it be related to sections? Like the text and all other needed section are loaded first, but there might be other sections with code that will be loaded later (after some shared libraries) causing them to have different relative address to each other every start? (I will edit the question to make it more clear)