// 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
R_GOT,
R_GOTONLY_PC,
R_GOTREL,
+ R_GOT_OFF,
R_GOT_FROM_END,
R_GOT_PAGE_PC,
R_GOT_PC,
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>
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(); }
return R_MIPS_GOT_LOCAL;
if (!S.isPreemptible())
return R_MIPS_GOT;
- return R_GOT;
+ return R_GOT_OFF;
}
}
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);
}
// 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;