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