diff --git a/lld/MachO/InputSection.h b/lld/MachO/InputSection.h --- a/lld/MachO/InputSection.h +++ b/lld/MachO/InputSection.h @@ -110,6 +110,18 @@ uint64_t outSecOff = 0; }; +// Helper functions to make it easy to sprinkle asserts. + +inline bool shouldOmitFromOutput(InputSection *isec) { + return isa(isec) && + cast(isec)->shouldOmitFromOutput(); +} + +inline bool isCoalescedWeak(InputSection *isec) { + return isa(isec) && + cast(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 { diff --git a/lld/MachO/InputSection.cpp b/lld/MachO/InputSection.cpp --- a/lld/MachO/InputSection.cpp +++ b/lld/MachO/InputSection.cpp @@ -64,6 +64,7 @@ minuendVA = toSym->getVA() + minuend.addend; else { auto *referentIsec = minuend.referent.get(); + assert(!::shouldOmitFromOutput(referentIsec)); minuendVA = referentIsec->getVA(minuend.addend); } referentVA = minuendVA - fromSym->getVA(); @@ -82,6 +83,7 @@ referentVA -= firstTLVDataSection->addr; } } else if (auto *referentIsec = r.referent.dyn_cast()) { + assert(!::shouldOmitFromOutput(referentIsec)); referentVA = referentIsec->getVA(r.addend); } target->relocateOne(loc, r, referentVA, getVA() + r.offset); diff --git a/lld/MachO/MapFile.cpp b/lld/MachO/MapFile.cpp --- a/lld/MachO/MapFile.cpp +++ b/lld/MachO/MapFile.cpp @@ -65,8 +65,10 @@ if (isa(file)) for (Symbol *sym : file->symbols) if (auto *d = dyn_cast_or_null(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 @@ 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) { diff --git a/lld/MachO/UnwindInfoSection.cpp b/lld/MachO/UnwindInfoSection.cpp --- a/lld/MachO/UnwindInfoSection.cpp +++ b/lld/MachO/UnwindInfoSection.cpp @@ -174,6 +174,7 @@ } if (auto *referentIsec = r.referent.dyn_cast()) { + 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.