[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

llvm-svn: 360187
This commit is contained in:
Simon Atanasyan 2019-05-07 20:26:23 +00:00
parent 494b763cfc
commit 3bdb81c26d
2 changed files with 6 additions and 5 deletions

View File

@ -327,13 +327,15 @@ void MIPS<ELFT>::writePlt(uint8_t *Buf, uint64_t GotPltEntryAddr,
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);

View File

@ -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