This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: Puzzle:Is addend ok when handling relocations in linking mips32-elf
Hi :
Thanks for your reply.
On Tue, Mar 10, 2009 at 7:26 AM, Alan Modra <amodra@bigpond.net.au> wrote:
> On Mon, Mar 09, 2009 at 07:11:45PM +0800, Amker.Cheng wrote:
>> here comes the problem, If i have a howto structure with nonzero bitpos,
>> I think addend will be wrong and should be right shift with howto->bitpos.
>
> Left shift actually. ?reloc.c:bfd_perform_relocation shows what should
> be done.
Well, I think there is a little difference between
bfd_perform_relocation & _bfd_mips_elf_relocate_section,
given a reloc entry "relent" and a 4 bytes relocation target
instruction "insn" which
including in place "addend", They do do the same thing: calculate
relocation adjustment
from "relent" and in place "addend". in a slightly different way as
described below.
1 : for bfd_perform_relocation
It first calculates relocation from "relent" and then do:
relocation >>= (bfd_vma) howto->rightshift;
relocation <<= (bfd_vma) howto->bitpos;
at last adds the relocation with in place "addend", puts the result
back to "insn".
2 : for _bfd_mips_elf_relocate_section
It first retrieves in place "addend" from the "insn" using follow codes
addend = mips_elf_obtain_contents (...)
addend &= howto->src_mask;
addend <<= howto->rightshift;
/*I think addend need to be $right$ shift by howto->bitpos,
because it is calculated from in place "addend", which was
left shift by then assembler or relocatable linker before.
*/
then it uses the retrieved "addend" and the supplied "relent" to
calculate the result and
puts the result back into "insn" like:
result = "value of relent" + "addend" /*in func mips_elf_calculate_relocation*/
/*need do "result<<howto->bitpos" if howto->bitpos nonzero */
insn &= howto->dst_mask;
insn |= (value & howto->dst_mask); /*in func mips_elf_perform_relocation*/
-------------------------------cut here
Anyway, relocation types with non howto->bitpos are not supported currently,
so it's ok now.
Here is all my understanding, please point it out if wrong. any reply
will be appreciated.
Thanks.
Regards.