_bfd_mips_elf_reloc_unshuffle (abfd, reloc_entry->howto->type, false,
location);
- vallo = bfd_get_32 (abfd, location);
+ /* The high 16 bits of the addend are stored in the high insn, the
+ low 16 bits in the low insn, but there is a catch: You can't
+ just concatenate the high and low parts. The high part of the
+ addend is adjusted for the fact that the low part is sign
+ extended. For example, an addend of 0x38000 would have 0x0004 in
+ the high part and 0x8000 (=0xff..f8000) in the low part.
+ To extract the actual addend, calculate (a)
+ ((hi & 0xffff) << 16) + ((lo & 0xffff) ^ 0x8000) - 0x8000.
+ We will be applying (symbol + addend) & 0xffff to the low insn,
+ and we want to apply (b) (symbol + addend + 0x8000) >> 16 to the
+ high insn (the +0x8000 adjusting for when the applied low part is
+ negative). Substituting (a) into (b) and recognising that
+ (hi & 0xffff) is already in the high insn gives a high part
+ addend adjustment of (lo & 0xffff) ^ 0x8000. */
+ vallo = (bfd_get_32 (abfd, location) & 0xffff) ^ 0x8000;
_bfd_mips_elf_reloc_shuffle (abfd, reloc_entry->howto->type, false,
location);
else if (hi->rel.howto->type == R_MICROMIPS_GOT16)
hi->rel.howto = MIPS_ELF_RTYPE_TO_HOWTO (abfd, R_MICROMIPS_HI16, false);
- /* VALLO is a signed 16-bit number. Bias it by 0x8000 so that any
- carry or borrow will induce a change of +1 or -1 in the high part. */
- hi->rel.addend += (vallo + 0x8000) & 0xffff;
+ hi->rel.addend += vallo;
ret = _bfd_mips_elf_generic_reloc (abfd, &hi->rel, symbol, hi->data,
hi->input_section, output_bfd,