Index: ELF/Target.cpp =================================================================== --- ELF/Target.cpp +++ ELF/Target.cpp @@ -113,6 +113,7 @@ template class MipsTargetInfo final : public TargetInfo { public: MipsTargetInfo(); + unsigned getGotRefReloc(unsigned Type) const override; void writeGotHeaderEntries(uint8_t *Buf) const override; void writeGotPltEntry(uint8_t *Buf, uint64_t Plt) const override; void writePltZeroEntry(uint8_t *Buf, uint64_t GotEntryAddr, @@ -845,6 +846,11 @@ } template +unsigned MipsTargetInfo::getGotRefReloc(unsigned Type) const { + return Type; +} + +template void MipsTargetInfo::writeGotHeaderEntries(uint8_t *Buf) const { typedef typename llvm::object::ELFFile::Elf_Off Elf_Off; auto *P = reinterpret_cast(Buf); @@ -864,7 +870,7 @@ template bool MipsTargetInfo::relocNeedsGot(uint32_t Type, const SymbolBody &S) const { - return Type == R_MIPS_GOT16; + return Type == R_MIPS_GOT16 || Type == R_MIPS_CALL16; } template @@ -882,9 +888,10 @@ case R_MIPS_32: add32(Loc, SA); break; + case R_MIPS_CALL16: case R_MIPS_GOT16: { int64_t V = SA - getMipsGpAddr(); - if (!isInt<16>(V)) + if (Type == R_MIPS_GOT16 && !isInt<16>(V)) error("Relocation R_MIPS_GOT16 out of range"); write32(Loc, (read32(Loc) & 0xffff0000) | (V & 0xffff)); break; Index: test/ELF/mips-call16.s =================================================================== --- /dev/null +++ test/ELF/mips-call16.s @@ -0,0 +1,40 @@ +# Check R_MIPS_CALL16 relocation calculation. + +# RUN: llvm-mc -filetype=obj -triple=mips-unknown-linux %s -o %t.o +# RUN: ld.lld %t.o -shared -o %t.exe +# RUN: llvm-objdump -d %t.exe | FileCheck %s +# RUN: llvm-readobj -mips-plt-got -symbols %t.exe \ +# RUN: | FileCheck -check-prefix=GOT %s + +# REQUIRES: mips + + .text + .globl __start +__start: + lw $t0,%call16(g1)($gp) + + .globl g1 + .type g1,@function +g1: + nop + +# CHECK: Disassembly of section .text: +# CHECK-NEXT: __start: +# CHECK-NEXT: 10000: 8f 88 80 18 lw $8, -32744 + +# GOT: Name: g1 +# GOT-NEXT: Value: 0x[[ADDR:[0-9A-F]+]] + +# GOT: Local entries [ +# GOT-NEXT: ] +# GOT-NEXT: Global entries [ +# GOT-NEXT: Entry { +# GOT-NEXT: Address: +# GOT-NEXT: Access: -32744 +# GOT-NEXT: Initial: 0x[[ADDR]] +# GOT-NEXT: Value: 0x[[ADDR]] +# GOT-NEXT: Type: Function +# GOT-NEXT: Section: .text +# GOT-NEXT: Name: g1 +# GOT-NEXT: } +# GOT-NEXT: ]