srg wrote:
Hi
In dynamic linking, when relocations are patched, are all calls and instructions with memory access edited with the new base address of the library in memory plus the offset of the symbol, so global variable access and jumps go to the right place?
Should've replied before...
Normal loading -> patching all relocations to point to the right place, load all in place, add swap entries (if necessary that is, to make it swappable), start program
dynamic loading (hope to get it right, thinking X86 ELF here) :
File is loaded verbatim, section by section. Dynamic linking symbol table is loaded too, shared libraries as specified by DT_SHARED (or sth similar) entries are loaded using this same routine (it ends somewhere, use ldd to list). Dynamic symbols that are procedures have a PLT (procedure linkage table), global external variables (for any one of the functions, including shared library functions) are done through the GOT. The PLT is a table of code with addresses mixed in, where the jump address is initially a jump to the next address. The code there loads the function number, calls an OS service to ask for the real address (couldn't bind later...), that service maps it and returns the address. Address is replaced, and jumped to the call at that place (now using the CORRECT address just asked for) and the call is performed. This prevents a lot of linking overhead, but does incur a little performance hit each time a new function is called.
The GOT is just filled in with offsets of all sorts of objects

.
BTW, do note that the EBX register is the only one used for purposes other than calculation, it's used for the base of any given dynamic library. The GOT is at a specific location and can thus be loaded at that location statically, and linked statically. The offsets themselves change inside the table.
HTH, C&CW, Candy