ELF32 relocation for R_386_PC32 entries
Posted: Thu Nov 20, 2014 8:11 pm
Hey guys,
I'm finishing the implementation of my ELF32 loader. Currently I'm testing everything on GNU/Linux with GCC. My tests consists of load an ELF32 library, look for a specific function and call it.
My loader already supports R_386_32, R_386_PC32, R_386_GLOB_DAT and R_386_JMP_SLOT relocation types, but I have a problem with R_386_PC32 when relocating an external function (e.g. some libc function).
When compiling some shared library, I got a relocation table like this:
For the function dummy it's easy: I take the value at the offset in the entry, add the address of the symbol to it (base address of the library in memory + Sym.Value) and subtract the address of the offset. But for an external function, like printf, I can't do that because I don't have the Sym.Value. I mean, I tried to replace "the address of the symbol" by the return of the dlsym function, by it crashes.
What could I do to relocate that symbols?
I'm finishing the implementation of my ELF32 loader. Currently I'm testing everything on GNU/Linux with GCC. My tests consists of load an ELF32 library, look for a specific function and call it.
My loader already supports R_386_32, R_386_PC32, R_386_GLOB_DAT and R_386_JMP_SLOT relocation types, but I have a problem with R_386_PC32 when relocating an external function (e.g. some libc function).
When compiling some shared library, I got a relocation table like this:
Code: Select all
Offset Info Type Sym.Value Sym. Name
000005d2 00000702 R_386_PC32 000005a0 dummy
000005e8 00000202 R_386_PC32 00000000 printf
What could I do to relocate that symbols?