1 //===- InputFiles.cpp -----------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #include "InputFiles.h"
10 #include "Config.h"
11 #include "InputChunks.h"
12 #include "InputEvent.h"
13 #include "InputGlobal.h"
14 #include "SymbolTable.h"
15 #include "lld/Common/ErrorHandler.h"
16 #include "lld/Common/Memory.h"
17 #include "lld/Common/Reproduce.h"
18 #include "llvm/Object/Binary.h"
19 #include "llvm/Object/Wasm.h"
20 #include "llvm/Support/TarWriter.h"
21 #include "llvm/Support/raw_ostream.h"
22 
23 #define DEBUG_TYPE "lld"
24 
25 using namespace llvm;
26 using namespace llvm::object;
27 using namespace llvm::wasm;
28 
29 namespace lld {
30 
31 // Returns a string in the format of "foo.o" or "foo.a(bar.o)".
32 std::string toString(const wasm::InputFile *file) {
33   if (!file)
34     return "<internal>";
35 
36   if (file->archiveName.empty())
37     return std::string(file->getName());
38 
39   return (file->archiveName + "(" + file->getName() + ")").str();
40 }
41 
42 namespace wasm {
43 std::unique_ptr<llvm::TarWriter> tar;
44 
45 Optional<MemoryBufferRef> readFile(StringRef path) {
46   log("Loading: " + path);
47 
48   auto mbOrErr = MemoryBuffer::getFile(path);
49   if (auto ec = mbOrErr.getError()) {
50     error("cannot open " + path + ": " + ec.message());
51     return None;
52   }
53   std::unique_ptr<MemoryBuffer> &mb = *mbOrErr;
54   MemoryBufferRef mbref = mb->getMemBufferRef();
55   make<std::unique_ptr<MemoryBuffer>>(std::move(mb)); // take MB ownership
56 
57   if (tar)
58     tar->append(relativeToRoot(path), mbref.getBuffer());
59   return mbref;
60 }
61 
62 InputFile *createObjectFile(MemoryBufferRef mb,
63                                        StringRef archiveName) {
64   file_magic magic = identify_magic(mb.getBuffer());
65   if (magic == file_magic::wasm_object) {
66     std::unique_ptr<Binary> bin =
67         CHECK(createBinary(mb), mb.getBufferIdentifier());
68     auto *obj = cast<WasmObjectFile>(bin.get());
69     if (obj->isSharedObject())
70       return make<SharedFile>(mb);
71     return make<ObjFile>(mb, archiveName);
72   }
73 
74   if (magic == file_magic::bitcode)
75     return make<BitcodeFile>(mb, archiveName);
76 
77   fatal("unknown file type: " + mb.getBufferIdentifier());
78 }
79 
80 void ObjFile::dumpInfo() const {
81   log("info for: " + toString(this) +
82       "\n              Symbols : " + Twine(symbols.size()) +
83       "\n     Function Imports : " + Twine(wasmObj->getNumImportedFunctions()) +
84       "\n       Global Imports : " + Twine(wasmObj->getNumImportedGlobals()) +
85       "\n        Event Imports : " + Twine(wasmObj->getNumImportedEvents()));
86 }
87 
88 // Relocations contain either symbol or type indices.  This function takes a
89 // relocation and returns relocated index (i.e. translates from the input
90 // symbol/type space to the output symbol/type space).
91 uint32_t ObjFile::calcNewIndex(const WasmRelocation &reloc) const {
92   if (reloc.Type == R_WASM_TYPE_INDEX_LEB) {
93     assert(typeIsUsed[reloc.Index]);
94     return typeMap[reloc.Index];
95   }
96   const Symbol *sym = symbols[reloc.Index];
97   if (auto *ss = dyn_cast<SectionSymbol>(sym))
98     sym = ss->getOutputSectionSymbol();
99   return sym->getOutputSymbolIndex();
100 }
101 
102 // Relocations can contain addend for combined sections. This function takes a
103 // relocation and returns updated addend by offset in the output section.
104 uint32_t ObjFile::calcNewAddend(const WasmRelocation &reloc) const {
105   switch (reloc.Type) {
106   case R_WASM_MEMORY_ADDR_LEB:
107   case R_WASM_MEMORY_ADDR_SLEB:
108   case R_WASM_MEMORY_ADDR_REL_SLEB:
109   case R_WASM_MEMORY_ADDR_I32:
110   case R_WASM_FUNCTION_OFFSET_I32:
111     return reloc.Addend;
112   case R_WASM_SECTION_OFFSET_I32:
113     return getSectionSymbol(reloc.Index)->section->outputOffset + reloc.Addend;
114   default:
115     llvm_unreachable("unexpected relocation type");
116   }
117 }
118 
119 // Calculate the value we expect to find at the relocation location.
120 // This is used as a sanity check before applying a relocation to a given
121 // location.  It is useful for catching bugs in the compiler and linker.
122 uint32_t ObjFile::calcExpectedValue(const WasmRelocation &reloc) const {
123   switch (reloc.Type) {
124   case R_WASM_TABLE_INDEX_I32:
125   case R_WASM_TABLE_INDEX_SLEB: {
126     const WasmSymbol &sym = wasmObj->syms()[reloc.Index];
127     return tableEntries[sym.Info.ElementIndex];
128   }
129   case R_WASM_TABLE_INDEX_REL_SLEB: {
130     const WasmSymbol &sym = wasmObj->syms()[reloc.Index];
131     return tableEntriesRel[sym.Info.ElementIndex];
132   }
133   case R_WASM_MEMORY_ADDR_SLEB:
134   case R_WASM_MEMORY_ADDR_I32:
135   case R_WASM_MEMORY_ADDR_LEB:
136   case R_WASM_MEMORY_ADDR_REL_SLEB: {
137     const WasmSymbol &sym = wasmObj->syms()[reloc.Index];
138     if (sym.isUndefined())
139       return 0;
140     const WasmSegment &segment =
141         wasmObj->dataSegments()[sym.Info.DataRef.Segment];
142     return segment.Data.Offset.Value.Int32 + sym.Info.DataRef.Offset +
143            reloc.Addend;
144   }
145   case R_WASM_FUNCTION_OFFSET_I32: {
146     const WasmSymbol &sym = wasmObj->syms()[reloc.Index];
147     InputFunction *f =
148         functions[sym.Info.ElementIndex - wasmObj->getNumImportedFunctions()];
149     return f->getFunctionInputOffset() + f->getFunctionCodeOffset() +
150            reloc.Addend;
151   }
152   case R_WASM_SECTION_OFFSET_I32:
153     return reloc.Addend;
154   case R_WASM_TYPE_INDEX_LEB:
155     return reloc.Index;
156   case R_WASM_FUNCTION_INDEX_LEB:
157   case R_WASM_GLOBAL_INDEX_LEB:
158   case R_WASM_GLOBAL_INDEX_I32:
159   case R_WASM_EVENT_INDEX_LEB: {
160     const WasmSymbol &sym = wasmObj->syms()[reloc.Index];
161     return sym.Info.ElementIndex;
162   }
163   default:
164     llvm_unreachable("unknown relocation type");
165   }
166 }
167 
168 // Translate from the relocation's index into the final linked output value.
169 uint32_t ObjFile::calcNewValue(const WasmRelocation &reloc) const {
170   const Symbol* sym = nullptr;
171   if (reloc.Type != R_WASM_TYPE_INDEX_LEB) {
172     sym = symbols[reloc.Index];
173 
174     // We can end up with relocations against non-live symbols.  For example
175     // in debug sections. We return reloc.Addend because always returning zero
176     // causes the generation of spurious range-list terminators in the
177     // .debug_ranges section.
178     if ((isa<FunctionSymbol>(sym) || isa<DataSymbol>(sym)) && !sym->isLive())
179       return reloc.Addend;
180   }
181 
182   switch (reloc.Type) {
183   case R_WASM_TABLE_INDEX_I32:
184   case R_WASM_TABLE_INDEX_SLEB:
185   case R_WASM_TABLE_INDEX_REL_SLEB: {
186     if (!getFunctionSymbol(reloc.Index)->hasTableIndex())
187       return 0;
188     uint32_t index = getFunctionSymbol(reloc.Index)->getTableIndex();
189     if (reloc.Type == R_WASM_TABLE_INDEX_REL_SLEB)
190       index -= config->tableBase;
191     return index;
192 
193   }
194   case R_WASM_MEMORY_ADDR_SLEB:
195   case R_WASM_MEMORY_ADDR_I32:
196   case R_WASM_MEMORY_ADDR_LEB:
197   case R_WASM_MEMORY_ADDR_REL_SLEB:
198     if (isa<UndefinedData>(sym) || sym->isUndefWeak())
199       return 0;
200     return cast<DefinedData>(sym)->getVirtualAddress() + reloc.Addend;
201   case R_WASM_TYPE_INDEX_LEB:
202     return typeMap[reloc.Index];
203   case R_WASM_FUNCTION_INDEX_LEB:
204     return getFunctionSymbol(reloc.Index)->getFunctionIndex();
205   case R_WASM_GLOBAL_INDEX_LEB:
206   case R_WASM_GLOBAL_INDEX_I32:
207     if (auto gs = dyn_cast<GlobalSymbol>(sym))
208       return gs->getGlobalIndex();
209     return sym->getGOTIndex();
210   case R_WASM_EVENT_INDEX_LEB:
211     return getEventSymbol(reloc.Index)->getEventIndex();
212   case R_WASM_FUNCTION_OFFSET_I32: {
213     auto *f = cast<DefinedFunction>(sym);
214     return f->function->outputOffset + f->function->getFunctionCodeOffset() +
215            reloc.Addend;
216   }
217   case R_WASM_SECTION_OFFSET_I32:
218     return getSectionSymbol(reloc.Index)->section->outputOffset + reloc.Addend;
219   default:
220     llvm_unreachable("unknown relocation type");
221   }
222 }
223 
224 template <class T>
225 static void setRelocs(const std::vector<T *> &chunks,
226                       const WasmSection *section) {
227   if (!section)
228     return;
229 
230   ArrayRef<WasmRelocation> relocs = section->Relocations;
231   assert(llvm::is_sorted(
232       relocs, [](const WasmRelocation &r1, const WasmRelocation &r2) {
233         return r1.Offset < r2.Offset;
234       }));
235   assert(llvm::is_sorted(chunks, [](InputChunk *c1, InputChunk *c2) {
236     return c1->getInputSectionOffset() < c2->getInputSectionOffset();
237   }));
238 
239   auto relocsNext = relocs.begin();
240   auto relocsEnd = relocs.end();
241   auto relocLess = [](const WasmRelocation &r, uint32_t val) {
242     return r.Offset < val;
243   };
244   for (InputChunk *c : chunks) {
245     auto relocsStart = std::lower_bound(relocsNext, relocsEnd,
246                                         c->getInputSectionOffset(), relocLess);
247     relocsNext = std::lower_bound(
248         relocsStart, relocsEnd, c->getInputSectionOffset() + c->getInputSize(),
249         relocLess);
250     c->setRelocations(ArrayRef<WasmRelocation>(relocsStart, relocsNext));
251   }
252 }
253 
254 void ObjFile::parse(bool ignoreComdats) {
255   // Parse a memory buffer as a wasm file.
256   LLVM_DEBUG(dbgs() << "Parsing object: " << toString(this) << "\n");
257   std::unique_ptr<Binary> bin = CHECK(createBinary(mb), toString(this));
258 
259   auto *obj = dyn_cast<WasmObjectFile>(bin.get());
260   if (!obj)
261     fatal(toString(this) + ": not a wasm file");
262   if (!obj->isRelocatableObject())
263     fatal(toString(this) + ": not a relocatable wasm file");
264 
265   bin.release();
266   wasmObj.reset(obj);
267 
268   // Build up a map of function indices to table indices for use when
269   // verifying the existing table index relocations
270   uint32_t totalFunctions =
271       wasmObj->getNumImportedFunctions() + wasmObj->functions().size();
272   tableEntriesRel.resize(totalFunctions);
273   tableEntries.resize(totalFunctions);
274   for (const WasmElemSegment &seg : wasmObj->elements()) {
275     if (seg.Offset.Opcode != WASM_OPCODE_I32_CONST)
276       fatal(toString(this) + ": invalid table elements");
277     uint32_t offset = seg.Offset.Value.Int32;
278     for (uint32_t index = 0; index < seg.Functions.size(); index++) {
279 
280       uint32_t functionIndex = seg.Functions[index];
281       tableEntriesRel[functionIndex] = index;
282       tableEntries[functionIndex] = offset + index;
283     }
284   }
285 
286   uint32_t sectionIndex = 0;
287 
288   // Bool for each symbol, true if called directly.  This allows us to implement
289   // a weaker form of signature checking where undefined functions that are not
290   // called directly (i.e. only address taken) don't have to match the defined
291   // function's signature.  We cannot do this for directly called functions
292   // because those signatures are checked at validation times.
293   // See https://bugs.llvm.org/show_bug.cgi?id=40412
294   std::vector<bool> isCalledDirectly(wasmObj->getNumberOfSymbols(), false);
295   for (const SectionRef &sec : wasmObj->sections()) {
296     const WasmSection &section = wasmObj->getWasmSection(sec);
297     // Wasm objects can have at most one code and one data section.
298     if (section.Type == WASM_SEC_CODE) {
299       assert(!codeSection);
300       codeSection = &section;
301     } else if (section.Type == WASM_SEC_DATA) {
302       assert(!dataSection);
303       dataSection = &section;
304     } else if (section.Type == WASM_SEC_CUSTOM) {
305       customSections.emplace_back(make<InputSection>(section, this));
306       customSections.back()->setRelocations(section.Relocations);
307       customSectionsByIndex[sectionIndex] = customSections.back();
308     }
309     sectionIndex++;
310     // Scans relocations to determine if a function symbol is called directly.
311     for (const WasmRelocation &reloc : section.Relocations)
312       if (reloc.Type == R_WASM_FUNCTION_INDEX_LEB)
313         isCalledDirectly[reloc.Index] = true;
314   }
315 
316   typeMap.resize(getWasmObj()->types().size());
317   typeIsUsed.resize(getWasmObj()->types().size(), false);
318 
319   ArrayRef<StringRef> comdats = wasmObj->linkingData().Comdats;
320   for (StringRef comdat : comdats) {
321     bool isNew = ignoreComdats || symtab->addComdat(comdat);
322     keptComdats.push_back(isNew);
323   }
324 
325   // Populate `Segments`.
326   for (const WasmSegment &s : wasmObj->dataSegments()) {
327     auto* seg = make<InputSegment>(s, this);
328     seg->discarded = isExcludedByComdat(seg);
329     segments.emplace_back(seg);
330   }
331   setRelocs(segments, dataSection);
332 
333   // Populate `Functions`.
334   ArrayRef<WasmFunction> funcs = wasmObj->functions();
335   ArrayRef<uint32_t> funcTypes = wasmObj->functionTypes();
336   ArrayRef<WasmSignature> types = wasmObj->types();
337   functions.reserve(funcs.size());
338 
339   for (size_t i = 0, e = funcs.size(); i != e; ++i) {
340     auto* func = make<InputFunction>(types[funcTypes[i]], &funcs[i], this);
341     func->discarded = isExcludedByComdat(func);
342     functions.emplace_back(func);
343   }
344   setRelocs(functions, codeSection);
345 
346   // Populate `Globals`.
347   for (const WasmGlobal &g : wasmObj->globals())
348     globals.emplace_back(make<InputGlobal>(g, this));
349 
350   // Populate `Events`.
351   for (const WasmEvent &e : wasmObj->events())
352     events.emplace_back(make<InputEvent>(types[e.Type.SigIndex], e, this));
353 
354   // Populate `Symbols` based on the symbols in the object.
355   symbols.reserve(wasmObj->getNumberOfSymbols());
356   for (const SymbolRef &sym : wasmObj->symbols()) {
357     const WasmSymbol &wasmSym = wasmObj->getWasmSymbol(sym.getRawDataRefImpl());
358     if (wasmSym.isDefined()) {
359       // createDefined may fail if the symbol is comdat excluded in which case
360       // we fall back to creating an undefined symbol
361       if (Symbol *d = createDefined(wasmSym)) {
362         symbols.push_back(d);
363         continue;
364       }
365     }
366     size_t idx = symbols.size();
367     symbols.push_back(createUndefined(wasmSym, isCalledDirectly[idx]));
368   }
369 }
370 
371 bool ObjFile::isExcludedByComdat(InputChunk *chunk) const {
372   uint32_t c = chunk->getComdat();
373   if (c == UINT32_MAX)
374     return false;
375   return !keptComdats[c];
376 }
377 
378 FunctionSymbol *ObjFile::getFunctionSymbol(uint32_t index) const {
379   return cast<FunctionSymbol>(symbols[index]);
380 }
381 
382 GlobalSymbol *ObjFile::getGlobalSymbol(uint32_t index) const {
383   return cast<GlobalSymbol>(symbols[index]);
384 }
385 
386 EventSymbol *ObjFile::getEventSymbol(uint32_t index) const {
387   return cast<EventSymbol>(symbols[index]);
388 }
389 
390 SectionSymbol *ObjFile::getSectionSymbol(uint32_t index) const {
391   return cast<SectionSymbol>(symbols[index]);
392 }
393 
394 DataSymbol *ObjFile::getDataSymbol(uint32_t index) const {
395   return cast<DataSymbol>(symbols[index]);
396 }
397 
398 Symbol *ObjFile::createDefined(const WasmSymbol &sym) {
399   StringRef name = sym.Info.Name;
400   uint32_t flags = sym.Info.Flags;
401 
402   switch (sym.Info.Kind) {
403   case WASM_SYMBOL_TYPE_FUNCTION: {
404     InputFunction *func =
405         functions[sym.Info.ElementIndex - wasmObj->getNumImportedFunctions()];
406     if (sym.isBindingLocal())
407       return make<DefinedFunction>(name, flags, this, func);
408     if (func->discarded)
409       return nullptr;
410     return symtab->addDefinedFunction(name, flags, this, func);
411   }
412   case WASM_SYMBOL_TYPE_DATA: {
413     InputSegment *seg = segments[sym.Info.DataRef.Segment];
414     uint32_t offset = sym.Info.DataRef.Offset;
415     uint32_t size = sym.Info.DataRef.Size;
416     if (sym.isBindingLocal())
417       return make<DefinedData>(name, flags, this, seg, offset, size);
418     if (seg->discarded)
419       return nullptr;
420     return symtab->addDefinedData(name, flags, this, seg, offset, size);
421   }
422   case WASM_SYMBOL_TYPE_GLOBAL: {
423     InputGlobal *global =
424         globals[sym.Info.ElementIndex - wasmObj->getNumImportedGlobals()];
425     if (sym.isBindingLocal())
426       return make<DefinedGlobal>(name, flags, this, global);
427     return symtab->addDefinedGlobal(name, flags, this, global);
428   }
429   case WASM_SYMBOL_TYPE_SECTION: {
430     InputSection *section = customSectionsByIndex[sym.Info.ElementIndex];
431     assert(sym.isBindingLocal());
432     return make<SectionSymbol>(flags, section, this);
433   }
434   case WASM_SYMBOL_TYPE_EVENT: {
435     InputEvent *event =
436         events[sym.Info.ElementIndex - wasmObj->getNumImportedEvents()];
437     if (sym.isBindingLocal())
438       return make<DefinedEvent>(name, flags, this, event);
439     return symtab->addDefinedEvent(name, flags, this, event);
440   }
441   }
442   llvm_unreachable("unknown symbol kind");
443 }
444 
445 Symbol *ObjFile::createUndefined(const WasmSymbol &sym, bool isCalledDirectly) {
446   StringRef name = sym.Info.Name;
447   uint32_t flags = sym.Info.Flags | WASM_SYMBOL_UNDEFINED;
448 
449   switch (sym.Info.Kind) {
450   case WASM_SYMBOL_TYPE_FUNCTION:
451     if (sym.isBindingLocal())
452       return make<UndefinedFunction>(name, sym.Info.ImportName,
453                                      sym.Info.ImportModule, flags, this,
454                                      sym.Signature, isCalledDirectly);
455     return symtab->addUndefinedFunction(name, sym.Info.ImportName,
456                                         sym.Info.ImportModule, flags, this,
457                                         sym.Signature, isCalledDirectly);
458   case WASM_SYMBOL_TYPE_DATA:
459     if (sym.isBindingLocal())
460       return make<UndefinedData>(name, flags, this);
461     return symtab->addUndefinedData(name, flags, this);
462   case WASM_SYMBOL_TYPE_GLOBAL:
463     if (sym.isBindingLocal())
464       return make<UndefinedGlobal>(name, sym.Info.ImportName,
465                                    sym.Info.ImportModule, flags, this,
466                                    sym.GlobalType);
467     return symtab->addUndefinedGlobal(name, sym.Info.ImportName,
468                                       sym.Info.ImportModule, flags, this,
469                                       sym.GlobalType);
470   case WASM_SYMBOL_TYPE_SECTION:
471     llvm_unreachable("section symbols cannot be undefined");
472   }
473   llvm_unreachable("unknown symbol kind");
474 }
475 
476 void ArchiveFile::parse() {
477   // Parse a MemoryBufferRef as an archive file.
478   LLVM_DEBUG(dbgs() << "Parsing library: " << toString(this) << "\n");
479   file = CHECK(Archive::create(mb), toString(this));
480 
481   // Read the symbol table to construct Lazy symbols.
482   int count = 0;
483   for (const Archive::Symbol &sym : file->symbols()) {
484     symtab->addLazy(this, &sym);
485     ++count;
486   }
487   LLVM_DEBUG(dbgs() << "Read " << count << " symbols\n");
488 }
489 
490 void ArchiveFile::addMember(const Archive::Symbol *sym) {
491   const Archive::Child &c =
492       CHECK(sym->getMember(),
493             "could not get the member for symbol " + sym->getName());
494 
495   // Don't try to load the same member twice (this can happen when members
496   // mutually reference each other).
497   if (!seen.insert(c.getChildOffset()).second)
498     return;
499 
500   LLVM_DEBUG(dbgs() << "loading lazy: " << sym->getName() << "\n");
501   LLVM_DEBUG(dbgs() << "from archive: " << toString(this) << "\n");
502 
503   MemoryBufferRef mb =
504       CHECK(c.getMemoryBufferRef(),
505             "could not get the buffer for the member defining symbol " +
506                 sym->getName());
507 
508   InputFile *obj = createObjectFile(mb, getName());
509   symtab->addFile(obj);
510 }
511 
512 static uint8_t mapVisibility(GlobalValue::VisibilityTypes gvVisibility) {
513   switch (gvVisibility) {
514   case GlobalValue::DefaultVisibility:
515     return WASM_SYMBOL_VISIBILITY_DEFAULT;
516   case GlobalValue::HiddenVisibility:
517   case GlobalValue::ProtectedVisibility:
518     return WASM_SYMBOL_VISIBILITY_HIDDEN;
519   }
520   llvm_unreachable("unknown visibility");
521 }
522 
523 static Symbol *createBitcodeSymbol(const std::vector<bool> &keptComdats,
524                                    const lto::InputFile::Symbol &objSym,
525                                    BitcodeFile &f) {
526   StringRef name = saver.save(objSym.getName());
527 
528   uint32_t flags = objSym.isWeak() ? WASM_SYMBOL_BINDING_WEAK : 0;
529   flags |= mapVisibility(objSym.getVisibility());
530 
531   int c = objSym.getComdatIndex();
532   bool excludedByComdat = c != -1 && !keptComdats[c];
533 
534   if (objSym.isUndefined() || excludedByComdat) {
535     flags |= WASM_SYMBOL_UNDEFINED;
536     if (objSym.isExecutable())
537       return symtab->addUndefinedFunction(name, None, None, flags, &f, nullptr,
538                                           true);
539     return symtab->addUndefinedData(name, flags, &f);
540   }
541 
542   if (objSym.isExecutable())
543     return symtab->addDefinedFunction(name, flags, &f, nullptr);
544   return symtab->addDefinedData(name, flags, &f, nullptr, 0, 0);
545 }
546 
547 bool BitcodeFile::doneLTO = false;
548 
549 void BitcodeFile::parse() {
550   if (doneLTO) {
551     error(toString(mb.getBufferIdentifier()) +
552           ": attempt to add bitcode file after LTO.");
553     return;
554   }
555 
556   obj = check(lto::InputFile::create(MemoryBufferRef(
557       mb.getBuffer(), saver.save(archiveName + mb.getBufferIdentifier()))));
558   Triple t(obj->getTargetTriple());
559   if (t.getArch() != Triple::wasm32) {
560     error(toString(mb.getBufferIdentifier()) + ": machine type must be wasm32");
561     return;
562   }
563   std::vector<bool> keptComdats;
564   for (StringRef s : obj->getComdatTable())
565     keptComdats.push_back(symtab->addComdat(s));
566 
567   for (const lto::InputFile::Symbol &objSym : obj->symbols())
568     symbols.push_back(createBitcodeSymbol(keptComdats, objSym, *this));
569 }
570 
571 } // namespace wasm
572 } // namespace lld
573