1

Are the addresses inside a shared library file virtual addresses, or relocatable addresses?

Does the answer depend on whether the shared library file was built with GCC’s -fPIC option?

Originated from What is the difference between Shared object file and Relocatable file?

1

Processes get a virtual address space. The ELF file specifies a virtual address to load the contents of the section including shared objects into that virtual address space. Those would be virtual addresses.

Sections have relocation tables which point to addresses that are position dependent which get corrected during relocation at load time there are multiple reasons for this but if all addresses in the section can be relocated to the section then its relocatable this is the goal of producing an ELF relocatable file which can than be used as input to create an executable or shared object.

A shared library is a layer up from ELF shared objects and is a function of the operating systems dynamic linker at load time. It will remap the relocated addresses in the processes virtual memory space. So the shared library both has relocatable sections and virtual addresses. Its misleading to call them relocatable addresses because its actually the code section and associated relocation table that make the address relocatable.

GCC -fPIC creates position independent code which eliminates the need for the relocation. Functionally though an ELF relocatable file can have position dependent or independent code in it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.