Skip to content

Commit 134e3c0

Browse files
jrtc27krishna2803
authored andcommitted
[NFCI][ELF][Mips] Replace MipsMultiGotPage with new RE_MIPS_OSEC_LOCAL_PAGE
Instead of having a special DynamicReloc::Kind, we can just use a new RelExpr for the calculation needed. The only odd thing we do that allows this is to keep a representative symbol for the OutputSection in question (the first we see for it) around to use in this relocation for the addend calculation. This reduces DynamicReloc to just AddendOnly vs AgainstSymbol, plus the internal Computed. Reviewers: MaskRay, arichardson Reviewed By: MaskRay, arichardson Pull Request: llvm#150810
1 parent 8989010 commit 134e3c0

File tree

6 files changed

+18
-23
lines changed

6 files changed

+18
-23
lines changed

lld/ELF/Arch/Mips.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ template <class ELFT> class MIPS final : public TargetInfo {
4040
};
4141
} // namespace
4242

43+
uint64_t elf::getMipsPageAddr(uint64_t addr) {
44+
return (addr + 0x8000) & ~0xffff;
45+
}
46+
4347
template <class ELFT> MIPS<ELFT>::MIPS(Ctx &ctx) : TargetInfo(ctx) {
4448
gotPltHeaderEntriesNum = 2;
4549
defaultMaxPageSize = 65536;

lld/ELF/InputSection.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -861,6 +861,11 @@ uint64_t InputSectionBase::getRelocTargetVA(Ctx &ctx, const Relocation &r,
861861
return ctx.in.mipsGot->getVA() +
862862
ctx.in.mipsGot->getPageEntryOffset(file, *r.sym, a) -
863863
ctx.in.mipsGot->getGp(file);
864+
case RE_MIPS_OSEC_LOCAL_PAGE:
865+
// This is used by the MIPS multi-GOT implementation. It relocates
866+
// addresses of 64kb pages that lie inside the output section that sym is
867+
// a representative for.
868+
return getMipsPageAddr(r.sym->getOutputSection()->addr) + a;
864869
case RE_MIPS_GOT_OFF:
865870
case RE_MIPS_GOT_OFF32:
866871
// In case of MIPS if a GOT relocation has non-zero addend this addend

lld/ELF/Relocations.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ enum RelExpr {
110110
RE_MIPS_GOT_LOCAL_PAGE,
111111
RE_MIPS_GOT_OFF,
112112
RE_MIPS_GOT_OFF32,
113+
RE_MIPS_OSEC_LOCAL_PAGE,
113114
RE_MIPS_TLSGD,
114115
RE_MIPS_TLSLD,
115116
RE_PPC32_PLTREL,

lld/ELF/SyntheticSections.cpp

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -769,10 +769,6 @@ void GotSection::writeTo(uint8_t *buf) {
769769
}
770770
}
771771

772-
static uint64_t getMipsPageAddr(uint64_t addr) {
773-
return (addr + 0x8000) & ~0xffff;
774-
}
775-
776772
static uint64_t getMipsPageCount(uint64_t size) {
777773
return (size + 0xfffe) / 0xffff + 1;
778774
}
@@ -786,7 +782,7 @@ void MipsGotSection::addEntry(InputFile &file, Symbol &sym, int64_t addend,
786782
FileGot &g = getGot(file);
787783
if (expr == RE_MIPS_GOT_LOCAL_PAGE) {
788784
if (const OutputSection *os = sym.getOutputSection())
789-
g.pagesMap.insert({os, {}});
785+
g.pagesMap.insert({os, {&sym}});
790786
else
791787
g.local16.insert({{nullptr, getMipsPageAddr(sym.getVA(ctx, addend))}, 0});
792788
} else if (sym.isTls())
@@ -1115,8 +1111,9 @@ void MipsGotSection::build() {
11151111
size_t pageCount = l.second.count;
11161112
for (size_t pi = 0; pi < pageCount; ++pi) {
11171113
uint64_t offset = (l.second.firstIndex + pi) * ctx.arg.wordsize;
1118-
ctx.mainPart->relaDyn->addReloc({ctx.target->relativeRel, this, offset,
1119-
l.first, int64_t(pi * 0x10000)});
1114+
ctx.mainPart->relaDyn->addReloc(
1115+
{ctx.target->relativeRel, this, offset, DynamicReloc::AddendOnly,
1116+
*l.second.repSym, int64_t(pi * 0x10000), RE_MIPS_OSEC_LOCAL_PAGE});
11201117
}
11211118
}
11221119
for (const std::pair<GotEntry, size_t> &p : got.local16) {
@@ -1655,9 +1652,6 @@ int64_t DynamicReloc::computeAddend(Ctx &ctx) const {
16551652
ctx, Relocation{expr, type, 0, addend, sym}, getOffset());
16561653
return ctx.arg.is64 ? ca : SignExtend64<32>(ca);
16571654
}
1658-
case MipsMultiGotPage:
1659-
assert(sym == nullptr);
1660-
return getMipsPageAddr(outputSec->addr) + addend;
16611655
}
16621656
llvm_unreachable("Unknown DynamicReloc::Kind enum");
16631657
}

lld/ELF/SyntheticSections.h

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -327,9 +327,11 @@ class MipsGotSection final : public SyntheticSection {
327327
size_t startIndex = 0;
328328

329329
struct PageBlock {
330+
Symbol *repSym; // Representative symbol for the OutputSection
330331
size_t firstIndex;
331332
size_t count;
332-
PageBlock() : firstIndex(0), count(0) {}
333+
PageBlock(Symbol *repSym = nullptr)
334+
: repSym(repSym), firstIndex(0), count(0) {}
333335
};
334336

335337
// Map output sections referenced by MIPS GOT relocations
@@ -430,9 +432,6 @@ class DynamicReloc {
430432
/// symbol table and uses InputSection::getRelocTargetVA() for the final
431433
/// addend.
432434
AgainstSymbol,
433-
/// This is used by the MIPS multi-GOT implementation. It relocates
434-
/// addresses of 64kb pages that lie inside the output section.
435-
MipsMultiGotPage,
436435
};
437436
/// This constructor records a normal relocation.
438437
DynamicReloc(RelType type, const InputSectionBase *inputSec,
@@ -446,14 +445,6 @@ class DynamicReloc {
446445
: sym(inputSec->getCtx().dummySym), inputSec(inputSec),
447446
offsetInSec(offsetInSec), type(type), addend(addend), kind(AddendOnly),
448447
expr(R_ADDEND) {}
449-
/// This constructor records dynamic relocation settings used by the MIPS
450-
/// multi-GOT implementation.
451-
DynamicReloc(RelType type, const InputSectionBase *inputSec,
452-
uint64_t offsetInSec, const OutputSection *outputSec,
453-
int64_t addend)
454-
: sym(nullptr), outputSec(outputSec), inputSec(inputSec),
455-
offsetInSec(offsetInSec), type(type), addend(addend),
456-
kind(MipsMultiGotPage), expr(R_ADDEND) {}
457448

458449
uint64_t getOffset() const;
459450
uint32_t getSymIndex(SymbolTableBaseSection *symTab) const;
@@ -470,7 +461,6 @@ class DynamicReloc {
470461
void computeRaw(Ctx &, SymbolTableBaseSection *symt);
471462

472463
Symbol *sym;
473-
const OutputSection *outputSec = nullptr;
474464
const InputSectionBase *inputSec;
475465
uint64_t offsetInSec;
476466
uint64_t r_offset;

lld/ELF/Target.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ void processArmCmseSymbols(Ctx &);
214214
template <class ELFT> uint32_t calcMipsEFlags(Ctx &);
215215
uint8_t getMipsFpAbiFlag(Ctx &, InputFile *file, uint8_t oldFlag,
216216
uint8_t newFlag);
217+
uint64_t getMipsPageAddr(uint64_t addr);
217218
bool isMipsN32Abi(Ctx &, const InputFile &f);
218219
bool isMicroMips(Ctx &);
219220
bool isMipsR6(Ctx &);

0 commit comments

Comments
 (0)