<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Sat, Dec 12, 2015 at 10:49 PM, 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: Sun Dec 13 00:49:01 2015<br>
New Revision: 255451<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=255451&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=255451&view=rev</a><br>
Log:<br>
[ELF][MIPS] Fix calculation of the R_MIPS_HI16 relocation<br>
<br>
Modified:<br>
    lld/trunk/ELF/Target.cpp<br>
    lld/trunk/test/ELF/mips-hilo.s<br>
<br>
Modified: lld/trunk/ELF/Target.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Target.cpp?rev=255451&r1=255450&r2=255451&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Target.cpp?rev=255451&r1=255450&r2=255451&view=diff</a><br>
==============================================================================<br>
--- lld/trunk/ELF/Target.cpp (original)<br>
+++ lld/trunk/ELF/Target.cpp Sun Dec 13 00:49:01 2015<br>
@@ -1287,6 +1287,8 @@ bool MipsTargetInfo<ELFT>::relocNeedsPlt<br>
   return false;<br>
 }<br>
<br>
+static uint16_t mipsHigh(uint64_t V) { return ((V + 0x8000) >> 16) & 0xffff; }<br></blockquote><div><br></div><div>You don't need &0xffff since this function returns a uint16_t value.</div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+<br>
 template <class ELFT><br>
 void MipsTargetInfo<ELFT>::relocateOne(uint8_t *Loc, uint8_t *BufEnd,<br>
                                        uint32_t Type, uint64_t P, uint64_t SA,<br>
@@ -1309,10 +1311,10 @@ void MipsTargetInfo<ELFT>::relocateOne(u<br>
     if (PairedLoc) {<br>
       uint64_t AHL = ((Instr & 0xffff) << 16) +<br>
                      SignExtend64<16>(read32<E>(PairedLoc) & 0xffff);<br>
-      write32<E>(Loc, (Instr & 0xffff0000) | (((SA + AHL) >> 16) & 0xffff));<br>
+      write32<E>(Loc, (Instr & 0xffff0000) | mipsHigh(SA + AHL));<br>
     } else {<br>
       warning("Can't find matching R_MIPS_LO16 relocation for R_MIPS_HI16");<br>
-      write32<E>(Loc, (Instr & 0xffff0000) | ((SA >> 16) & 0xffff));<br>
+      write32<E>(Loc, (Instr & 0xffff0000) | mipsHigh(SA));<br>
     }<br>
     break;<br>
   }<br>
<br>
Modified: lld/trunk/test/ELF/mips-hilo.s<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/mips-hilo.s?rev=255451&r1=255450&r2=255451&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/mips-hilo.s?rev=255451&r1=255450&r2=255451&view=diff</a><br>
==============================================================================<br>
--- lld/trunk/test/ELF/mips-hilo.s (original)<br>
+++ lld/trunk/test/ELF/mips-hilo.s Sun Dec 13 00:49:01 2015<br>
@@ -40,9 +40,9 @@ g1:<br>
 #                                                    ^-- %lo(__start+4)<br>
 # CHECK-NEXT:  2000c:   21 08 00 0c   addi   $8, $8, 12<br>
 #                                                    ^-- %lo(g1+8)<br>
-# CHECK-NEXT:  20010:   3c 08 00 03   lui    $8, 3<br>
+# CHECK-NEXT:  20010:   3c 08 00 04   lui    $8, 4<br>
 #                                                ^-- %hi(l1+0x10000-4)<br>
-# CHECK-NEXT:  20014:   3c 09 00 04   lui    $9, 4<br>
+# CHECK-NEXT:  20014:   3c 09 00 05   lui    $9, 5<br>
 #                                                ^-- %hi(l1+0x20000-4)<br>
 # CHECK-NEXT:  20018:   21 08 ff fc   addi   $8, $8, -4<br>
 #                                                    ^-- %lo(l1-4)<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></div>