[lld] r360187 - [mips] Fix ld instruction in PLT entries on MIPS64

Simon Atanasyan via llvm-commits llvm-commits at lists.llvm.org
Tue May 7 13:26:23 PDT 2019


Author: atanasyan
Date: Tue May  7 13:26:23 2019
New Revision: 360187

URL: http://llvm.org/viewvc/llvm-project?rev=360187&view=rev
Log:
[mips] Fix ld instruction in PLT entries on MIPS64

Use `ld` and `daddiu` instructions in MIPS64 PLT records. That fixes a
segmentation fault.

Patch by Qiao Pengcheng.

Differential Revision: https://reviews.llvm.org/D61586

Modified:
    lld/trunk/ELF/Arch/Mips.cpp
    lld/trunk/test/ELF/mips-plt-n64.s

Modified: lld/trunk/ELF/Arch/Mips.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Arch/Mips.cpp?rev=360187&r1=360186&r2=360187&view=diff
==============================================================================
--- lld/trunk/ELF/Arch/Mips.cpp (original)
+++ lld/trunk/ELF/Arch/Mips.cpp Tue May  7 13:26:23 2019
@@ -327,13 +327,15 @@ void MIPS<ELFT>::writePlt(uint8_t *Buf,
     return;
   }
 
+  uint32_t LoadInst = ELFT::Is64Bits ? 0xddf90000 : 0x8df90000;
   uint32_t JrInst = isMipsR6() ? (Config->ZHazardplt ? 0x03200409 : 0x03200009)
                                : (Config->ZHazardplt ? 0x03200408 : 0x03200008);
+  uint32_t AddInst = ELFT::Is64Bits ? 0x65f80000 : 0x25f80000;
 
   write32<E>(Buf, 0x3c0f0000);     // lui   $15, %hi(.got.plt entry)
-  write32<E>(Buf + 4, 0x8df90000); // l[wd] $25, %lo(.got.plt entry)($15)
+  write32<E>(Buf + 4, LoadInst);   // l[wd] $25, %lo(.got.plt entry)($15)
   write32<E>(Buf + 8, JrInst);     // jr  $25 / jr.hb $25
-  write32<E>(Buf + 12, 0x25f80000); // addiu $24, $15, %lo(.got.plt entry)
+  write32<E>(Buf + 12, AddInst);   // [d]addiu $24, $15, %lo(.got.plt entry)
   writeValue<E>(Buf, GotPltEntryAddr + 0x8000, 16, 16);
   writeValue<E>(Buf + 4, GotPltEntryAddr, 16, 0);
   writeValue<E>(Buf + 12, GotPltEntryAddr, 16, 0);

Modified: lld/trunk/test/ELF/mips-plt-n64.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/mips-plt-n64.s?rev=360187&r1=360186&r2=360187&view=diff
==============================================================================
--- lld/trunk/test/ELF/mips-plt-n64.s (original)
+++ lld/trunk/test/ELF/mips-plt-n64.s Tue May  7 13:26:23 2019
@@ -11,7 +11,6 @@
 # RUN: ld.lld %t.o %t.so -o %t.exe -z hazardplt
 # RUN: llvm-objdump -d %t.exe | FileCheck %s --check-prefixes=CHECK,HAZARDPLT
 
-
 # CHECK:      Disassembly of section .text:
 # CHECK-EMPTY:
 # CHECK-NEXT: __start:
@@ -31,10 +30,10 @@
 # HAZARDPLT:     20028:       03 20 fc 09     jalr.hb $25
 # CHECK-NEXT:    2002c:       27 18 ff fe     addiu   $24, $24, -2
 # CHECK-NEXT:    20030:       3c 0f 00 03     lui     $15, 3
-# CHECK-NEXT:    20034:       8d f9 00 18     lw      $25, 24($15)
+# CHECK-NEXT:    20034:       dd f9 00 18     ld      $25, 24($15)
 # DEFAULT:       20038:       03 20 00 08     jr      $25
 # HAZARDPLT:     20038:       03 20 04 08     jr.hb   $25
-# CHECK-NEXT:    2003c:       25 f8 00 18     addiu   $24, $15, 24
+# CHECK-NEXT:    2003c:       65 f8 00 18     daddiu  $24, $15, 24
 
   .text
   .option pic0




More information about the llvm-commits mailing list