Index: lld/COFF/InputFiles.cpp =================================================================== --- lld/COFF/InputFiles.cpp +++ lld/COFF/InputFiles.cpp @@ -227,11 +227,17 @@ uint32_t ParentSection) { SectionChunk *Parent = SparseChunks[ParentSection]; - // If the parent is pending, it probably means that its section definition - // appears after us in the symbol table. Leave the associated section as - // pending; we will handle it during the second pass in initializeSymbols(). - if (Parent == PendingComdat) + if (Parent == PendingComdat) { + // This can only happen if an associative comdat refers to another + // associative comdat that appears after it. + StringRef Name, ParentName; + COFFObj->getSymbolName(Sym, Name); + COFFSymbolRef ParentSym = check(COFFObj->getSymbol(ParentSection)); + COFFObj->getSymbolName(ParentSym, ParentName); + error("associative comdat " + Name + + " refers to associative comdat " + ParentName); return; + } // Check whether the parent is prevailing. If it is, so are we, and we read // the section; otherwise mark it as discarded. @@ -438,21 +444,15 @@ return Leader; } - // Read associative section definitions and prepare to handle the comdat - // leader symbol by setting the section's ComdatDefs pointer if we encounter a - // non-associative comdat. + // Prepare to handle the comdat leader symbol by setting the section's + // ComdatDefs pointer if we encounter a non-associative comdat. if (SparseChunks[SectionNumber] == PendingComdat) { if (const coff_aux_section_definition *Def = Sym.getSectionDefinition()) { - if (Def->Selection == IMAGE_COMDAT_SELECT_ASSOCIATIVE) - readAssociativeDefinition(Sym, Def); - else + if (Def->Selection != IMAGE_COMDAT_SELECT_ASSOCIATIVE) ComdatDefs[SectionNumber] = Def; } - } - - // readAssociativeDefinition() writes to SparseChunks, so need to check again. - if (SparseChunks[SectionNumber] == PendingComdat) return None; + } return createRegular(Sym); }