forked from OSchip/llvm-project
[ELF][MIPS] Replace the magic number of GOT header entries by constant. NFC
llvm-svn: 288128
This commit is contained in:
parent
80f3d9ce93
commit
a0efc4268c
|
@ -536,10 +536,10 @@ MipsGotSection<ELFT>::getPageEntryOffset(uintX_t EntryValue) {
|
||||||
EntryValue = (EntryValue + 0x8000) & ~0xffff;
|
EntryValue = (EntryValue + 0x8000) & ~0xffff;
|
||||||
// Take into account MIPS GOT header.
|
// Take into account MIPS GOT header.
|
||||||
// See comment in the MipsGotSection::writeTo.
|
// See comment in the MipsGotSection::writeTo.
|
||||||
size_t NewIndex = PageIndexMap.size() + 2;
|
size_t NewIndex = PageIndexMap.size();
|
||||||
auto P = PageIndexMap.insert(std::make_pair(EntryValue, NewIndex));
|
auto P = PageIndexMap.insert(std::make_pair(EntryValue, NewIndex));
|
||||||
assert(!P.second || PageIndexMap.size() <= (PageEntriesNum - 2));
|
assert(!P.second || PageIndexMap.size() <= PageEntriesNum);
|
||||||
return (uintX_t)P.first->second * sizeof(uintX_t);
|
return (HeaderEntriesNum + P.first->second) * sizeof(uintX_t);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class ELFT>
|
template <class ELFT>
|
||||||
|
@ -547,25 +547,22 @@ typename MipsGotSection<ELFT>::uintX_t
|
||||||
MipsGotSection<ELFT>::getBodyEntryOffset(const SymbolBody &B,
|
MipsGotSection<ELFT>::getBodyEntryOffset(const SymbolBody &B,
|
||||||
uintX_t Addend) const {
|
uintX_t Addend) const {
|
||||||
// Calculate offset of the GOT entries block: TLS, global, local.
|
// Calculate offset of the GOT entries block: TLS, global, local.
|
||||||
uintX_t GotBlockOff;
|
uintX_t Index = HeaderEntriesNum + PageEntriesNum;
|
||||||
if (B.isTls())
|
if (B.isTls())
|
||||||
GotBlockOff = getTlsOffset();
|
Index += LocalEntries.size() + LocalEntries32.size() + GlobalEntries.size();
|
||||||
else if (B.IsInGlobalMipsGot)
|
else if (B.IsInGlobalMipsGot)
|
||||||
GotBlockOff = getLocalEntriesNum() * sizeof(uintX_t);
|
Index += LocalEntries.size() + LocalEntries32.size();
|
||||||
else if (B.Is32BitMipsGot)
|
else if (B.Is32BitMipsGot)
|
||||||
GotBlockOff = (PageEntriesNum + LocalEntries.size()) * sizeof(uintX_t);
|
Index += LocalEntries.size();
|
||||||
else
|
// Calculate offset of the GOT entry in the block.
|
||||||
GotBlockOff = PageEntriesNum * sizeof(uintX_t);
|
|
||||||
// Calculate index of the GOT entry in the block.
|
|
||||||
uintX_t GotIndex;
|
|
||||||
if (B.isInGot())
|
if (B.isInGot())
|
||||||
GotIndex = B.GotIndex;
|
Index += B.GotIndex;
|
||||||
else {
|
else {
|
||||||
auto It = EntryIndexMap.find({&B, Addend});
|
auto It = EntryIndexMap.find({&B, Addend});
|
||||||
assert(It != EntryIndexMap.end());
|
assert(It != EntryIndexMap.end());
|
||||||
GotIndex = It->second;
|
Index += It->second;
|
||||||
}
|
}
|
||||||
return GotBlockOff + GotIndex * sizeof(uintX_t);
|
return Index * sizeof(uintX_t);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class ELFT>
|
template <class ELFT>
|
||||||
|
@ -587,14 +584,15 @@ const SymbolBody *MipsGotSection<ELFT>::getFirstGlobalEntry() const {
|
||||||
|
|
||||||
template <class ELFT>
|
template <class ELFT>
|
||||||
unsigned MipsGotSection<ELFT>::getLocalEntriesNum() const {
|
unsigned MipsGotSection<ELFT>::getLocalEntriesNum() const {
|
||||||
return PageEntriesNum + LocalEntries.size() + LocalEntries32.size();
|
return HeaderEntriesNum + PageEntriesNum + LocalEntries.size() +
|
||||||
|
LocalEntries32.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class ELFT> void MipsGotSection<ELFT>::finalize() {
|
template <class ELFT> void MipsGotSection<ELFT>::finalize() {
|
||||||
size_t EntriesNum = TlsEntries.size();
|
size_t EntriesNum = TlsEntries.size();
|
||||||
// Take into account MIPS GOT header.
|
// Take into account MIPS GOT header.
|
||||||
// See comment in the MipsGotSection::writeTo.
|
// See comment in the MipsGotSection::writeTo.
|
||||||
PageEntriesNum = 2;
|
PageEntriesNum = 0;
|
||||||
for (const OutputSectionBase *OutSec : OutSections) {
|
for (const OutputSectionBase *OutSec : OutSections) {
|
||||||
// Calculate an upper bound of MIPS GOT entries required to store page
|
// Calculate an upper bound of MIPS GOT entries required to store page
|
||||||
// addresses of local symbols. We assume the worst case - each 64kb
|
// addresses of local symbols. We assume the worst case - each 64kb
|
||||||
|
@ -640,6 +638,7 @@ template <class ELFT> void MipsGotSection<ELFT>::writeTo(uint8_t *Buf) {
|
||||||
// if we had to do this.
|
// if we had to do this.
|
||||||
auto *P = reinterpret_cast<typename ELFT::Off *>(Buf);
|
auto *P = reinterpret_cast<typename ELFT::Off *>(Buf);
|
||||||
P[1] = uintX_t(1) << (ELFT::Is64Bits ? 63 : 31);
|
P[1] = uintX_t(1) << (ELFT::Is64Bits ? 63 : 31);
|
||||||
|
Buf += HeaderEntriesNum * sizeof(uintX_t);
|
||||||
// Write 'page address' entries to the local part of the GOT.
|
// Write 'page address' entries to the local part of the GOT.
|
||||||
for (std::pair<uintX_t, size_t> &L : PageIndexMap) {
|
for (std::pair<uintX_t, size_t> &L : PageIndexMap) {
|
||||||
uint8_t *Entry = Buf + L.second * sizeof(uintX_t);
|
uint8_t *Entry = Buf + L.second * sizeof(uintX_t);
|
||||||
|
|
|
@ -164,7 +164,9 @@ private:
|
||||||
// TLS entries:
|
// TLS entries:
|
||||||
// Entries created by TLS relocations.
|
// Entries created by TLS relocations.
|
||||||
|
|
||||||
// Total number of allocated "Header" and "Page" entries.
|
// Number of "Header" entries.
|
||||||
|
static const unsigned HeaderEntriesNum = 2;
|
||||||
|
// Number of allocated "Page" entries.
|
||||||
uint32_t PageEntriesNum = 0;
|
uint32_t PageEntriesNum = 0;
|
||||||
// Output sections referenced by MIPS GOT relocations.
|
// Output sections referenced by MIPS GOT relocations.
|
||||||
llvm::SmallPtrSet<const OutputSectionBase *, 10> OutSections;
|
llvm::SmallPtrSet<const OutputSectionBase *, 10> OutSections;
|
||||||
|
|
Loading…
Reference in New Issue