[lld] r317741 - [MIPS] Setup less-significant bit in the .got and .got.plt entries in case of microMIPS code
Simon Atanasyan via llvm-commits
llvm-commits at lists.llvm.org
Wed Nov 8 15:34:34 PST 2017
Author: atanasyan
Date: Wed Nov 8 15:34:34 2017
New Revision: 317741
URL: http://llvm.org/viewvc/llvm-project?rev=317741&view=rev
Log:
[MIPS] Setup less-significant bit in the .got and .got.plt entries in case of microMIPS code
The less-significant bit signals about microMIPS code for jump/branch
instructions.
Added:
lld/trunk/test/ELF/mips-micro-plt.s
Modified:
lld/trunk/ELF/Arch/Mips.cpp
lld/trunk/ELF/SyntheticSections.cpp
Modified: lld/trunk/ELF/Arch/Mips.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Arch/Mips.cpp?rev=317741&r1=317740&r2=317741&view=diff
==============================================================================
--- lld/trunk/ELF/Arch/Mips.cpp (original)
+++ lld/trunk/ELF/Arch/Mips.cpp Wed Nov 8 15:34:34 2017
@@ -191,9 +191,14 @@ template <class ELFT> RelType MIPS<ELFT>
return RelativeRel;
}
+static bool isMicroMips() { return Config->EFlags & EF_MIPS_MICROMIPS; }
+
template <class ELFT>
void MIPS<ELFT>::writeGotPlt(uint8_t *Buf, const Symbol &) const {
- write32<ELFT::TargetEndianness>(Buf, InX::Plt->getVA());
+ uint64_t VA = InX::Plt->getVA();
+ if (isMicroMips())
+ VA |= 1;
+ write32<ELFT::TargetEndianness>(Buf, VA);
}
template <endianness E> static uint32_t readShuffle(const uint8_t *Loc) {
@@ -241,8 +246,6 @@ static void writeMicroRelocation16(uint8
write16<E>(Loc, Data);
}
-static bool isMicroMips() { return Config->EFlags & EF_MIPS_MICROMIPS; }
-
template <class ELFT> void MIPS<ELFT>::writePltHeader(uint8_t *Buf) const {
const endianness E = ELFT::TargetEndianness;
if (isMicroMips()) {
Modified: lld/trunk/ELF/SyntheticSections.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SyntheticSections.cpp?rev=317741&r1=317740&r2=317741&view=diff
==============================================================================
--- lld/trunk/ELF/SyntheticSections.cpp (original)
+++ lld/trunk/ELF/SyntheticSections.cpp Wed Nov 8 15:34:34 2017
@@ -853,6 +853,8 @@ void MipsGotSection::writeTo(uint8_t *Bu
Buf += Config->Wordsize;
const Symbol *Sym = SA.first;
uint64_t VA = Sym->getVA(SA.second);
+ if (Sym->StOther & STO_MIPS_MICROMIPS)
+ VA |= 1;
writeUint(Entry, VA);
};
std::for_each(std::begin(LocalEntries), std::end(LocalEntries), AddEntry);
Added: lld/trunk/test/ELF/mips-micro-plt.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/mips-micro-plt.s?rev=317741&view=auto
==============================================================================
--- lld/trunk/test/ELF/mips-micro-plt.s (added)
+++ lld/trunk/test/ELF/mips-micro-plt.s Wed Nov 8 15:34:34 2017
@@ -0,0 +1,45 @@
+# Check less-significant bit setup for microMIPS PLT.
+
+# RUN: llvm-mc -filetype=obj -triple=mips-unknown-linux \
+# RUN: -mattr=micromips %S/Inputs/mips-dynamic.s -o %t-dso.o
+# RUN: ld.lld %t-dso.o -shared -o %t.so
+# RUN: llvm-mc -filetype=obj -triple=mips-unknown-linux \
+# RUN: -mattr=micromips %s -o %t-exe.o
+# RUN: ld.lld %t-exe.o %t.so -o %t.exe
+# RUN: llvm-readobj -mips-plt-got %t.exe | FileCheck %s
+
+# REQUIRES: mips
+
+# CHECK: Primary GOT {
+# CHECK: Local entries [
+# CHECK-NEXT: Entry {
+# CHECK-NEXT: Address:
+# CHECK-NEXT: Access:
+# CHECK-NEXT: Initial: 0x20009
+# CHECK-NEXT: }
+# CHECK: ]
+# CHECK: }
+
+# CHECK: PLT GOT {
+# CHECK: Entries [
+# CHECK-NEXT: Entry {
+# CHECK-NEXT: Address:
+# CHECK-NEXT: Initial: 0x20011
+# CHECK-NEXT: Value: 0x0
+# CHECK-NEXT: Type: Function
+# CHECK-NEXT: Section: Undefined
+# CHECK-NEXT: Name: foo0@
+# CHECK-NEXT: }
+# CHECK-NEXT: ]
+# CHECK-NEXT: }
+
+ .text
+ .set micromips
+ .global foo
+ .hidden foo
+ .global __start
+__start:
+ lw $t0,%got(foo)($gp)
+ addi $t0,$t0,%lo(foo)
+foo:
+ jal foo0
More information about the llvm-commits
mailing list