[lld-macho][nfc] Put back shouldOmitFromOutput() asserts

I removed them in rG5de7467e982 but @thakis pointed out that
they were useful to keep, so here they are again. I've also converted
the `!isCoalescedWeak()` asserts into `!shouldOmitFromOutput()` asserts,
since the latter check subsumes the former.

Reviewed By: #lld-macho, thakis

Differential Revision: https://reviews.llvm.org/D104169
This commit is contained in:
Jez Ng 2021-06-16 15:23:04 -04:00
parent d619cf5ac5
commit b8bbb9723a
4 changed files with 19 additions and 1 deletions

View File

@ -64,6 +64,7 @@ void ConcatInputSection::writeTo(uint8_t *buf) {
minuendVA = toSym->getVA() + minuend.addend;
else {
auto *referentIsec = minuend.referent.get<InputSection *>();
assert(!::shouldOmitFromOutput(referentIsec));
minuendVA = referentIsec->getVA(minuend.addend);
}
referentVA = minuendVA - fromSym->getVA();
@ -82,6 +83,7 @@ void ConcatInputSection::writeTo(uint8_t *buf) {
referentVA -= firstTLVDataSection->addr;
}
} else if (auto *referentIsec = r.referent.dyn_cast<InputSection *>()) {
assert(!::shouldOmitFromOutput(referentIsec));
referentVA = referentIsec->getVA(r.addend);
}
target->relocateOne(loc, r, referentVA, getVA() + r.offset);

View File

@ -110,6 +110,18 @@ public:
uint64_t outSecOff = 0;
};
// Helper functions to make it easy to sprinkle asserts.
inline bool shouldOmitFromOutput(InputSection *isec) {
return isa<ConcatInputSection>(isec) &&
cast<ConcatInputSection>(isec)->shouldOmitFromOutput();
}
inline bool isCoalescedWeak(InputSection *isec) {
return isa<ConcatInputSection>(isec) &&
cast<ConcatInputSection>(isec)->isCoalescedWeak();
}
// We allocate a lot of these and binary search on them, so they should be as
// compact as possible. Hence the use of 31 rather than 64 bits for the hash.
struct StringPiece {

View File

@ -65,8 +65,10 @@ static std::vector<Defined *> getSymbols() {
if (isa<ObjFile>(file))
for (Symbol *sym : file->symbols)
if (auto *d = dyn_cast_or_null<Defined>(sym))
if (d->isLive() && d->isec && d->getFile() == file)
if (d->isLive() && d->isec && d->getFile() == file) {
assert(!shouldOmitFromOutput(d->isec));
v.push_back(d);
}
return v;
}
@ -142,6 +144,7 @@ void macho::writeMapFile() {
os << "# Address\t File Name\n";
for (InputSection *isec : inputSections) {
auto symsIt = sectionSyms.find(isec);
assert(!shouldOmitFromOutput(isec) || (symsIt == sectionSyms.end()));
if (symsIt == sectionSyms.end())
continue;
for (Symbol *sym : symsIt->second) {

View File

@ -174,6 +174,7 @@ void UnwindInfoSectionImpl<Ptr>::prepareRelocations(ConcatInputSection *isec) {
}
if (auto *referentIsec = r.referent.dyn_cast<InputSection *>()) {
assert(!isCoalescedWeak(referentIsec));
// Personality functions can be referenced via section relocations
// if they live in the same object file. Create placeholder synthetic
// symbols for them in the GOT.