[lld] r262707 - [ELF][MIPS] Factor out the code writing relocation result into low 16-bit of destination. NFC

Rui Ueyama via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 4 11:30:32 PST 2016


Thank you for all these cleanups. Particularly this is a good one as
calling relocateOne was too a bit much. It's now nice and clean.

On Fri, Mar 4, 2016 at 2:55 AM, Simon Atanasyan via llvm-commits <
llvm-commits at lists.llvm.org> wrote:

> Author: atanasyan
> Date: Fri Mar  4 04:55:24 2016
> New Revision: 262707
>
> URL: http://llvm.org/viewvc/llvm-project?rev=262707&view=rev
> Log:
> [ELF][MIPS] Factor out the code writing relocation result into low 16-bit
> of destination. NFC
>
> Modified:
>     lld/trunk/ELF/Target.cpp
>
> Modified: lld/trunk/ELF/Target.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Target.cpp?rev=262707&r1=262706&r2=262707&view=diff
>
> ==============================================================================
> --- lld/trunk/ELF/Target.cpp (original)
> +++ lld/trunk/ELF/Target.cpp Fri Mar  4 04:55:24 2016
> @@ -1647,6 +1647,12 @@ static void writeMipsHi16(uint8_t *Loc,
>  }
>
>  template <endianness E>
> +static void writeMipsLo16(uint8_t *Loc, uint64_t V) {
> +  uint32_t Instr = read32<E>(Loc);
> +  write32<E>(Loc, (Instr & 0xffff0000) | (V & 0xffff));
> +}
> +
> +template <endianness E>
>  static int64_t readMipsAHL(uint8_t *HiLoc, uint8_t *LoLoc) {
>    return ((read32<E>(HiLoc) & 0xffff) << 16) +
>           SignExtend64<16>(read32<E>(LoLoc) & 0xffff);
> @@ -1664,10 +1670,9 @@ void MipsTargetInfo<ELFT>::writePltZero(
>    write32<E>(Buf + 24, 0x0320f809); // jalr  $25
>    write32<E>(Buf + 28, 0x2718fffe); // subu  $24, $24, 2
>    uint64_t Got = Out<ELFT>::GotPlt->getVA();
> -  uint64_t Plt = Out<ELFT>::Plt->getVA();
>    writeMipsHi16<E>(Buf, Got);
> -  relocateOne(Buf + 4, Buf + 8, R_MIPS_LO16, Plt + 4, Got);
> -  relocateOne(Buf + 8, Buf + 12, R_MIPS_LO16, Plt + 8, Got);
> +  writeMipsLo16<E>(Buf + 4, Got);
> +  writeMipsLo16<E>(Buf + 8, Got);
>  }
>
>  template <class ELFT>
> @@ -1680,8 +1685,8 @@ void MipsTargetInfo<ELFT>::writePlt(uint
>    write32<E>(Buf + 8, 0x03200008);  // jr    $25
>    write32<E>(Buf + 12, 0x25f80000); // addiu $24, $15, %lo(.got.plt entry)
>    writeMipsHi16<E>(Buf, GotEntryAddr);
> -  relocateOne(Buf + 4, Buf + 8, R_MIPS_LO16, PltEntryAddr + 4,
> GotEntryAddr);
> -  relocateOne(Buf + 12, Buf + 16, R_MIPS_LO16, PltEntryAddr + 8,
> GotEntryAddr);
> +  writeMipsLo16<E>(Buf + 4, GotEntryAddr);
> +  writeMipsLo16<E>(Buf + 12, GotEntryAddr);
>  }
>
>  template <class ELFT>
> @@ -1727,14 +1732,14 @@ void MipsTargetInfo<ELFT>::relocateOne(u
>      int64_t V = S - getMipsGpAddr<ELFT>();
>      if (Type == R_MIPS_GOT16)
>        checkInt<16>(V, Type);
> -    write32<E>(Loc, (read32<E>(Loc) & 0xffff0000) | (V & 0xffff));
> +    writeMipsLo16<E>(Loc, V);
>      break;
>    }
>    case R_MIPS_GPREL16: {
>      uint32_t Instr = read32<E>(Loc);
>      int64_t V = S + SignExtend64<16>(Instr & 0xffff) -
> getMipsGpAddr<ELFT>();
>      checkInt<16>(V, Type);
> -    write32<E>(Loc, (Instr & 0xffff0000) | (V & 0xffff));
> +    writeMipsLo16<E>(Loc, V);
>      break;
>    }
>    case R_MIPS_GPREL32:
> @@ -1751,12 +1756,9 @@ void MipsTargetInfo<ELFT>::relocateOne(u
>    case R_MIPS_JALR:
>      // Ignore this optimization relocation for now
>      break;
> -  case R_MIPS_LO16: {
> -    uint32_t Instr = read32<E>(Loc);
> -    int64_t AHL = SignExtend64<16>(Instr & 0xffff);
> -    write32<E>(Loc, (Instr & 0xffff0000) | ((S + AHL) & 0xffff));
> +  case R_MIPS_LO16:
> +    writeMipsLo16<E>(Loc, S + SignExtend64<16>(read32<E>(Loc) & 0xffff));
>      break;
> -  }
>    case R_MIPS_PC16:
>      applyMipsPcReloc<E, 16, 2>(Loc, Type, P, S);
>      break;
> @@ -1780,12 +1782,9 @@ void MipsTargetInfo<ELFT>::relocateOne(u
>        writeMipsHi16<E>(Loc, S - P);
>      }
>      break;
> -  case R_MIPS_PCLO16: {
> -    uint32_t Instr = read32<E>(Loc);
> -    int64_t AHL = SignExtend64<16>(Instr & 0xffff);
> -    write32<E>(Loc, (Instr & 0xffff0000) | ((S + AHL - P) & 0xffff));
> +  case R_MIPS_PCLO16:
> +    writeMipsLo16<E>(Loc, S + SignExtend64<16>(read32<E>(Loc) & 0xffff) -
> P);
>      break;
> -  }
>    default:
>      fatal("unrecognized reloc " + Twine(Type));
>    }
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160304/dbc8c548/attachment.html>


More information about the llvm-commits mailing list