Not understanding R_X86_64_COPY

Discussions on more advanced topics such as monolithic vs micro-kernels, transactional memory models, and paging vs segmentation should go here. Use this forum to expand and improve the wiki!
Post Reply
mariuszp
Member
Member
Posts: 587
Joined: Sat Oct 16, 2010 3:38 pm

Not understanding R_X86_64_COPY

Post by mariuszp »

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?
jnc100
Member
Member
Posts: 775
Joined: Mon Apr 09, 2007 12:10 pm
Location: London, UK
Contact:

Re: Not understanding R_X86_64_COPY

Post by jnc100 »

The library uses the application's copy of the data (via GLOB_DAT relocations in the library). See here for an overview.

Regards,
John.
rianquinn
Posts: 16
Joined: Thu Jan 21, 2010 9:31 pm

Re: Not understanding R_X86_64_COPY

Post by rianquinn »

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
Post Reply