I've been trying to get a better grasp of how shared libraries work but I just can't rap my head around two things.
1- Each process has its own virtual memory space and page table, so If a shared library gets loaded into one process virtual memory space then how can a second process access that shared library since it's not in its memory space?
2- I understand that only the text section is shared while global data is not, how is this possible? My understanding is that each reference to a global variable is done via the Global Offset Table (GOT for short). So, if I have this line of code x = glob
then this will roughly equal something like mov eax,DWORD PTR [ecx-0x10]
in assembly, where ecx
is used as the base value for the GOT. But if this is the case, then it is obvious that no matter which process calls that line, it will always access the same global variable whose address is at offset 0x10 in the GOT. So how can two processes have different copies of global variable, if they use the same text section that references the same GOT entry?