[lld][WebAssembly] Move input vectors from symtab to ctx. NFC (#78640)

Also convert from std::vector to SmallVector.

This matches the ELF linker where these were moved into the ctx object
in 9a572164d592e and converted to SmallVector in ba948c5a9c524b.

GitOrigin-RevId: 3c5845703c85f221ca12880ce9107a0c44cf7b27
diff --git a/wasm/Config.h b/wasm/Config.h
index cc8a1dc..dc7ca26 100644
--- a/wasm/Config.h
+++ b/wasm/Config.h
@@ -23,6 +23,13 @@
 namespace lld::wasm {
 
 class InputFile;
+class StubFile;
+class ObjFile;
+class SharedFile;
+class BitcodeFile;
+class InputTable;
+class InputGlobal;
+class InputFunction;
 class Symbol;
 
 // For --unresolved-symbols.
@@ -108,6 +115,14 @@
 
 // The Ctx object hold all other (non-configuration) global state.
 struct Ctx {
+  llvm::SmallVector<ObjFile *, 0> objectFiles;
+  llvm::SmallVector<StubFile *, 0> stubFiles;
+  llvm::SmallVector<SharedFile *, 0> sharedFiles;
+  llvm::SmallVector<BitcodeFile *, 0> bitcodeFiles;
+  llvm::SmallVector<InputFunction *, 0> syntheticFunctions;
+  llvm::SmallVector<InputGlobal *, 0> syntheticGlobals;
+  llvm::SmallVector<InputTable *, 0> syntheticTables;
+
   // True if we are creating position-independent code.
   bool isPic;
 
diff --git a/wasm/Driver.cpp b/wasm/Driver.cpp
index 05a9686..4a4f9a9 100644
--- a/wasm/Driver.cpp
+++ b/wasm/Driver.cpp
@@ -899,7 +899,7 @@
 
 static void processStubLibrariesPreLTO() {
   log("-- processStubLibrariesPreLTO");
-  for (auto &stub_file : symtab->stubFiles) {
+  for (auto &stub_file : ctx.stubFiles) {
     LLVM_DEBUG(llvm::dbgs()
                << "processing stub file: " << stub_file->getName() << "\n");
     for (auto [name, deps]: stub_file->symbolDependencies) {
@@ -924,7 +924,7 @@
   bool depsAdded = false;
   do {
     depsAdded = false;
-    for (auto &stub_file : symtab->stubFiles) {
+    for (auto &stub_file : ctx.stubFiles) {
       LLVM_DEBUG(llvm::dbgs()
                  << "processing stub file: " << stub_file->getName() << "\n");
       for (auto [name, deps]: stub_file->symbolDependencies) {
@@ -1075,7 +1075,7 @@
   }
 
   // Update pointers in input files.
-  parallelForEach(symtab->objectFiles, [&](InputFile *file) {
+  parallelForEach(ctx.objectFiles, [&](InputFile *file) {
     MutableArrayRef<Symbol *> syms = file->getMutableSymbols();
     for (size_t i = 0, e = syms.size(); i != e; ++i)
       if (Symbol *s = map.lookup(syms[i]))
@@ -1091,7 +1091,7 @@
   // splitIntoPieces needs to be called on each MergeInputChunk
   // before calling finalizeContents().
   LLVM_DEBUG(llvm::dbgs() << "splitSections\n");
-  parallelForEach(symtab->objectFiles, [](ObjFile *file) {
+  parallelForEach(ctx.objectFiles, [](ObjFile *file) {
     for (InputChunk *seg : file->segments) {
       if (auto *s = dyn_cast<MergeInputChunk>(seg))
         s->splitIntoPieces();
@@ -1263,7 +1263,7 @@
   // We only need to add libcall symbols to the link before LTO if the symbol's
   // definition is in bitcode. Any other required libcall symbols will be added
   // to the link after LTO when we add the LTO object file to the link.
-  if (!symtab->bitcodeFiles.empty())
+  if (!ctx.bitcodeFiles.empty())
     for (auto *s : lto::LTO::getRuntimeLibcallSymbols())
       handleLibcall(s);
   if (errorCount())
diff --git a/wasm/MapFile.cpp b/wasm/MapFile.cpp
index 288c189..c96b64c 100644
--- a/wasm/MapFile.cpp
+++ b/wasm/MapFile.cpp
@@ -51,7 +51,7 @@
 // Returns a list of all symbols that we want to print out.
 static std::vector<Symbol *> getSymbols() {
   std::vector<Symbol *> v;
-  for (InputFile *file : symtab->objectFiles)
+  for (InputFile *file : ctx.objectFiles)
     for (Symbol *b : file->getSymbols())
       if (auto *dr = dyn_cast<Symbol>(b))
         if ((!isa<SectionSymbol>(dr)) && dr->isLive() &&
diff --git a/wasm/MarkLive.cpp b/wasm/MarkLive.cpp
index 773af2f..b8ab774 100644
--- a/wasm/MarkLive.cpp
+++ b/wasm/MarkLive.cpp
@@ -97,7 +97,7 @@
     enqueue(WasmSym::callDtors);
 
   // Enqueue constructors in objects explicitly live from the command-line.
-  for (const ObjFile *obj : symtab->objectFiles)
+  for (const ObjFile *obj : ctx.objectFiles)
     if (obj->isLive())
       enqueueInitFunctions(obj);
 
@@ -151,7 +151,7 @@
 
   // Report garbage-collected sections.
   if (config->printGcSections) {
-    for (const ObjFile *obj : symtab->objectFiles) {
+    for (const ObjFile *obj : ctx.objectFiles) {
       for (InputChunk *c : obj->functions)
         if (!c->live)
           message("removing unused section " + toString(c));
@@ -168,13 +168,13 @@
         if (!t->live)
           message("removing unused section " + toString(t));
     }
-    for (InputChunk *c : symtab->syntheticFunctions)
+    for (InputChunk *c : ctx.syntheticFunctions)
       if (!c->live)
         message("removing unused section " + toString(c));
-    for (InputGlobal *g : symtab->syntheticGlobals)
+    for (InputGlobal *g : ctx.syntheticGlobals)
       if (!g->live)
         message("removing unused section " + toString(g));
-    for (InputTable *t : symtab->syntheticTables)
+    for (InputTable *t : ctx.syntheticTables)
       if (!t->live)
         message("removing unused section " + toString(t));
   }
@@ -192,7 +192,7 @@
 
   // If there are any init functions, mark `__wasm_call_ctors` live so that
   // it can call them.
-  for (const ObjFile *file : symtab->objectFiles) {
+  for (const ObjFile *file : ctx.objectFiles) {
     const WasmLinkingData &l = file->getWasmObj()->linkingData();
     for (const WasmInitFunc &f : l.InitFunctions) {
       auto *sym = file->getFunctionSymbol(f.Symbol);
diff --git a/wasm/SymbolTable.cpp b/wasm/SymbolTable.cpp
index 9dd599e..9988490 100644
--- a/wasm/SymbolTable.cpp
+++ b/wasm/SymbolTable.cpp
@@ -34,14 +34,14 @@
 
   // .so file
   if (auto *f = dyn_cast<SharedFile>(file)) {
-    sharedFiles.push_back(f);
+    ctx.sharedFiles.push_back(f);
     return;
   }
 
   // stub file
   if (auto *f = dyn_cast<StubFile>(file)) {
     f->parse();
-    stubFiles.push_back(f);
+    ctx.stubFiles.push_back(f);
     return;
   }
 
@@ -52,7 +52,7 @@
   if (auto *f = dyn_cast<BitcodeFile>(file)) {
     // This order, first adding to `bitcodeFiles` and then parsing is necessary.
     // See https://github.com/llvm/llvm-project/pull/73095
-    bitcodeFiles.push_back(f);
+    ctx.bitcodeFiles.push_back(f);
     f->parse(symName);
     return;
   }
@@ -60,7 +60,7 @@
   // Regular object file
   auto *f = cast<ObjFile>(file);
   f->parse(false);
-  objectFiles.push_back(f);
+  ctx.objectFiles.push_back(f);
 }
 
 // This function is where all the optimizations of link-time
@@ -74,18 +74,18 @@
   // Prevent further LTO objects being included
   BitcodeFile::doneLTO = true;
 
-  if (bitcodeFiles.empty())
+  if (ctx.bitcodeFiles.empty())
     return;
 
   // Compile bitcode files and replace bitcode symbols.
   lto.reset(new BitcodeCompiler);
-  for (BitcodeFile *f : bitcodeFiles)
+  for (BitcodeFile *f : ctx.bitcodeFiles)
     lto->add(*f);
 
   for (StringRef filename : lto->compile()) {
     auto *obj = make<ObjFile>(MemoryBufferRef(filename, "lto.tmp"), "");
     obj->parse(true);
-    objectFiles.push_back(obj);
+    ctx.objectFiles.push_back(obj);
   }
 }
 
@@ -218,7 +218,7 @@
                                                    InputFunction *function) {
   LLVM_DEBUG(dbgs() << "addSyntheticFunction: " << name << "\n");
   assert(!find(name));
-  syntheticFunctions.emplace_back(function);
+  ctx.syntheticFunctions.emplace_back(function);
   return replaceSymbol<DefinedFunction>(insertName(name).first, name,
                                         flags, nullptr, function);
 }
@@ -255,7 +255,7 @@
   LLVM_DEBUG(dbgs() << "addSyntheticGlobal: " << name << " -> " << global
                     << "\n");
   assert(!find(name));
-  syntheticGlobals.emplace_back(global);
+  ctx.syntheticGlobals.emplace_back(global);
   return replaceSymbol<DefinedGlobal>(insertName(name).first, name, flags,
                                       nullptr, global);
 }
@@ -267,7 +267,7 @@
     return nullptr;
   LLVM_DEBUG(dbgs() << "addOptionalGlobalSymbol: " << name << " -> " << global
                     << "\n");
-  syntheticGlobals.emplace_back(global);
+  ctx.syntheticGlobals.emplace_back(global);
   return replaceSymbol<DefinedGlobal>(s, name, WASM_SYMBOL_VISIBILITY_HIDDEN,
                                       nullptr, global);
 }
@@ -280,7 +280,7 @@
   assert(!s || s->isUndefined());
   if (!s)
     s = insertName(name).first;
-  syntheticTables.emplace_back(table);
+  ctx.syntheticTables.emplace_back(table);
   return replaceSymbol<DefinedTable>(s, name, flags, nullptr, table);
 }
 
@@ -855,7 +855,7 @@
                                                    StringRef debugName) {
   auto *func = make<SyntheticFunction>(sig, sym->getName(), debugName);
   func->setBody(unreachableFn);
-  syntheticFunctions.emplace_back(func);
+  ctx.syntheticFunctions.emplace_back(func);
   // Mark new symbols as local. For relocatable output we don't want them
   // to be exported outside the object file.
   replaceSymbol<DefinedFunction>(sym, debugName, WASM_SYMBOL_BINDING_LOCAL,
diff --git a/wasm/SymbolTable.h b/wasm/SymbolTable.h
index 59eda1c..c5518ee 100644
--- a/wasm/SymbolTable.h
+++ b/wasm/SymbolTable.h
@@ -101,14 +101,6 @@
   void handleWeakUndefines();
   DefinedFunction *createUndefinedStub(const WasmSignature &sig);
 
-  std::vector<ObjFile *> objectFiles;
-  std::vector<StubFile *> stubFiles;
-  std::vector<SharedFile *> sharedFiles;
-  std::vector<BitcodeFile *> bitcodeFiles;
-  std::vector<InputFunction *> syntheticFunctions;
-  std::vector<InputGlobal *> syntheticGlobals;
-  std::vector<InputTable *> syntheticTables;
-
 private:
   std::pair<Symbol *, bool> insert(StringRef name, const InputFile *file);
   std::pair<Symbol *, bool> insertName(StringRef name);
diff --git a/wasm/SyntheticSections.cpp b/wasm/SyntheticSections.cpp
index f95174f..72e2559 100644
--- a/wasm/SyntheticSections.cpp
+++ b/wasm/SyntheticSections.cpp
@@ -57,7 +57,7 @@
 bool DylinkSection::isNeeded() const {
   return ctx.isPic ||
          config->unresolvedSymbols == UnresolvedPolicy::ImportDynamic ||
-         !symtab->sharedFiles.empty();
+         !ctx.sharedFiles.empty();
 }
 
 void DylinkSection::writeBody() {
@@ -72,10 +72,10 @@
     sub.writeTo(os);
   }
 
-  if (symtab->sharedFiles.size()) {
+  if (ctx.sharedFiles.size()) {
     SubSection sub(WASM_DYLINK_NEEDED);
-    writeUleb128(sub.os, symtab->sharedFiles.size(), "Needed");
-    for (auto *so : symtab->sharedFiles)
+    writeUleb128(sub.os, ctx.sharedFiles.size(), "Needed");
+    for (auto *so : ctx.sharedFiles)
       writeStr(sub.os, llvm::sys::path::filename(so->getName()), "so name");
     sub.writeTo(os);
   }
diff --git a/wasm/Writer.cpp b/wasm/Writer.cpp
index 7c19a1b..d1a06c9 100644
--- a/wasm/Writer.cpp
+++ b/wasm/Writer.cpp
@@ -133,7 +133,7 @@
 void Writer::calculateCustomSections() {
   log("calculateCustomSections");
   bool stripDebug = config->stripDebug || config->stripAll;
-  for (ObjFile *file : symtab->objectFiles) {
+  for (ObjFile *file : ctx.objectFiles) {
     for (InputChunk *section : file->customSections) {
       // Exclude COMDAT sections that are not selected for inclusion
       if (section->discarded)
@@ -207,7 +207,7 @@
 }
 
 void Writer::populateProducers() {
-  for (ObjFile *file : symtab->objectFiles) {
+  for (ObjFile *file : ctx.objectFiles) {
     const WasmProducerInfo &info = file->getWasmObj()->getProducerInfo();
     out.producersSec->addInfo(info);
   }
@@ -591,7 +591,7 @@
   }
 
   // Find the sets of used, required, and disallowed features
-  for (ObjFile *file : symtab->objectFiles) {
+  for (ObjFile *file : ctx.objectFiles) {
     StringRef fileName(file->getName());
     for (auto &feature : file->getWasmObj()->getTargetFeatures()) {
       switch (feature.Prefix) {
@@ -654,7 +654,7 @@
   }
 
   // Validate the required and disallowed constraints for each file
-  for (ObjFile *file : symtab->objectFiles) {
+  for (ObjFile *file : ctx.objectFiles) {
     StringRef fileName(file->getName());
     SmallSet<std::string, 8> objectFeatures;
     for (const auto &feature : file->getWasmObj()->getTargetFeatures()) {
@@ -832,7 +832,7 @@
     if (sym->isUsedInRegularObj && sym->isLive())
       out.linkingSec->addToSymtab(sym);
 
-  for (ObjFile *file : symtab->objectFiles) {
+  for (ObjFile *file : ctx.objectFiles) {
     LLVM_DEBUG(dbgs() << "Local symtab entries: " << file->getName() << "\n");
     for (Symbol *sym : file->getSymbols())
       if (sym->isLocal() && !isa<SectionSymbol>(sym) && sym->isLive())
@@ -848,7 +848,7 @@
   // 4. The signatures of all imported tags
   // 5. The signatures of all defined tags
 
-  for (ObjFile *file : symtab->objectFiles) {
+  for (ObjFile *file : ctx.objectFiles) {
     ArrayRef<WasmSignature> types = file->getWasmObj()->types();
     for (uint32_t i = 0; i < types.size(); i++)
       if (file->typeIsUsed[i])
@@ -939,7 +939,7 @@
 }
 
 static void scanRelocations() {
-  for (ObjFile *file : symtab->objectFiles) {
+  for (ObjFile *file : ctx.objectFiles) {
     LLVM_DEBUG(dbgs() << "scanRelocations: " << file->getName() << "\n");
     for (InputChunk *chunk : file->functions)
       scanRelocations(chunk);
@@ -955,37 +955,37 @@
   // global are effected by the number of imports.
   out.importSec->seal();
 
-  for (InputFunction *func : symtab->syntheticFunctions)
+  for (InputFunction *func : ctx.syntheticFunctions)
     out.functionSec->addFunction(func);
 
-  for (ObjFile *file : symtab->objectFiles) {
+  for (ObjFile *file : ctx.objectFiles) {
     LLVM_DEBUG(dbgs() << "Functions: " << file->getName() << "\n");
     for (InputFunction *func : file->functions)
       out.functionSec->addFunction(func);
   }
 
-  for (InputGlobal *global : symtab->syntheticGlobals)
+  for (InputGlobal *global : ctx.syntheticGlobals)
     out.globalSec->addGlobal(global);
 
-  for (ObjFile *file : symtab->objectFiles) {
+  for (ObjFile *file : ctx.objectFiles) {
     LLVM_DEBUG(dbgs() << "Globals: " << file->getName() << "\n");
     for (InputGlobal *global : file->globals)
       out.globalSec->addGlobal(global);
   }
 
-  for (ObjFile *file : symtab->objectFiles) {
+  for (ObjFile *file : ctx.objectFiles) {
     LLVM_DEBUG(dbgs() << "Tags: " << file->getName() << "\n");
     for (InputTag *tag : file->tags)
       out.tagSec->addTag(tag);
   }
 
-  for (ObjFile *file : symtab->objectFiles) {
+  for (ObjFile *file : ctx.objectFiles) {
     LLVM_DEBUG(dbgs() << "Tables: " << file->getName() << "\n");
     for (InputTable *table : file->tables)
       out.tableSec->addTable(table);
   }
 
-  for (InputTable *table : symtab->syntheticTables)
+  for (InputTable *table : ctx.syntheticTables)
     out.tableSec->addTable(table);
 
   out.globalSec->assignIndexes();
@@ -1022,7 +1022,7 @@
 }
 
 void Writer::createOutputSegments() {
-  for (ObjFile *file : symtab->objectFiles) {
+  for (ObjFile *file : ctx.objectFiles) {
     for (InputChunk *segment : file->segments) {
       if (!segment->live)
         continue;
@@ -1639,7 +1639,7 @@
   if (!config->relocatable && !WasmSym::callCtors->isLive())
     return;
 
-  for (ObjFile *file : symtab->objectFiles) {
+  for (ObjFile *file : ctx.objectFiles) {
     const WasmLinkingData &l = file->getWasmObj()->linkingData();
     for (const WasmInitFunc &f : l.InitFunctions) {
       FunctionSymbol *sym = file->getFunctionSymbol(f.Symbol);