summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lld/ELF/InputSection.cpp6
-rw-r--r--lld/ELF/InputSection.h1
-rw-r--r--lld/ELF/OutputSections.cpp8
-rw-r--r--lld/ELF/OutputSections.h4
-rw-r--r--lld/ELF/Target.cpp12
-rw-r--r--lld/ELF/Writer.cpp7
6 files changed, 21 insertions, 17 deletions
diff --git a/lld/ELF/InputSection.cpp b/lld/ELF/InputSection.cpp
index 82b5f98ce9e..3df6cf0070d 100644
--- a/lld/ELF/InputSection.cpp
+++ b/lld/ELF/InputSection.cpp
@@ -211,18 +211,20 @@ getSymVA(uint32_t Type, typename ELFT::uint A, typename ELFT::uint P,
// relocations because they use the following expression to calculate
// the relocation's result for local symbol: S + A + GP0 - G.
return Body.getVA<ELFT>(A) + File.getMipsGp0();
+ case R_GOT_OFF:
+ return Body.getGotOffset<ELFT>() + A;
case R_MIPS_GOT_LOCAL:
// If relocation against MIPS local symbol requires GOT entry, this entry
// should be initialized by 'page address'. This address is high 16-bits
// of sum the symbol's value and the addend.
- return Out<ELFT>::Got->getMipsLocalPageAddr(Body.getVA<ELFT>(A));
+ return Out<ELFT>::Got->getMipsLocalPageOffset(Body.getVA<ELFT>(A));
case R_MIPS_GOT:
// For non-local symbols GOT entries should contain their full
// addresses. But if such symbol cannot be preempted, we do not
// have to put them into the "global" part of GOT and use dynamic
// linker to determine their actual addresses. That is why we
// create GOT entries for them in the "local" part of GOT.
- return Out<ELFT>::Got->getMipsLocalEntryAddr(Body.getVA<ELFT>(A));
+ return Out<ELFT>::Got->getMipsLocalEntryOffset(Body.getVA<ELFT>(A));
case R_PPC_OPD: {
uint64_t SymVA = Body.getVA<ELFT>(A);
// If we have an undefined weak symbol, we might get here with a symbol
diff --git a/lld/ELF/InputSection.h b/lld/ELF/InputSection.h
index 577257333b2..c34c94d336d 100644
--- a/lld/ELF/InputSection.h
+++ b/lld/ELF/InputSection.h
@@ -31,6 +31,7 @@ enum RelExpr {
R_GOT,
R_GOTONLY_PC,
R_GOTREL,
+ R_GOT_OFF,
R_GOT_FROM_END,
R_GOT_PAGE_PC,
R_GOT_PC,
diff --git a/lld/ELF/OutputSections.cpp b/lld/ELF/OutputSections.cpp
index 96505b244f8..08fed9a43ae 100644
--- a/lld/ELF/OutputSections.cpp
+++ b/lld/ELF/OutputSections.cpp
@@ -165,19 +165,19 @@ template <class ELFT> bool GotSection<ELFT>::addTlsIndex() {
template <class ELFT>
typename GotSection<ELFT>::uintX_t
-GotSection<ELFT>::getMipsLocalPageAddr(uintX_t EntryValue) {
+GotSection<ELFT>::getMipsLocalPageOffset(uintX_t EntryValue) {
// Initialize the entry by the %hi(EntryValue) expression
// but without right-shifting.
- return getMipsLocalEntryAddr((EntryValue + 0x8000) & ~0xffff);
+ return getMipsLocalEntryOffset((EntryValue + 0x8000) & ~0xffff);
}
template <class ELFT>
typename GotSection<ELFT>::uintX_t
-GotSection<ELFT>::getMipsLocalEntryAddr(uintX_t EntryValue) {
+GotSection<ELFT>::getMipsLocalEntryOffset(uintX_t EntryValue) {
size_t NewIndex = Target->GotHeaderEntriesNum + MipsLocalGotPos.size();
auto P = MipsLocalGotPos.insert(std::make_pair(EntryValue, NewIndex));
assert(!P.second || MipsLocalGotPos.size() <= MipsLocalEntries);
- return this->getVA() + P.first->second * sizeof(uintX_t);
+ return P.first->second * sizeof(uintX_t) - MipsGPOffset;
}
template <class ELFT>
diff --git a/lld/ELF/OutputSections.h b/lld/ELF/OutputSections.h
index 54685a864be..85808a820c5 100644
--- a/lld/ELF/OutputSections.h
+++ b/lld/ELF/OutputSections.h
@@ -112,8 +112,8 @@ public:
bool addDynTlsEntry(SymbolBody &Sym);
bool addTlsIndex();
bool empty() const { return MipsLocalEntries == 0 && Entries.empty(); }
- uintX_t getMipsLocalEntryAddr(uintX_t EntryValue);
- uintX_t getMipsLocalPageAddr(uintX_t Addr);
+ uintX_t getMipsLocalEntryOffset(uintX_t EntryValue);
+ uintX_t getMipsLocalPageOffset(uintX_t Addr);
uintX_t getGlobalDynAddr(const SymbolBody &B) const;
uintX_t getGlobalDynOffset(const SymbolBody &B) const;
uintX_t getNumEntries() const { return Entries.size(); }
diff --git a/lld/ELF/Target.cpp b/lld/ELF/Target.cpp
index 0e07fae502b..48c5f6aa731 100644
--- a/lld/ELF/Target.cpp
+++ b/lld/ELF/Target.cpp
@@ -1510,7 +1510,7 @@ RelExpr MipsTargetInfo<ELFT>::getRelExpr(uint32_t Type,
return R_MIPS_GOT_LOCAL;
if (!S.isPreemptible())
return R_MIPS_GOT;
- return R_GOT;
+ return R_GOT_OFF;
}
}
@@ -1726,14 +1726,12 @@ void MipsTargetInfo<ELFT>::relocateOne(uint8_t *Loc, uint32_t Type,
write32<E>(Loc, (Instr & ~0x3ffffff) | (Val >> 2));
break;
}
+ case R_MIPS_GOT16:
+ checkInt<16>(Val, Type);
+ // fallthrough
case R_MIPS_CALL16:
- case R_MIPS_GOT16: {
- int64_t V = Val - getMipsGpAddr<ELFT>();
- if (Type == R_MIPS_GOT16)
- checkInt<16>(V, Type);
- writeMipsLo16<E>(Loc, V);
+ writeMipsLo16<E>(Loc, Val);
break;
- }
case R_MIPS_GPREL16: {
int64_t V = Val - getMipsGpAddr<ELFT>();
checkInt<16>(V, Type);
diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp
index 3421eb3e2a4..71b2664baac 100644
--- a/lld/ELF/Writer.cpp
+++ b/lld/ELF/Writer.cpp
@@ -566,9 +566,12 @@ void Writer<ELFT>::scanRelocs(InputSectionBase<ELFT> &C, ArrayRef<RelTy> Rels) {
}
// If a relocation needs GOT, we create a GOT slot for the symbol.
- if (Expr == R_GOT || Expr == R_MIPS_GOT || Expr == R_MIPS_GOT_LOCAL ||
- Expr == R_GOT_PAGE_PC || Expr == R_GOT_PC || Expr == R_GOT_FROM_END) {
+ if (Expr == R_GOT || Expr == R_GOT_OFF || Expr == R_MIPS_GOT ||
+ Expr == R_MIPS_GOT_LOCAL || Expr == R_GOT_PAGE_PC || Expr == R_GOT_PC ||
+ Expr == R_GOT_FROM_END) {
uint32_t T = Body.isTls() ? Target->getTlsGotRel(Type) : Type;
+ if (Config->EMachine == EM_MIPS && Expr == R_GOT_OFF)
+ Addend -= MipsGPOffset;
C.Relocations.push_back({Expr, T, Offset, Addend, &Body});
if (Body.isInGot())
continue;
OpenPOWER on IntegriCloud