[MIPS] Setup less-significant bit in a symbol value in microMIPS thunks
authorSimon Atanasyan <simon@atanasyan.com>
Thu, 9 Nov 2017 10:42:22 +0000 (10:42 +0000)
committerSimon Atanasyan <simon@atanasyan.com>
Thu, 9 Nov 2017 10:42:22 +0000 (10:42 +0000)
The less-significant bit signals about microMIPS code for jump/branch instructions.

llvm-svn: 317778

lld/ELF/Thunks.cpp
lld/test/ELF/mips-micro-thunks.s

index c87070d..81b5a3b 100644 (file)
@@ -258,7 +258,7 @@ InputSection *MipsThunk::getTargetInputSection() const {
 // Write microMIPS R2-R5 LA25 thunk code
 // to call PIC function from the non-PIC one.
 void MicroMipsThunk::writeTo(uint8_t *Buf, ThunkSection &) const {
-  uint64_t S = Destination.getVA();
+  uint64_t S = Destination.getVA() | 1;
   write16(Buf, 0x41b9, Config->Endianness);       // lui   $25, %hi(func)
   write16(Buf + 4, 0xd400, Config->Endianness);   // j     func
   write16(Buf + 8, 0x3339, Config->Endianness);   // addiu $25, $25, %lo(func)
@@ -283,7 +283,7 @@ InputSection *MicroMipsThunk::getTargetInputSection() const {
 // Write microMIPS R6 LA25 thunk code
 // to call PIC function from the non-PIC one.
 void MicroMipsR6Thunk::writeTo(uint8_t *Buf, ThunkSection &) const {
-  uint64_t S = Destination.getVA();
+  uint64_t S = Destination.getVA() | 1;
   uint64_t P = ThunkSym->getVA();
   write16(Buf, 0x1320, Config->Endianness);       // lui   $25, %hi(func)
   write16(Buf + 4, 0x3339, Config->Endianness);   // addiu $25, $25, %lo(func)
index d536ae3..18a8fc3 100644 (file)
@@ -27,7 +27,7 @@
 # EB: __microLA25Thunk_foo:
 # EB-NEXT:    20008:       41 b9 00 02     lui     $25, 2
 # EB-NEXT:    2000c:       d4 01 00 10     j       131104
-# EB-NEXT:    20010:       33 39 00 20     addiu   $25, $25, 32
+# EB-NEXT:    20010:       33 39 00 21     addiu   $25, $25, 33
 # EB-NEXT:    20014:       0c 00           nop
 
 # EL: __start:
@@ -37,7 +37,7 @@
 # EL: __microLA25Thunk_foo:
 # EL-NEXT:    20008:       b9 41 02 00     lui     $25, 2
 # EL-NEXT:    2000c:       01 d4 10 00     j       131104
-# EL-NEXT:    20010:       39 33 20 00     addiu   $25, $25, 32
+# EL-NEXT:    20010:       39 33 21 00     addiu   $25, $25, 33
 # EL-NEXT:    20014:       00 0c           nop
 
   .text