I'm trying to implement dynamic library loading in my OS. Currently I handle 4 types of relocations: R_X86_64_64, R_X86_64_JUMP_SLOT, R_X86_64_RELATIVE and R_X86_64_GLOB_DAT. They relocate without problems. I understand I don't need to handle all types of relocations as they don't all appear in dynamic relocation tables... or am I wrong?
The other type of relocation I'm seeing if an executable references an "extern" variable is R_X86_64_COPY. I understand that I have to copy the symbol with the specified name from a library (according to r_offset, st_name and st_size?) but this does not really make sense to me. If the executable modifies the value of this variable the library wouldn't be able to see that change, because it has its own copy.
Or am I misunderstanding something here?
Not understanding R_X86_64_COPY
Re: Not understanding R_X86_64_COPY
The library uses the application's copy of the data (via GLOB_DAT relocations in the library). See here for an overview.
Regards,
John.
Regards,
John.
Re: Not understanding R_X86_64_COPY
Just implemented R_X86_64_GLOB_DAT and R_X86_64_JUMP_SLOT relocations and they are working great. I ended up doing the same thing where the calculation is really B + S, and not S like you see in the docs. Any idea why the docs state to simply store the st_value as the relocation, but in reality you need to add the lib_base_vaddr + sym->st_value.
It's incredibly misleading.
Thanks,
- Rian
It's incredibly misleading.
Thanks,
- Rian