Re: R_386_RELATIVE relocation type. what is it for?



On Nov 5, 11:31 pm, Pawel <paulin...@xxxxxxxxx> wrote:
Hallo group readers!

I am trying to understand why R_386_RELATIVE relocation type is needed
in shared libraries. As I understand PIC code, all references from
.text section of a library to its .data section are based on the fact
that the distance between these two is constant.

eh....are u sure your last statement is correct? my logical thinking
says no, as each section relative to each other's order is fixed, but
the distance in terms of bytes is not fixed, all depends on the
section size specified in the ELF header.

So regardless of
where is .text and .data mapped in process address space, the library
code, knowing the distance to the symbol it wants to use, can just read/write
this data.

Could You please give me some example when R_386_RELATIVE is needed.

From specs:

R_386_RELATIVE
The link editor creates this relocation type for dynamic linking. Its
offset
member gives a location within a shared object that contains a value
representing a relative address. The dynamic linker computes the
corresponding virtual address by adding the virtual address at which
the
shared object was loaded to the relative address. Relocation entries
for this
type must specify 0 for the symbol table index.

My interpretation:
Basically, the problem is that the shared object codes can be loaded
arbitrarily anywhere in memory space. So supposed you issued this:

0x8888: mov eax, 0x123456

where 0x123456 is a virtual address WITHIN THE address space specified
in the shared object - unloaded yet, and 0x8888 is the address of the
instruction. But after loading the shared object, the linker/loader
needs to modify it to:

mov eax, 0x45678

so, how to do that? The address pointing exactly to the starting
bytes of 0x123456 ie 0x8888+1, will have its contents added with the
amount of bytes shifted by the loader - to become 0x45678.

Correct me if I am wrong.

.



Relevant Pages

  • Re: R_386_RELATIVE relocation type. what is it for?
    ... in shared libraries. ... The link editor creates this relocation type for dynamic linking. ... shared object was loaded to the relative address. ... type must specify 0 for the symbol table index. ...
    (comp.os.linux.development.system)
  • RE: Kerberos linking on AIX 6.1
    ... let's say we have a shared object foo.o which is required at link-time for main.c ... Onderwerp: Re: Kerberos linking on AIX 6.1 ... So you will have to archive the shared libraries with ar. ...
    (comp.protocols.kerberos)
  • Re: Removng a handler installed with pthread_atfork
    ... > shared object. ... executable and any number of shared libraries, ... prohibit your clients from dlclosing your library, ... In order to understand recursion you must first understand recursion. ...
    (comp.unix.programmer)
  • Re: malloc crashes on Linux RedHat 9.0
    ... >Compiling without -fPIC can not possibly corrupt heap, ... A non-pic shared object expects to be loaded at ... compiling shared libraries without -fPIC actually works fine ... >on all platforms I know of (though it does produce a shared library ...
    (comp.os.linux.development.apps)
  • Re: Critical section question
    ... not Modify) a shared object? ... Your question doesn't specify any hardware or threading library. ...
    (comp.programming.threads)