[WebAssembly] Simplify COMDAT handling.

Differential Revision: https://reviews.llvm.org/D43966

llvm-svn: 326509
diff --git a/lld/wasm/InputFiles.cpp b/lld/wasm/InputFiles.cpp
index fc5caee..fab6db2 100644
--- a/lld/wasm/InputFiles.cpp
+++ b/lld/wasm/InputFiles.cpp
@@ -117,9 +117,6 @@
   TypeMap.resize(getWasmObj()->types().size());
   TypeIsUsed.resize(getWasmObj()->types().size(), false);
 
-  for (StringRef Name : WasmObj->comdats())
-    Symtab->addComdat(Name, this);
-
   // Populate `Segments`.
   for (const WasmSegment &S : WasmObj->dataSegments()) {
     InputSegment *Seg = make<InputSegment>(S, this);
@@ -156,8 +153,10 @@
 }
 
 bool ObjFile::isExcludedByComdat(InputChunk *Chunk) const {
-  StringRef Comdat = Chunk->getComdat();
-  return !Comdat.empty() && Symtab->findComdat(Comdat) != this;
+  StringRef S = Chunk->getComdat();
+  if (S.empty())
+    return false;
+  return !Symtab->addComdat(S, this);
 }
 
 FunctionSymbol *ObjFile::getFunctionSymbol(uint32_t Index) const {