forked from OSchip/llvm-project
[ELF] Simplify MergeInputSection::getParentOffset. NFC
and remove overly verbose comments.
This commit is contained in:
parent
6778e2f441
commit
8565a87fd4
|
@ -1410,26 +1410,17 @@ void MergeInputSection::splitIntoPieces() {
|
||||||
splitNonStrings(data(), entsize);
|
splitNonStrings(data(), entsize);
|
||||||
}
|
}
|
||||||
|
|
||||||
SectionPiece *MergeInputSection::getSectionPiece(uint64_t offset) {
|
SectionPiece &MergeInputSection::getSectionPiece(uint64_t offset) {
|
||||||
if (this->rawData.size() <= offset)
|
if (rawData.size() <= offset)
|
||||||
fatal(toString(this) + ": offset is outside the section");
|
fatal(toString(this) + ": offset is outside the section");
|
||||||
|
return partition_point(
|
||||||
// If Offset is not at beginning of a section piece, it is not in the map.
|
pieces, [=](SectionPiece p) { return p.inputOff <= offset; })[-1];
|
||||||
// In that case we need to do a binary search of the original section piece vector.
|
|
||||||
auto it = partition_point(
|
|
||||||
pieces, [=](SectionPiece p) { return p.inputOff <= offset; });
|
|
||||||
return &it[-1];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns the offset in an output section for a given input offset.
|
// Return the offset in an output section for a given input offset.
|
||||||
// Because contents of a mergeable section is not contiguous in output,
|
|
||||||
// it is not just an addition to a base output offset.
|
|
||||||
uint64_t MergeInputSection::getParentOffset(uint64_t offset) const {
|
uint64_t MergeInputSection::getParentOffset(uint64_t offset) const {
|
||||||
// If Offset is not at beginning of a section piece, it is not in the map.
|
const SectionPiece &piece = getSectionPiece(offset);
|
||||||
// In that case we need to search from the original section piece vector.
|
return piece.outputOff + (offset - piece.inputOff);
|
||||||
const SectionPiece &piece = *getSectionPiece(offset);
|
|
||||||
uint64_t addend = offset - piece.inputOff;
|
|
||||||
return piece.outputOff + addend;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template InputSection::InputSection(ObjFile<ELF32LE> &, const ELF32LE::Shdr &,
|
template InputSection::InputSection(ObjFile<ELF32LE> &, const ELF32LE::Shdr &,
|
||||||
|
|
|
@ -282,8 +282,8 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns the SectionPiece at a given input section offset.
|
// Returns the SectionPiece at a given input section offset.
|
||||||
SectionPiece *getSectionPiece(uint64_t offset);
|
SectionPiece &getSectionPiece(uint64_t offset);
|
||||||
const SectionPiece *getSectionPiece(uint64_t offset) const {
|
const SectionPiece &getSectionPiece(uint64_t offset) const {
|
||||||
return const_cast<MergeInputSection *>(this)->getSectionPiece(offset);
|
return const_cast<MergeInputSection *>(this)->getSectionPiece(offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -198,7 +198,7 @@ void MarkLive<ELFT>::enqueue(InputSectionBase *sec, uint64_t offset) {
|
||||||
// (splittable) sections, each piece of data has independent liveness bit.
|
// (splittable) sections, each piece of data has independent liveness bit.
|
||||||
// So we explicitly tell it which offset is in use.
|
// So we explicitly tell it which offset is in use.
|
||||||
if (auto *ms = dyn_cast<MergeInputSection>(sec))
|
if (auto *ms = dyn_cast<MergeInputSection>(sec))
|
||||||
ms->getSectionPiece(offset)->live = true;
|
ms->getSectionPiece(offset).live = true;
|
||||||
|
|
||||||
// Set Sec->Partition to the meet (i.e. the "minimum") of Partition and
|
// Set Sec->Partition to the meet (i.e. the "minimum") of Partition and
|
||||||
// Sec->Partition in the following lattice: 1 < other < 0. If Sec->Partition
|
// Sec->Partition in the following lattice: 1 < other < 0. If Sec->Partition
|
||||||
|
|
|
@ -673,7 +673,7 @@ static bool includeInSymtab(const Symbol &b) {
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if (auto *s = dyn_cast<MergeInputSection>(sec))
|
if (auto *s = dyn_cast<MergeInputSection>(sec))
|
||||||
return s->getSectionPiece(d->value)->live;
|
return s->getSectionPiece(d->value).live;
|
||||||
return sec->isLive();
|
return sec->isLive();
|
||||||
}
|
}
|
||||||
return b.used || !config->gcSections;
|
return b.used || !config->gcSections;
|
||||||
|
|
Loading…
Reference in New Issue