Index: wasm/InputChunks.h =================================================================== --- wasm/InputChunks.h +++ wasm/InputChunks.h @@ -57,12 +57,12 @@ virtual StringRef getComdat() const = 0; virtual StringRef getName() const = 0; - bool Discarded = false; std::vector OutRelocations; ObjFile *File; - // The garbage collector sets sections' Live bits. - // If GC is disabled, all sections are considered live by default. + // Signals that the section is part of the output. The garbage collector, + // and COMDAT handling can set a sections' Live bit. + // If GC is disabled, all sections start out as live by default. unsigned Live : 1; protected: Index: wasm/InputFiles.cpp =================================================================== --- wasm/InputFiles.cpp +++ wasm/InputFiles.cpp @@ -252,7 +252,7 @@ S = createDefined(WasmSym, Symbol::Kind::DefinedFunctionKind, Function); break; } else { - Function->Discarded = true; + Function->Live = false; LLVM_FALLTHROUGH; // Exclude function, and add the symbol as undefined } } @@ -267,7 +267,7 @@ getGlobalValue(WasmSym)); break; } else { - Segment->Discarded = true; + Segment->Live = false; LLVM_FALLTHROUGH; // Exclude global, and add the symbol as undefined } } Index: wasm/Writer.cpp =================================================================== --- wasm/Writer.cpp +++ wasm/Writer.cpp @@ -662,14 +662,11 @@ continue; if (Sym->isGlobal()) continue; - if (Sym->getChunk()->Discarded) + if (!Sym->getChunk()->Live) continue; if ((Sym->isHidden() || Sym->isLocal()) && !ExportHidden) continue; - - // We should never be exporting a non-live symbol - assert(Sym->getChunk()->Live); ExportedSymbols.emplace_back(WasmExportEntry{Sym, BudgeLocalName(Sym)}); } } @@ -759,7 +756,7 @@ for (ObjFile *File : Symtab->ObjectFiles) { DEBUG(dbgs() << "Functions: " << File->getName() << "\n"); for (InputFunction *Func : File->Functions) { - if (Func->Discarded || !Func->Live) + if (!Func->Live) continue; DefinedFunctions.emplace_back(Func); Func->setOutputIndex(FunctionIndex++); @@ -769,7 +766,7 @@ for (ObjFile *File : Symtab->ObjectFiles) { DEBUG(dbgs() << "Handle relocs: " << File->getName() << "\n"); auto HandleRelocs = [&](InputChunk *Chunk) { - if (Chunk->Discarded) + if (!Chunk->Live) return; ArrayRef Types = File->getWasmObj()->types(); for (const WasmRelocation& Reloc : Chunk->getRelocations()) { @@ -813,7 +810,7 @@ void Writer::createOutputSegments() { for (ObjFile *File : Symtab->ObjectFiles) { for (InputSegment *Segment : File->Segments) { - if (Segment->Discarded || !Segment->Live) + if (!Segment->Live) continue; StringRef Name = getOutputDataSegmentName(Segment->getName()); OutputSegment *&S = SegmentMap[Name];