Shared library position
Posted: Thu Jul 31, 2008 5:45 am
Hello,
I'm trying to implement ELF shared library support, and shared library support in general
As I am not a native english speeker, it was very difficult for me to understand the ELF specifications (for example it took me a few days even to understand that sections and segments were not the same thing )
Let me introduce my problem:
Let's say program A requires lib1 wich requires lib2
Program A is loaded at address 0x8000000, lib1 at address 0x90000000 and lib2 at address 0xA0000000
So everything is mapped in the same virtual memory and we start relocalisation:
Let's say that a function call in lib1 at address 0x9000002c requires a function found in lib2 at offset 0xA0000100
So we simply write "0xA0000100" at address 0x9000002c
Now let's start program B which also requires lib1 (and thus lib2)
Program B is loaded at address 0x9000000, and thus lib1 at 0xA0000000 and lib2 at 0xB0000000
The problem is : As lib1 shares the same physical memory in virtual memories A and B, its offset 0x2c cannot point at the same time to addresses 0xA0000100 and 0xB0000100
I don't think I was clear but this problem must be quite simple and common despite the fact that I didn't find any solution neither in the wiki nor in this forum
Of course you could answer "you just have to load program B at 0x80000000" or "load lib1 at 0xB0000000 and lib2 at 0xA0000000" but that may not always be possible when there are multiple dependencies
I have also been reading PE specifications but it seems to work the same way as ELF
I'm trying to implement ELF shared library support, and shared library support in general
As I am not a native english speeker, it was very difficult for me to understand the ELF specifications (for example it took me a few days even to understand that sections and segments were not the same thing )
Let me introduce my problem:
Let's say program A requires lib1 wich requires lib2
Program A is loaded at address 0x8000000, lib1 at address 0x90000000 and lib2 at address 0xA0000000
So everything is mapped in the same virtual memory and we start relocalisation:
Let's say that a function call in lib1 at address 0x9000002c requires a function found in lib2 at offset 0xA0000100
So we simply write "0xA0000100" at address 0x9000002c
Now let's start program B which also requires lib1 (and thus lib2)
Program B is loaded at address 0x9000000, and thus lib1 at 0xA0000000 and lib2 at 0xB0000000
The problem is : As lib1 shares the same physical memory in virtual memories A and B, its offset 0x2c cannot point at the same time to addresses 0xA0000100 and 0xB0000100
I don't think I was clear but this problem must be quite simple and common despite the fact that I didn't find any solution neither in the wiki nor in this forum
Of course you could answer "you just have to load program B at 0x80000000" or "load lib1 at 0xB0000000 and lib2 at 0xA0000000" but that may not always be possible when there are multiple dependencies
I have also been reading PE specifications but it seems to work the same way as ELF