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 lld;
26 using namespace lld::wasm;
27 
28 using namespace llvm;
29 using namespace llvm::object;
30 using namespace llvm::wasm;
31 
32 std::unique_ptr<llvm::TarWriter> lld::wasm::Tar;
33 
34 Optional<MemoryBufferRef> lld::wasm::readFile(StringRef Path) {
35   log("Loading: " + Path);
36 
37   auto MBOrErr = MemoryBuffer::getFile(Path);
38   if (auto EC = MBOrErr.getError()) {
39     error("cannot open " + Path + ": " + EC.message());
40     return None;
41   }
42   std::unique_ptr<MemoryBuffer> &MB = *MBOrErr;
43   MemoryBufferRef MBRef = MB->getMemBufferRef();
44   make<std::unique_ptr<MemoryBuffer>>(std::move(MB)); // take MB ownership
45 
46   if (Tar)
47     Tar->append(relativeToRoot(Path), MBRef.getBuffer());
48   return MBRef;
49 }
50 
51 InputFile *lld::wasm::createObjectFile(MemoryBufferRef MB,
52                                        StringRef ArchiveName) {
53   file_magic Magic = identify_magic(MB.getBuffer());
54   if (Magic == file_magic::wasm_object) {
55     std::unique_ptr<Binary> Bin = check(createBinary(MB));
56     auto *Obj = cast<WasmObjectFile>(Bin.get());
57     if (Obj->isSharedObject())
58       return make<SharedFile>(MB);
59     return make<ObjFile>(MB, ArchiveName);
60   }
61 
62   if (Magic == file_magic::bitcode)
63     return make<BitcodeFile>(MB, ArchiveName);
64 
65   fatal("unknown file type: " + MB.getBufferIdentifier());
66 }
67 
68 void ObjFile::dumpInfo() const {
69   log("info for: " + toString(this) +
70       "\n              Symbols : " + Twine(Symbols.size()) +
71       "\n     Function Imports : " + Twine(WasmObj->getNumImportedFunctions()) +
72       "\n       Global Imports : " + Twine(WasmObj->getNumImportedGlobals()) +
73       "\n        Event Imports : " + Twine(WasmObj->getNumImportedEvents()));
74 }
75 
76 // Relocations contain either symbol or type indices.  This function takes a
77 // relocation and returns relocated index (i.e. translates from the input
78 // symbol/type space to the output symbol/type space).
79 uint32_t ObjFile::calcNewIndex(const WasmRelocation &Reloc) const {
80   if (Reloc.Type == R_WASM_TYPE_INDEX_LEB) {
81     assert(TypeIsUsed[Reloc.Index]);
82     return TypeMap[Reloc.Index];
83   }
84   const Symbol *Sym = Symbols[Reloc.Index];
85   if (auto *SS = dyn_cast<SectionSymbol>(Sym))
86     Sym = SS->getOutputSectionSymbol();
87   return Sym->getOutputSymbolIndex();
88 }
89 
90 // Relocations can contain addend for combined sections. This function takes a
91 // relocation and returns updated addend by offset in the output section.
92 uint32_t ObjFile::calcNewAddend(const WasmRelocation &Reloc) const {
93   switch (Reloc.Type) {
94   case R_WASM_MEMORY_ADDR_LEB:
95   case R_WASM_MEMORY_ADDR_SLEB:
96   case R_WASM_MEMORY_ADDR_I32:
97   case R_WASM_FUNCTION_OFFSET_I32:
98     return Reloc.Addend;
99   case R_WASM_SECTION_OFFSET_I32:
100     return getSectionSymbol(Reloc.Index)->Section->OutputOffset + Reloc.Addend;
101   default:
102     llvm_unreachable("unexpected relocation type");
103   }
104 }
105 
106 // Calculate the value we expect to find at the relocation location.
107 // This is used as a sanity check before applying a relocation to a given
108 // location.  It is useful for catching bugs in the compiler and linker.
109 uint32_t ObjFile::calcExpectedValue(const WasmRelocation &Reloc) const {
110   switch (Reloc.Type) {
111   case R_WASM_TABLE_INDEX_I32:
112   case R_WASM_TABLE_INDEX_SLEB:
113   case R_WASM_TABLE_INDEX_REL_SLEB: {
114     const WasmSymbol &Sym = WasmObj->syms()[Reloc.Index];
115     return TableEntries[Sym.Info.ElementIndex];
116   }
117   case R_WASM_MEMORY_ADDR_SLEB:
118   case R_WASM_MEMORY_ADDR_I32:
119   case R_WASM_MEMORY_ADDR_LEB:
120   case R_WASM_MEMORY_ADDR_REL_SLEB: {
121     const WasmSymbol &Sym = WasmObj->syms()[Reloc.Index];
122     if (Sym.isUndefined())
123       return 0;
124     const WasmSegment &Segment =
125         WasmObj->dataSegments()[Sym.Info.DataRef.Segment];
126     return Segment.Data.Offset.Value.Int32 + Sym.Info.DataRef.Offset +
127            Reloc.Addend;
128   }
129   case R_WASM_FUNCTION_OFFSET_I32: {
130     const WasmSymbol &Sym = WasmObj->syms()[Reloc.Index];
131     InputFunction *F =
132         Functions[Sym.Info.ElementIndex - WasmObj->getNumImportedFunctions()];
133     return F->getFunctionInputOffset() + F->getFunctionCodeOffset() +
134            Reloc.Addend;
135   }
136   case R_WASM_SECTION_OFFSET_I32:
137     return Reloc.Addend;
138   case R_WASM_TYPE_INDEX_LEB:
139     return Reloc.Index;
140   case R_WASM_FUNCTION_INDEX_LEB:
141   case R_WASM_GLOBAL_INDEX_LEB:
142   case R_WASM_EVENT_INDEX_LEB: {
143     const WasmSymbol &Sym = WasmObj->syms()[Reloc.Index];
144     return Sym.Info.ElementIndex;
145   }
146   default:
147     llvm_unreachable("unknown relocation type");
148   }
149 }
150 
151 // Translate from the relocation's index into the final linked output value.
152 uint32_t ObjFile::calcNewValue(const WasmRelocation &Reloc) const {
153   const Symbol* Sym = nullptr;
154   if (Reloc.Type != R_WASM_TYPE_INDEX_LEB) {
155     Sym = Symbols[Reloc.Index];
156 
157     // We can end up with relocations against non-live symbols.  For example
158     // in debug sections.
159     if ((isa<FunctionSymbol>(Sym) || isa<DataSymbol>(Sym)) && !Sym->isLive())
160       return 0;
161 
162     // Special handling for undefined data symbols.  Most relocations against
163     // such symbols cannot be resolved.
164     if (isa<DataSymbol>(Sym) && Sym->isUndefined()) {
165       if (Sym->isWeak() || Config->Relocatable)
166         return 0;
167       // R_WASM_MEMORY_ADDR_I32 relocations in PIC code are turned into runtime
168       // fixups in __wasm_apply_relocs
169       if (Config->Pic && Reloc.Type == R_WASM_MEMORY_ADDR_I32)
170         return 0;
171       if (Reloc.Type != R_WASM_GLOBAL_INDEX_LEB) {
172         llvm_unreachable(
173           ("invalid relocation against undefined data symbol: " + toString(*Sym))
174               .c_str());
175       }
176     }
177   }
178 
179   switch (Reloc.Type) {
180   case R_WASM_TABLE_INDEX_I32:
181   case R_WASM_TABLE_INDEX_SLEB:
182   case R_WASM_TABLE_INDEX_REL_SLEB:
183     if (Config->Pic && !getFunctionSymbol(Reloc.Index)->hasTableIndex())
184       return 0;
185     return getFunctionSymbol(Reloc.Index)->getTableIndex();
186   case R_WASM_MEMORY_ADDR_SLEB:
187   case R_WASM_MEMORY_ADDR_I32:
188   case R_WASM_MEMORY_ADDR_LEB:
189   case R_WASM_MEMORY_ADDR_REL_SLEB:
190     return cast<DefinedData>(Sym)->getVirtualAddress() + Reloc.Addend;
191   case R_WASM_TYPE_INDEX_LEB:
192     return TypeMap[Reloc.Index];
193   case R_WASM_FUNCTION_INDEX_LEB:
194     return getFunctionSymbol(Reloc.Index)->getFunctionIndex();
195   case R_WASM_GLOBAL_INDEX_LEB:
196     if (auto GS = dyn_cast<GlobalSymbol>(Sym))
197       return GS->getGlobalIndex();
198     return Sym->getGOTIndex();
199   case R_WASM_EVENT_INDEX_LEB:
200     return getEventSymbol(Reloc.Index)->getEventIndex();
201   case R_WASM_FUNCTION_OFFSET_I32: {
202     auto *F = cast<DefinedFunction>(Sym);
203     return F->Function->OutputOffset + F->Function->getFunctionCodeOffset() +
204            Reloc.Addend;
205   }
206   case R_WASM_SECTION_OFFSET_I32:
207     return getSectionSymbol(Reloc.Index)->Section->OutputOffset + Reloc.Addend;
208   default:
209     llvm_unreachable("unknown relocation type");
210   }
211 }
212 
213 template <class T>
214 static void setRelocs(const std::vector<T *> &Chunks,
215                       const WasmSection *Section) {
216   if (!Section)
217     return;
218 
219   ArrayRef<WasmRelocation> Relocs = Section->Relocations;
220   assert(std::is_sorted(Relocs.begin(), Relocs.end(),
221                         [](const WasmRelocation &R1, const WasmRelocation &R2) {
222                           return R1.Offset < R2.Offset;
223                         }));
224   assert(std::is_sorted(
225       Chunks.begin(), Chunks.end(), [](InputChunk *C1, InputChunk *C2) {
226         return C1->getInputSectionOffset() < C2->getInputSectionOffset();
227       }));
228 
229   auto RelocsNext = Relocs.begin();
230   auto RelocsEnd = Relocs.end();
231   auto RelocLess = [](const WasmRelocation &R, uint32_t Val) {
232     return R.Offset < Val;
233   };
234   for (InputChunk *C : Chunks) {
235     auto RelocsStart = std::lower_bound(RelocsNext, RelocsEnd,
236                                         C->getInputSectionOffset(), RelocLess);
237     RelocsNext = std::lower_bound(
238         RelocsStart, RelocsEnd, C->getInputSectionOffset() + C->getInputSize(),
239         RelocLess);
240     C->setRelocations(ArrayRef<WasmRelocation>(RelocsStart, RelocsNext));
241   }
242 }
243 
244 void ObjFile::parse(bool IgnoreComdats) {
245   // Parse a memory buffer as a wasm file.
246   LLVM_DEBUG(dbgs() << "Parsing object: " << toString(this) << "\n");
247   std::unique_ptr<Binary> Bin = CHECK(createBinary(MB), toString(this));
248 
249   auto *Obj = dyn_cast<WasmObjectFile>(Bin.get());
250   if (!Obj)
251     fatal(toString(this) + ": not a wasm file");
252   if (!Obj->isRelocatableObject())
253     fatal(toString(this) + ": not a relocatable wasm file");
254 
255   Bin.release();
256   WasmObj.reset(Obj);
257 
258   // Build up a map of function indices to table indices for use when
259   // verifying the existing table index relocations
260   uint32_t TotalFunctions =
261       WasmObj->getNumImportedFunctions() + WasmObj->functions().size();
262   TableEntries.resize(TotalFunctions);
263   for (const WasmElemSegment &Seg : WasmObj->elements()) {
264     if (Seg.Offset.Opcode != WASM_OPCODE_I32_CONST)
265       fatal(toString(this) + ": invalid table elements");
266     uint32_t Offset = Seg.Offset.Value.Int32;
267     for (uint32_t Index = 0; Index < Seg.Functions.size(); Index++) {
268 
269       uint32_t FunctionIndex = Seg.Functions[Index];
270       TableEntries[FunctionIndex] = Offset + Index;
271     }
272   }
273 
274   uint32_t SectionIndex = 0;
275   SymbolIsCalledDirectly.resize(WasmObj->getNumberOfSymbols(), false);
276   for (const SectionRef &Sec : WasmObj->sections()) {
277     const WasmSection &Section = WasmObj->getWasmSection(Sec);
278     // Wasm objects can have at most one code and one data section.
279     if (Section.Type == WASM_SEC_CODE) {
280       assert(!CodeSection);
281       CodeSection = &Section;
282     } else if (Section.Type == WASM_SEC_DATA) {
283       assert(!DataSection);
284       DataSection = &Section;
285     } else if (Section.Type == WASM_SEC_CUSTOM) {
286       CustomSections.emplace_back(make<InputSection>(Section, this));
287       CustomSections.back()->setRelocations(Section.Relocations);
288       CustomSectionsByIndex[SectionIndex] = CustomSections.back();
289     }
290     SectionIndex++;
291     // Scans relocations to dermine determine if a function symbol is called
292     // directly
293     for (const WasmRelocation &Reloc : Section.Relocations)
294       if (Reloc.Type == R_WASM_FUNCTION_INDEX_LEB)
295         SymbolIsCalledDirectly[Reloc.Index] = true;
296   }
297 
298   TypeMap.resize(getWasmObj()->types().size());
299   TypeIsUsed.resize(getWasmObj()->types().size(), false);
300 
301   ArrayRef<StringRef> Comdats = WasmObj->linkingData().Comdats;
302   for (unsigned I = 0; I < Comdats.size(); ++I)
303     if (IgnoreComdats)
304       KeptComdats.push_back(true);
305     else
306       KeptComdats.push_back(Symtab->addComdat(Comdats[I]));
307 
308   // Populate `Segments`.
309   for (const WasmSegment &S : WasmObj->dataSegments())
310     Segments.emplace_back(make<InputSegment>(S, this));
311   setRelocs(Segments, DataSection);
312 
313   // Populate `Functions`.
314   ArrayRef<WasmFunction> Funcs = WasmObj->functions();
315   ArrayRef<uint32_t> FuncTypes = WasmObj->functionTypes();
316   ArrayRef<WasmSignature> Types = WasmObj->types();
317   Functions.reserve(Funcs.size());
318 
319   for (size_t I = 0, E = Funcs.size(); I != E; ++I)
320     Functions.emplace_back(
321         make<InputFunction>(Types[FuncTypes[I]], &Funcs[I], this));
322   setRelocs(Functions, CodeSection);
323 
324   // Populate `Globals`.
325   for (const WasmGlobal &G : WasmObj->globals())
326     Globals.emplace_back(make<InputGlobal>(G, this));
327 
328   // Populate `Events`.
329   for (const WasmEvent &E : WasmObj->events())
330     Events.emplace_back(make<InputEvent>(Types[E.Type.SigIndex], E, this));
331 
332   // Populate `Symbols` based on the WasmSymbols in the object.
333   Symbols.reserve(WasmObj->getNumberOfSymbols());
334   for (const SymbolRef &Sym : WasmObj->symbols()) {
335     const WasmSymbol &WasmSym = WasmObj->getWasmSymbol(Sym.getRawDataRefImpl());
336     if (WasmSym.isDefined()) {
337       // createDefined may fail if the symbol is comdat excluded in which case
338       // we fall back to creating an undefined symbol
339       if (Symbol *D = createDefined(WasmSym)) {
340         Symbols.push_back(D);
341         continue;
342       }
343     }
344     size_t Idx = Symbols.size();
345     Symbols.push_back(createUndefined(WasmSym, SymbolIsCalledDirectly[Idx]));
346   }
347 }
348 
349 bool ObjFile::isExcludedByComdat(InputChunk *Chunk) const {
350   uint32_t C = Chunk->getComdat();
351   if (C == UINT32_MAX)
352     return false;
353   return !KeptComdats[C];
354 }
355 
356 FunctionSymbol *ObjFile::getFunctionSymbol(uint32_t Index) const {
357   return cast<FunctionSymbol>(Symbols[Index]);
358 }
359 
360 GlobalSymbol *ObjFile::getGlobalSymbol(uint32_t Index) const {
361   return cast<GlobalSymbol>(Symbols[Index]);
362 }
363 
364 EventSymbol *ObjFile::getEventSymbol(uint32_t Index) const {
365   return cast<EventSymbol>(Symbols[Index]);
366 }
367 
368 SectionSymbol *ObjFile::getSectionSymbol(uint32_t Index) const {
369   return cast<SectionSymbol>(Symbols[Index]);
370 }
371 
372 DataSymbol *ObjFile::getDataSymbol(uint32_t Index) const {
373   return cast<DataSymbol>(Symbols[Index]);
374 }
375 
376 Symbol *ObjFile::createDefined(const WasmSymbol &Sym) {
377   StringRef Name = Sym.Info.Name;
378   uint32_t Flags = Sym.Info.Flags;
379 
380   switch (Sym.Info.Kind) {
381   case WASM_SYMBOL_TYPE_FUNCTION: {
382     InputFunction *Func =
383         Functions[Sym.Info.ElementIndex - WasmObj->getNumImportedFunctions()];
384     if (isExcludedByComdat(Func)) {
385       Func->Live = false;
386       return nullptr;
387     }
388 
389     if (Sym.isBindingLocal())
390       return make<DefinedFunction>(Name, Flags, this, Func);
391     return Symtab->addDefinedFunction(Name, Flags, this, Func);
392   }
393   case WASM_SYMBOL_TYPE_DATA: {
394     InputSegment *Seg = Segments[Sym.Info.DataRef.Segment];
395     if (isExcludedByComdat(Seg)) {
396       Seg->Live = false;
397       return nullptr;
398     }
399 
400     uint32_t Offset = Sym.Info.DataRef.Offset;
401     uint32_t Size = Sym.Info.DataRef.Size;
402 
403     if (Sym.isBindingLocal())
404       return make<DefinedData>(Name, Flags, this, Seg, Offset, Size);
405     return Symtab->addDefinedData(Name, Flags, this, Seg, Offset, Size);
406   }
407   case WASM_SYMBOL_TYPE_GLOBAL: {
408     InputGlobal *Global =
409         Globals[Sym.Info.ElementIndex - WasmObj->getNumImportedGlobals()];
410     if (Sym.isBindingLocal())
411       return make<DefinedGlobal>(Name, Flags, this, Global);
412     return Symtab->addDefinedGlobal(Name, Flags, this, Global);
413   }
414   case WASM_SYMBOL_TYPE_SECTION: {
415     InputSection *Section = CustomSectionsByIndex[Sym.Info.ElementIndex];
416     assert(Sym.isBindingLocal());
417     return make<SectionSymbol>(Flags, Section, this);
418   }
419   case WASM_SYMBOL_TYPE_EVENT: {
420     InputEvent *Event =
421         Events[Sym.Info.ElementIndex - WasmObj->getNumImportedEvents()];
422     if (Sym.isBindingLocal())
423       return make<DefinedEvent>(Name, Flags, this, Event);
424     return Symtab->addDefinedEvent(Name, Flags, this, Event);
425   }
426   }
427   llvm_unreachable("unknown symbol kind");
428 }
429 
430 Symbol *ObjFile::createUndefined(const WasmSymbol &Sym, bool IsCalledDirectly) {
431   StringRef Name = Sym.Info.Name;
432   uint32_t Flags = Sym.Info.Flags;
433 
434   switch (Sym.Info.Kind) {
435   case WASM_SYMBOL_TYPE_FUNCTION:
436     return Symtab->addUndefinedFunction(Name, Sym.Info.ImportName,
437                                         Sym.Info.ImportModule, Flags, this,
438                                         Sym.Signature, IsCalledDirectly);
439   case WASM_SYMBOL_TYPE_DATA:
440     return Symtab->addUndefinedData(Name, Flags, this);
441   case WASM_SYMBOL_TYPE_GLOBAL:
442     return Symtab->addUndefinedGlobal(Name, Sym.Info.ImportName,
443                                       Sym.Info.ImportModule, Flags, this,
444                                       Sym.GlobalType);
445   case WASM_SYMBOL_TYPE_SECTION:
446     llvm_unreachable("section symbols cannot be undefined");
447   }
448   llvm_unreachable("unknown symbol kind");
449 }
450 
451 void ArchiveFile::parse(bool IgnoreComdats) {
452   // Parse a MemoryBufferRef as an archive file.
453   LLVM_DEBUG(dbgs() << "Parsing library: " << toString(this) << "\n");
454   File = CHECK(Archive::create(MB), toString(this));
455 
456   // Read the symbol table to construct Lazy symbols.
457   int Count = 0;
458   for (const Archive::Symbol &Sym : File->symbols()) {
459     Symtab->addLazy(this, &Sym);
460     ++Count;
461   }
462   LLVM_DEBUG(dbgs() << "Read " << Count << " symbols\n");
463 }
464 
465 void ArchiveFile::addMember(const Archive::Symbol *Sym) {
466   const Archive::Child &C =
467       CHECK(Sym->getMember(),
468             "could not get the member for symbol " + Sym->getName());
469 
470   // Don't try to load the same member twice (this can happen when members
471   // mutually reference each other).
472   if (!Seen.insert(C.getChildOffset()).second)
473     return;
474 
475   LLVM_DEBUG(dbgs() << "loading lazy: " << Sym->getName() << "\n");
476   LLVM_DEBUG(dbgs() << "from archive: " << toString(this) << "\n");
477 
478   MemoryBufferRef MB =
479       CHECK(C.getMemoryBufferRef(),
480             "could not get the buffer for the member defining symbol " +
481                 Sym->getName());
482 
483   InputFile *Obj = createObjectFile(MB, getName());
484   Symtab->addFile(Obj);
485 }
486 
487 static uint8_t mapVisibility(GlobalValue::VisibilityTypes GvVisibility) {
488   switch (GvVisibility) {
489   case GlobalValue::DefaultVisibility:
490     return WASM_SYMBOL_VISIBILITY_DEFAULT;
491   case GlobalValue::HiddenVisibility:
492   case GlobalValue::ProtectedVisibility:
493     return WASM_SYMBOL_VISIBILITY_HIDDEN;
494   }
495   llvm_unreachable("unknown visibility");
496 }
497 
498 static Symbol *createBitcodeSymbol(const std::vector<bool> &KeptComdats,
499                                    const lto::InputFile::Symbol &ObjSym,
500                                    BitcodeFile &F) {
501   StringRef Name = Saver.save(ObjSym.getName());
502 
503   uint32_t Flags = ObjSym.isWeak() ? WASM_SYMBOL_BINDING_WEAK : 0;
504   Flags |= mapVisibility(ObjSym.getVisibility());
505 
506   int C = ObjSym.getComdatIndex();
507   bool ExcludedByComdat = C != -1 && !KeptComdats[C];
508 
509   if (ObjSym.isUndefined() || ExcludedByComdat) {
510     if (ObjSym.isExecutable())
511       return Symtab->addUndefinedFunction(Name, Name, DefaultModule, Flags, &F,
512                                           nullptr, true);
513     return Symtab->addUndefinedData(Name, Flags, &F);
514   }
515 
516   if (ObjSym.isExecutable())
517     return Symtab->addDefinedFunction(Name, Flags, &F, nullptr);
518   return Symtab->addDefinedData(Name, Flags, &F, nullptr, 0, 0);
519 }
520 
521 void BitcodeFile::parse(bool IgnoreComdats) {
522   Obj = check(lto::InputFile::create(MemoryBufferRef(
523       MB.getBuffer(), Saver.save(ArchiveName + MB.getBufferIdentifier()))));
524   Triple T(Obj->getTargetTriple());
525   if (T.getArch() != Triple::wasm32) {
526     error(toString(MB.getBufferIdentifier()) + ": machine type must be wasm32");
527     return;
528   }
529   std::vector<bool> KeptComdats;
530   for (StringRef S : Obj->getComdatTable())
531     if (IgnoreComdats)
532       KeptComdats.push_back(true);
533     else
534       KeptComdats.push_back(Symtab->addComdat(S));
535 
536   for (const lto::InputFile::Symbol &ObjSym : Obj->symbols())
537     Symbols.push_back(createBitcodeSymbol(KeptComdats, ObjSym, *this));
538 }
539 
540 // Returns a string in the format of "foo.o" or "foo.a(bar.o)".
541 std::string lld::toString(const wasm::InputFile *File) {
542   if (!File)
543     return "<internal>";
544 
545   if (File->ArchiveName.empty())
546     return File->getName();
547 
548   return (File->ArchiveName + "(" + File->getName() + ")").str();
549 }
550