<div dir="ltr">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.</div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Mar 4, 2016 at 2:55 AM, Simon Atanasyan via llvm-commits <span dir="ltr"><<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: atanasyan<br>
Date: Fri Mar  4 04:55:24 2016<br>
New Revision: 262707<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=262707&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=262707&view=rev</a><br>
Log:<br>
[ELF][MIPS] Factor out the code writing relocation result into low 16-bit of destination. NFC<br>
<br>
Modified:<br>
    lld/trunk/ELF/Target.cpp<br>
<br>
Modified: lld/trunk/ELF/Target.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Target.cpp?rev=262707&r1=262706&r2=262707&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Target.cpp?rev=262707&r1=262706&r2=262707&view=diff</a><br>
==============================================================================<br>
--- lld/trunk/ELF/Target.cpp (original)<br>
+++ lld/trunk/ELF/Target.cpp Fri Mar  4 04:55:24 2016<br>
@@ -1647,6 +1647,12 @@ static void writeMipsHi16(uint8_t *Loc,<br>
 }<br>
<br>
 template <endianness E><br>
+static void writeMipsLo16(uint8_t *Loc, uint64_t V) {<br>
+  uint32_t Instr = read32<E>(Loc);<br>
+  write32<E>(Loc, (Instr & 0xffff0000) | (V & 0xffff));<br>
+}<br>
+<br>
+template <endianness E><br>
 static int64_t readMipsAHL(uint8_t *HiLoc, uint8_t *LoLoc) {<br>
   return ((read32<E>(HiLoc) & 0xffff) << 16) +<br>
          SignExtend64<16>(read32<E>(LoLoc) & 0xffff);<br>
@@ -1664,10 +1670,9 @@ void MipsTargetInfo<ELFT>::writePltZero(<br>
   write32<E>(Buf + 24, 0x0320f809); // jalr  $25<br>
   write32<E>(Buf + 28, 0x2718fffe); // subu  $24, $24, 2<br>
   uint64_t Got = Out<ELFT>::GotPlt->getVA();<br>
-  uint64_t Plt = Out<ELFT>::Plt->getVA();<br>
   writeMipsHi16<E>(Buf, Got);<br>
-  relocateOne(Buf + 4, Buf + 8, R_MIPS_LO16, Plt + 4, Got);<br>
-  relocateOne(Buf + 8, Buf + 12, R_MIPS_LO16, Plt + 8, Got);<br>
+  writeMipsLo16<E>(Buf + 4, Got);<br>
+  writeMipsLo16<E>(Buf + 8, Got);<br>
 }<br>
<br>
 template <class ELFT><br>
@@ -1680,8 +1685,8 @@ void MipsTargetInfo<ELFT>::writePlt(uint<br>
   write32<E>(Buf + 8, 0x03200008);  // jr    $25<br>
   write32<E>(Buf + 12, 0x25f80000); // addiu $24, $15, %lo(.got.plt entry)<br>
   writeMipsHi16<E>(Buf, GotEntryAddr);<br>
-  relocateOne(Buf + 4, Buf + 8, R_MIPS_LO16, PltEntryAddr + 4, GotEntryAddr);<br>
-  relocateOne(Buf + 12, Buf + 16, R_MIPS_LO16, PltEntryAddr + 8, GotEntryAddr);<br>
+  writeMipsLo16<E>(Buf + 4, GotEntryAddr);<br>
+  writeMipsLo16<E>(Buf + 12, GotEntryAddr);<br>
 }<br>
<br>
 template <class ELFT><br>
@@ -1727,14 +1732,14 @@ void MipsTargetInfo<ELFT>::relocateOne(u<br>
     int64_t V = S - getMipsGpAddr<ELFT>();<br>
     if (Type == R_MIPS_GOT16)<br>
       checkInt<16>(V, Type);<br>
-    write32<E>(Loc, (read32<E>(Loc) & 0xffff0000) | (V & 0xffff));<br>
+    writeMipsLo16<E>(Loc, V);<br>
     break;<br>
   }<br>
   case R_MIPS_GPREL16: {<br>
     uint32_t Instr = read32<E>(Loc);<br>
     int64_t V = S + SignExtend64<16>(Instr & 0xffff) - getMipsGpAddr<ELFT>();<br>
     checkInt<16>(V, Type);<br>
-    write32<E>(Loc, (Instr & 0xffff0000) | (V & 0xffff));<br>
+    writeMipsLo16<E>(Loc, V);<br>
     break;<br>
   }<br>
   case R_MIPS_GPREL32:<br>
@@ -1751,12 +1756,9 @@ void MipsTargetInfo<ELFT>::relocateOne(u<br>
   case R_MIPS_JALR:<br>
     // Ignore this optimization relocation for now<br>
     break;<br>
-  case R_MIPS_LO16: {<br>
-    uint32_t Instr = read32<E>(Loc);<br>
-    int64_t AHL = SignExtend64<16>(Instr & 0xffff);<br>
-    write32<E>(Loc, (Instr & 0xffff0000) | ((S + AHL) & 0xffff));<br>
+  case R_MIPS_LO16:<br>
+    writeMipsLo16<E>(Loc, S + SignExtend64<16>(read32<E>(Loc) & 0xffff));<br>
     break;<br>
-  }<br>
   case R_MIPS_PC16:<br>
     applyMipsPcReloc<E, 16, 2>(Loc, Type, P, S);<br>
     break;<br>
@@ -1780,12 +1782,9 @@ void MipsTargetInfo<ELFT>::relocateOne(u<br>
       writeMipsHi16<E>(Loc, S - P);<br>
     }<br>
     break;<br>
-  case R_MIPS_PCLO16: {<br>
-    uint32_t Instr = read32<E>(Loc);<br>
-    int64_t AHL = SignExtend64<16>(Instr & 0xffff);<br>
-    write32<E>(Loc, (Instr & 0xffff0000) | ((S + AHL - P) & 0xffff));<br>
+  case R_MIPS_PCLO16:<br>
+    writeMipsLo16<E>(Loc, S + SignExtend64<16>(read32<E>(Loc) & 0xffff) - P);<br>
     break;<br>
-  }<br>
   default:<br>
     fatal("unrecognized reloc " + Twine(Type));<br>
   }<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a><br>
</blockquote></div><br></div>