This is the mail archive of the binutils@sources.redhat.com mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: REL vs. RELA: how to choose?


> From: "Ray Donnelly" <raydonnelly@chorltonhome.freeserve.co.uk>
> Date: Thu, 15 Feb 2001 02:37:15 -0800

> Aren't addends stored with the rightshift shifted off them? I mean, what's
> the point in having a rela relocation record for an insn that can't hold the
> total offset as there isn't space in the bitfield? Note, I'm quite new to
> this and so could be missing things - like facts!

Consider MIPS, which mistakenly chose REL instead of RELA.  To load a
32-bit constant into registers on MIPS, you use two instructions, one
which loads a sign-extended 16-bit value into a register and one that
adds a 16-bit value to the top 16 bits.  (Or perhaps the other way
around, it doesn't matter.)

So, suppose the symbol 'foo' has value 0x80000000, and you want to
load foo+0x8000 into a register.  The sequence of instructions is

     load 0x8000        which loads 0xffff8000
     add  0x8001	which adds  0x80010000

and you have relocs for each insn, you have a 'LO' reloc that means
'the low 16 bits of S+A', and a 'HA' reloc, which means 'the high 16
bits of S+A+0x8000'; in this case S is 'foo'==0x80000000, and 'A' is
0x8000.

You were suggesting that the HA reloc needs only the top 16 bits of
the addend `A'.  But all those bits are zero.  In fact, if you think
about it, you can see that the HA reloc needs 17 bits of the addend,
and since there's only 16 bits in the instruction you are stuck.

This actually happens on MIPS, and the only reason it doesn't cause
more trouble is that almost all addends are zero.

-- 
- Geoffrey Keating <geoffk@geoffk.org>


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]