diff --git a/lld/MachO/InputSection.cpp b/lld/MachO/InputSection.cpp index 9ae9ca34286f0..b56e496f15670 100644 --- a/lld/MachO/InputSection.cpp +++ b/lld/MachO/InputSection.cpp @@ -64,6 +64,7 @@ void ConcatInputSection::writeTo(uint8_t *buf) { 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 @@ void ConcatInputSection::writeTo(uint8_t *buf) { 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/InputSection.h b/lld/MachO/InputSection.h index dabf30a5e1135..e0d463ea30bc0 100644 --- a/lld/MachO/InputSection.h +++ b/lld/MachO/InputSection.h @@ -110,6 +110,18 @@ class ConcatInputSection final : public InputSection { 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/MapFile.cpp b/lld/MachO/MapFile.cpp index 1b516bbef646f..26db02d1e7a2c 100644 --- a/lld/MachO/MapFile.cpp +++ b/lld/MachO/MapFile.cpp @@ -65,8 +65,10 @@ static std::vector getSymbols() { 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 @@ 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) { diff --git a/lld/MachO/UnwindInfoSection.cpp b/lld/MachO/UnwindInfoSection.cpp index 8b3db310ca152..309e5ce64d73c 100644 --- a/lld/MachO/UnwindInfoSection.cpp +++ b/lld/MachO/UnwindInfoSection.cpp @@ -174,6 +174,7 @@ void UnwindInfoSectionImpl::prepareRelocations(ConcatInputSection *isec) { } 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.