Martin Rosenau wrote:
> Hello.
> 
> I already posted my questions to the Sun forums and I was asked to re-post it 
> here:
> 
> I'm developing a simple compiler that should directly write object files. I 
> currently plan to use the standard ELF format so I can use the "ld(1)" linker.
> 
> I want to avoid "copy relocations" so I want to create statements like this:
>   mov (_GLOBAL_OFFSET_TABLE_+myvariable at GOT),%eax
> 
> instead of:
>   lea myvariable,%eax
> 
> Of course I could do:
>   mov $_GLOBAL_OFFSET_TABLE_,%eax
>   mov myvariable at GOT(%eax),%eax
> 
> but this would be less efficient!
> 
> Is there any way to do this?
> I could do that if I could apply two relocations (R_386_32 and R_386_GOT) to 
> the same address. Does the linker allow this? (Simply trying out is not a 
> good idea because I know that there are different versions of "ld" so I will 
> not be sure if all versions will behave the same way.)

The linker would happily apply two relocations to the same offset, but
there's a catch.  REL relocations apply any addend by depositing the
addend in the offset.  The relocation takes the contents of the offset,
uses this content as part of the relocation calculation, and then
writes the result back into the offset.  If you have two relocations
against the same offset, they're going to get in trouble dealing with
an addend (or the contents of the offset from the first relocation).

I don't believe ld(1) has any checks against such a scenario either -
might be hard to debug.

You can avoid copy relocations (a very admiral goal) by using PIC references
to external data.  These would result in the two instruction GOT reference.

Better yet would be to encourage users not to reference external data in the
first place.  Any reference makes the size of the data become part of the
interface which can restrict future data size changes.  Obtaining data through
functional interfaces is more flexible.

-- 

Rod.

Reply via email to