why do we need reloc_offset ??

2 messages, 2 authors, 2009-09-03 · open the first message on its own page

why do we need reloc_offset ??

From: HongWoo Lee <hidden>
Date: 2009-09-02 06:33:54

Hi everyone~

In ther linux kernel code, I found the reloc_offset.

{{{
// file : misc.S
/* Returns (address we are running at) - (address we were linked at)
 * for use before the text and data are mapped to KERNELBASE.
 */
_GLOBAL(reloc_offset)
}}}

I couldn't understand the comment saying "Returns (address we are running
at) - (address we were linked at)".
For now, I'm studying each instruction.

And below is best comment I can explain for each instruction.

_GLOBAL(reloc_offset)
        mflr    r0                // move from link register, save the
return address
        bl      1f                 // bl 1f
1:     mflr    r3                // move from link register, r3 is just
return address pointing itself
        LOAD_REG_IMMEDIATE(r4,1b)    // get the 1b address, r4 is the
address
        subf    r3,r4,r3        // r3 = r3 – r4
        mtlr    r0                // restore return address
        blr

After this, I still don't know why "r3-r4" is the offset.
And what does it mean ??

Please explain to me the reason why we need reloc_offset and the code.
Or let me know any helpful reference about this.

Thank in advance.

HongWoo.

Re: why do we need reloc_offset ??

From: Michael Ellerman <hidden>
Date: 2009-09-03 02:19:49

On Wed, 2009-09-02 at 15:33 +0900, HongWoo Lee wrote:
Hi everyone~ 

In ther linux kernel code, I found the reloc_offset. 

{{{
// file : misc.S 
/* Returns (address we are running at) - (address we were linked at)
 * for use before the text and data are mapped to KERNELBASE.
 */
_GLOBAL(reloc_offset)
}}}

I couldn't understand the comment saying "Returns (address we are
running at) - (address we were linked at)". 
For now, I'm studying each instruction. 

And below is best comment I can explain for each instruction. 

_GLOBAL(reloc_offset)
        mflr    r0                // move from link register, save the return address
        bl      1f                 // bl 1f
1:     mflr    r3                // move from link register, r3 is just return address pointing itself 
At this point r3 contains the value of LR based on the branch we just
did. So it's the address of the current instruction, based on where the
code is _running_.
        LOAD_REG_IMMEDIATE(r4,1b)    // get the 1b address, r4 is the address 
Here we load into r4 the address of the previous instruction, but based
on the label "1b". The address of the label is calculated by the linker,
so r4 contains the address the instruction was linked at.
        subf    r3,r4,r3        // r3 = r3 – r4 
So here we calculate any difference between the address the code was
linked at and the address it's running at.
        mtlr    r0                // restore return address 
        blr

After this, I still don't know why "r3-r4" is the offset. 
And what does it mean ?? 
The offset is just the difference between the address the code was
linked at and the address it's running it. It's used in places where the
code might be (or is always) running at an address other than the
address it was linked at.

cheers
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help