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 // This file contains functions to parse Mach-O object files. In this comment, 10 // we describe the Mach-O file structure and how we parse it. 11 // 12 // Mach-O is not very different from ELF or COFF. The notion of symbols, 13 // sections and relocations exists in Mach-O as it does in ELF and COFF. 14 // 15 // Perhaps the notion that is new to those who know ELF/COFF is "subsections". 16 // In ELF/COFF, sections are an atomic unit of data copied from input files to 17 // output files. When we merge or garbage-collect sections, we treat each 18 // section as an atomic unit. In Mach-O, that's not the case. Sections can 19 // consist of multiple subsections, and subsections are a unit of merging and 20 // garbage-collecting. Therefore, Mach-O's subsections are more similar to 21 // ELF/COFF's sections than Mach-O's sections are. 22 // 23 // A section can have multiple symbols. A symbol that does not have the 24 // N_ALT_ENTRY attribute indicates a beginning of a subsection. Therefore, by 25 // definition, a symbol is always present at the beginning of each subsection. A 26 // symbol with N_ALT_ENTRY attribute does not start a new subsection and can 27 // point to a middle of a subsection. 28 // 29 // The notion of subsections also affects how relocations are represented in 30 // Mach-O. All references within a section need to be explicitly represented as 31 // relocations if they refer to different subsections, because we obviously need 32 // to fix up addresses if subsections are laid out in an output file differently 33 // than they were in object files. To represent that, Mach-O relocations can 34 // refer to an unnamed location via its address. Scattered relocations (those 35 // with the R_SCATTERED bit set) always refer to unnamed locations. 36 // Non-scattered relocations refer to an unnamed location if r_extern is not set 37 // and r_symbolnum is zero. 38 // 39 // Without the above differences, I think you can use your knowledge about ELF 40 // and COFF for Mach-O. 41 // 42 //===----------------------------------------------------------------------===// 43 44 #include "InputFiles.h" 45 #include "Config.h" 46 #include "DriverUtils.h" 47 #include "ExportTrie.h" 48 #include "InputSection.h" 49 #include "MachOStructs.h" 50 #include "ObjC.h" 51 #include "OutputSection.h" 52 #include "OutputSegment.h" 53 #include "SymbolTable.h" 54 #include "Symbols.h" 55 #include "Target.h" 56 57 #include "lld/Common/ErrorHandler.h" 58 #include "lld/Common/Memory.h" 59 #include "llvm/ADT/iterator.h" 60 #include "llvm/BinaryFormat/MachO.h" 61 #include "llvm/LTO/LTO.h" 62 #include "llvm/Support/Endian.h" 63 #include "llvm/Support/MemoryBuffer.h" 64 #include "llvm/Support/Path.h" 65 66 using namespace llvm; 67 using namespace llvm::MachO; 68 using namespace llvm::support::endian; 69 using namespace llvm::sys; 70 using namespace lld; 71 using namespace lld::macho; 72 73 std::vector<InputFile *> macho::inputFiles; 74 75 // Open a given file path and return it as a memory-mapped file. 76 Optional<MemoryBufferRef> macho::readFile(StringRef path) { 77 // Open a file. 78 auto mbOrErr = MemoryBuffer::getFile(path); 79 if (auto ec = mbOrErr.getError()) { 80 error("cannot open " + path + ": " + ec.message()); 81 return None; 82 } 83 84 std::unique_ptr<MemoryBuffer> &mb = *mbOrErr; 85 MemoryBufferRef mbref = mb->getMemBufferRef(); 86 make<std::unique_ptr<MemoryBuffer>>(std::move(mb)); // take mb ownership 87 88 // If this is a regular non-fat file, return it. 89 const char *buf = mbref.getBufferStart(); 90 auto *hdr = reinterpret_cast<const MachO::fat_header *>(buf); 91 if (read32be(&hdr->magic) != MachO::FAT_MAGIC) 92 return mbref; 93 94 // Object files and archive files may be fat files, which contains 95 // multiple real files for different CPU ISAs. Here, we search for a 96 // file that matches with the current link target and returns it as 97 // a MemoryBufferRef. 98 auto *arch = reinterpret_cast<const MachO::fat_arch *>(buf + sizeof(*hdr)); 99 100 for (uint32_t i = 0, n = read32be(&hdr->nfat_arch); i < n; ++i) { 101 if (reinterpret_cast<const char *>(arch + i + 1) > 102 buf + mbref.getBufferSize()) { 103 error(path + ": fat_arch struct extends beyond end of file"); 104 return None; 105 } 106 107 if (read32be(&arch[i].cputype) != target->cpuType || 108 read32be(&arch[i].cpusubtype) != target->cpuSubtype) 109 continue; 110 111 uint32_t offset = read32be(&arch[i].offset); 112 uint32_t size = read32be(&arch[i].size); 113 if (offset + size > mbref.getBufferSize()) 114 error(path + ": slice extends beyond end of file"); 115 return MemoryBufferRef(StringRef(buf + offset, size), path.copy(bAlloc)); 116 } 117 118 error("unable to find matching architecture in " + path); 119 return None; 120 } 121 122 const load_command *macho::findCommand(const mach_header_64 *hdr, 123 uint32_t type) { 124 const uint8_t *p = 125 reinterpret_cast<const uint8_t *>(hdr) + sizeof(mach_header_64); 126 127 for (uint32_t i = 0, n = hdr->ncmds; i < n; ++i) { 128 auto *cmd = reinterpret_cast<const load_command *>(p); 129 if (cmd->cmd == type) 130 return cmd; 131 p += cmd->cmdsize; 132 } 133 return nullptr; 134 } 135 136 void InputFile::parseSections(ArrayRef<section_64> sections) { 137 subsections.reserve(sections.size()); 138 auto *buf = reinterpret_cast<const uint8_t *>(mb.getBufferStart()); 139 140 for (const section_64 &sec : sections) { 141 InputSection *isec = make<InputSection>(); 142 isec->file = this; 143 isec->name = 144 StringRef(sec.sectname, strnlen(sec.sectname, sizeof(sec.sectname))); 145 isec->segname = 146 StringRef(sec.segname, strnlen(sec.segname, sizeof(sec.segname))); 147 isec->data = {isZeroFill(sec.flags) ? nullptr : buf + sec.offset, 148 static_cast<size_t>(sec.size)}; 149 if (sec.align >= 32) 150 error("alignment " + std::to_string(sec.align) + " of section " + 151 isec->name + " is too large"); 152 else 153 isec->align = 1 << sec.align; 154 isec->flags = sec.flags; 155 subsections.push_back({{0, isec}}); 156 } 157 } 158 159 // Find the subsection corresponding to the greatest section offset that is <= 160 // that of the given offset. 161 // 162 // offset: an offset relative to the start of the original InputSection (before 163 // any subsection splitting has occurred). It will be updated to represent the 164 // same location as an offset relative to the start of the containing 165 // subsection. 166 static InputSection *findContainingSubsection(SubsectionMap &map, 167 uint32_t *offset) { 168 auto it = std::prev(map.upper_bound(*offset)); 169 *offset -= it->first; 170 return it->second; 171 } 172 173 void InputFile::parseRelocations(const section_64 &sec, 174 SubsectionMap &subsecMap) { 175 auto *buf = reinterpret_cast<const uint8_t *>(mb.getBufferStart()); 176 ArrayRef<any_relocation_info> anyRelInfos( 177 reinterpret_cast<const any_relocation_info *>(buf + sec.reloff), 178 sec.nreloc); 179 180 for (const any_relocation_info &anyRelInfo : anyRelInfos) { 181 if (anyRelInfo.r_word0 & R_SCATTERED) 182 fatal("TODO: Scattered relocations not supported"); 183 184 auto relInfo = reinterpret_cast<const relocation_info &>(anyRelInfo); 185 186 Reloc r; 187 r.type = relInfo.r_type; 188 r.pcrel = relInfo.r_pcrel; 189 r.length = relInfo.r_length; 190 uint64_t rawAddend = target->getImplicitAddend(mb, sec, relInfo); 191 192 if (relInfo.r_extern) { 193 r.referent = symbols[relInfo.r_symbolnum]; 194 r.addend = rawAddend; 195 } else { 196 if (relInfo.r_symbolnum == 0 || relInfo.r_symbolnum > subsections.size()) 197 fatal("invalid section index in relocation for offset " + 198 std::to_string(r.offset) + " in section " + sec.sectname + 199 " of " + getName()); 200 201 SubsectionMap &referentSubsecMap = subsections[relInfo.r_symbolnum - 1]; 202 const section_64 &referentSec = sectionHeaders[relInfo.r_symbolnum - 1]; 203 uint32_t referentOffset; 204 if (relInfo.r_pcrel) { 205 // The implicit addend for pcrel section relocations is the pcrel offset 206 // in terms of the addresses in the input file. Here we adjust it so 207 // that it describes the offset from the start of the referent section. 208 // TODO: The offset of 4 is probably not right for ARM64, nor for 209 // relocations with r_length != 2. 210 referentOffset = 211 sec.addr + relInfo.r_address + 4 + rawAddend - referentSec.addr; 212 } else { 213 // The addend for a non-pcrel relocation is its absolute address. 214 referentOffset = rawAddend - referentSec.addr; 215 } 216 r.referent = findContainingSubsection(referentSubsecMap, &referentOffset); 217 r.addend = referentOffset; 218 } 219 220 r.offset = relInfo.r_address; 221 InputSection *subsec = findContainingSubsection(subsecMap, &r.offset); 222 subsec->relocs.push_back(r); 223 } 224 } 225 226 static macho::Symbol *createDefined(const structs::nlist_64 &sym, 227 StringRef name, InputSection *isec, 228 uint32_t value) { 229 if (sym.n_type & N_EXT) 230 // Global defined symbol 231 return symtab->addDefined(name, isec, value, sym.n_desc & N_WEAK_DEF); 232 // Local defined symbol 233 return make<Defined>(name, isec, value, sym.n_desc & N_WEAK_DEF, 234 /*isExternal=*/false); 235 } 236 237 // Absolute symbols are defined symbols that do not have an associated 238 // InputSection. They cannot be weak. 239 static macho::Symbol *createAbsolute(const structs::nlist_64 &sym, 240 StringRef name) { 241 if (sym.n_type & N_EXT) 242 return symtab->addDefined(name, nullptr, sym.n_value, /*isWeakDef=*/false); 243 return make<Defined>(name, nullptr, sym.n_value, /*isWeakDef=*/false, 244 /*isExternal=*/false); 245 } 246 247 macho::Symbol *InputFile::parseNonSectionSymbol(const structs::nlist_64 &sym, 248 StringRef name) { 249 uint8_t type = sym.n_type & N_TYPE; 250 switch (type) { 251 case N_UNDF: 252 return sym.n_value == 0 253 ? symtab->addUndefined(name) 254 : symtab->addCommon(name, this, sym.n_value, 255 1 << GET_COMM_ALIGN(sym.n_desc)); 256 case N_ABS: 257 return createAbsolute(sym, name); 258 case N_PBUD: 259 case N_INDR: 260 error("TODO: support symbols of type " + std::to_string(type)); 261 return nullptr; 262 case N_SECT: 263 llvm_unreachable( 264 "N_SECT symbols should not be passed to parseNonSectionSymbol"); 265 default: 266 llvm_unreachable("invalid symbol type"); 267 } 268 } 269 270 void InputFile::parseSymbols(ArrayRef<structs::nlist_64> nList, 271 const char *strtab, bool subsectionsViaSymbols) { 272 // resize(), not reserve(), because we are going to create N_ALT_ENTRY symbols 273 // out-of-sequence. 274 symbols.resize(nList.size()); 275 std::vector<size_t> altEntrySymIdxs; 276 277 for (size_t i = 0, n = nList.size(); i < n; ++i) { 278 const structs::nlist_64 &sym = nList[i]; 279 StringRef name = strtab + sym.n_strx; 280 281 if ((sym.n_type & N_TYPE) != N_SECT) { 282 symbols[i] = parseNonSectionSymbol(sym, name); 283 continue; 284 } 285 286 const section_64 &sec = sectionHeaders[sym.n_sect - 1]; 287 SubsectionMap &subsecMap = subsections[sym.n_sect - 1]; 288 uint64_t offset = sym.n_value - sec.addr; 289 290 // If the input file does not use subsections-via-symbols, all symbols can 291 // use the same subsection. Otherwise, we must split the sections along 292 // symbol boundaries. 293 if (!subsectionsViaSymbols) { 294 symbols[i] = createDefined(sym, name, subsecMap[0], offset); 295 continue; 296 } 297 298 // nList entries aren't necessarily arranged in address order. Therefore, 299 // we can't create alt-entry symbols at this point because a later symbol 300 // may split its section, which may affect which subsection the alt-entry 301 // symbol is assigned to. So we need to handle them in a second pass below. 302 if (sym.n_desc & N_ALT_ENTRY) { 303 altEntrySymIdxs.push_back(i); 304 continue; 305 } 306 307 // Find the subsection corresponding to the greatest section offset that is 308 // <= that of the current symbol. The subsection that we find either needs 309 // to be used directly or split in two. 310 uint32_t firstSize = offset; 311 InputSection *firstIsec = findContainingSubsection(subsecMap, &firstSize); 312 313 if (firstSize == 0) { 314 // Alias of an existing symbol, or the first symbol in the section. These 315 // are handled by reusing the existing section. 316 symbols[i] = createDefined(sym, name, firstIsec, 0); 317 continue; 318 } 319 320 // We saw a symbol definition at a new offset. Split the section into two 321 // subsections. The new symbol uses the second subsection. 322 auto *secondIsec = make<InputSection>(*firstIsec); 323 secondIsec->data = firstIsec->data.slice(firstSize); 324 firstIsec->data = firstIsec->data.slice(0, firstSize); 325 // TODO: ld64 appears to preserve the original alignment as well as each 326 // subsection's offset from the last aligned address. We should consider 327 // emulating that behavior. 328 secondIsec->align = MinAlign(firstIsec->align, offset); 329 330 subsecMap[offset] = secondIsec; 331 // By construction, the symbol will be at offset zero in the new section. 332 symbols[i] = createDefined(sym, name, secondIsec, 0); 333 } 334 335 for (size_t idx : altEntrySymIdxs) { 336 const structs::nlist_64 &sym = nList[idx]; 337 StringRef name = strtab + sym.n_strx; 338 SubsectionMap &subsecMap = subsections[sym.n_sect - 1]; 339 uint32_t off = sym.n_value - sectionHeaders[sym.n_sect - 1].addr; 340 InputSection *subsec = findContainingSubsection(subsecMap, &off); 341 symbols[idx] = createDefined(sym, name, subsec, off); 342 } 343 } 344 345 OpaqueFile::OpaqueFile(MemoryBufferRef mb, StringRef segName, 346 StringRef sectName) 347 : InputFile(OpaqueKind, mb) { 348 InputSection *isec = make<InputSection>(); 349 isec->file = this; 350 isec->name = sectName.take_front(16); 351 isec->segname = segName.take_front(16); 352 const auto *buf = reinterpret_cast<const uint8_t *>(mb.getBufferStart()); 353 isec->data = {buf, mb.getBufferSize()}; 354 subsections.push_back({{0, isec}}); 355 } 356 357 ObjFile::ObjFile(MemoryBufferRef mb) : InputFile(ObjKind, mb) { 358 auto *buf = reinterpret_cast<const uint8_t *>(mb.getBufferStart()); 359 auto *hdr = reinterpret_cast<const mach_header_64 *>(mb.getBufferStart()); 360 361 if (const load_command *cmd = findCommand(hdr, LC_SEGMENT_64)) { 362 auto *c = reinterpret_cast<const segment_command_64 *>(cmd); 363 sectionHeaders = ArrayRef<section_64>{ 364 reinterpret_cast<const section_64 *>(c + 1), c->nsects}; 365 parseSections(sectionHeaders); 366 } 367 368 // TODO: Error on missing LC_SYMTAB? 369 if (const load_command *cmd = findCommand(hdr, LC_SYMTAB)) { 370 auto *c = reinterpret_cast<const symtab_command *>(cmd); 371 ArrayRef<structs::nlist_64> nList( 372 reinterpret_cast<const structs::nlist_64 *>(buf + c->symoff), c->nsyms); 373 const char *strtab = reinterpret_cast<const char *>(buf) + c->stroff; 374 bool subsectionsViaSymbols = hdr->flags & MH_SUBSECTIONS_VIA_SYMBOLS; 375 parseSymbols(nList, strtab, subsectionsViaSymbols); 376 } 377 378 // The relocations may refer to the symbols, so we parse them after we have 379 // parsed all the symbols. 380 for (size_t i = 0, n = subsections.size(); i < n; ++i) 381 parseRelocations(sectionHeaders[i], subsections[i]); 382 } 383 384 // The path can point to either a dylib or a .tbd file. 385 static Optional<DylibFile *> loadDylib(StringRef path, DylibFile *umbrella) { 386 Optional<MemoryBufferRef> mbref = readFile(path); 387 if (!mbref) { 388 error("could not read dylib file at " + path); 389 return {}; 390 } 391 392 file_magic magic = identify_magic(mbref->getBuffer()); 393 if (magic == file_magic::tapi_file) 394 return makeDylibFromTAPI(*mbref, umbrella); 395 assert(magic == file_magic::macho_dynamically_linked_shared_lib); 396 return make<DylibFile>(*mbref, umbrella); 397 } 398 399 // TBD files are parsed into a series of TAPI documents (InterfaceFiles), with 400 // the first document storing child pointers to the rest of them. When we are 401 // processing a given TBD file, we store that top-level document here. When 402 // processing re-exports, we search its children for potentially matching 403 // documents in the same TBD file. Note that the children themselves don't 404 // point to further documents, i.e. this is a two-level tree. 405 // 406 // ld64 allows a TAPI re-export to reference documents nested within other TBD 407 // files, but that seems like a strange design, so this is an intentional 408 // deviation. 409 const InterfaceFile *currentTopLevelTapi = nullptr; 410 411 // Re-exports can either refer to on-disk files, or to documents within .tbd 412 // files. 413 static Optional<DylibFile *> loadReexport(StringRef path, DylibFile *umbrella) { 414 if (path::is_absolute(path, path::Style::posix)) 415 for (StringRef root : config->systemLibraryRoots) 416 if (Optional<std::string> dylibPath = 417 resolveDylibPath((root + path).str())) 418 return loadDylib(*dylibPath, umbrella); 419 420 // TODO: Expand @loader_path, @executable_path etc 421 422 if (currentTopLevelTapi) { 423 for (InterfaceFile &child : 424 make_pointee_range(currentTopLevelTapi->documents())) { 425 if (path == child.getInstallName()) 426 return make<DylibFile>(child, umbrella); 427 assert(child.documents().empty()); 428 } 429 } 430 431 if (Optional<std::string> dylibPath = resolveDylibPath(path)) 432 return loadDylib(*dylibPath, umbrella); 433 434 error("unable to locate re-export with install name " + path); 435 return {}; 436 } 437 438 DylibFile::DylibFile(MemoryBufferRef mb, DylibFile *umbrella) 439 : InputFile(DylibKind, mb) { 440 if (umbrella == nullptr) 441 umbrella = this; 442 443 auto *buf = reinterpret_cast<const uint8_t *>(mb.getBufferStart()); 444 auto *hdr = reinterpret_cast<const mach_header_64 *>(mb.getBufferStart()); 445 446 // Initialize dylibName. 447 if (const load_command *cmd = findCommand(hdr, LC_ID_DYLIB)) { 448 auto *c = reinterpret_cast<const dylib_command *>(cmd); 449 dylibName = reinterpret_cast<const char *>(cmd) + read32le(&c->dylib.name); 450 } else { 451 error("dylib " + getName() + " missing LC_ID_DYLIB load command"); 452 return; 453 } 454 455 // Initialize symbols. 456 // TODO: if a re-exported dylib is public (lives in /usr/lib or 457 // /System/Library/Frameworks), we should bind to its symbols directly 458 // instead of the re-exporting umbrella library. 459 if (const load_command *cmd = findCommand(hdr, LC_DYLD_INFO_ONLY)) { 460 auto *c = reinterpret_cast<const dyld_info_command *>(cmd); 461 parseTrie(buf + c->export_off, c->export_size, 462 [&](const Twine &name, uint64_t flags) { 463 bool isWeakDef = flags & EXPORT_SYMBOL_FLAGS_WEAK_DEFINITION; 464 bool isTlv = flags & EXPORT_SYMBOL_FLAGS_KIND_THREAD_LOCAL; 465 symbols.push_back(symtab->addDylib(saver.save(name), umbrella, 466 isWeakDef, isTlv)); 467 }); 468 } else { 469 error("LC_DYLD_INFO_ONLY not found in " + getName()); 470 return; 471 } 472 473 if (hdr->flags & MH_NO_REEXPORTED_DYLIBS) 474 return; 475 476 const uint8_t *p = 477 reinterpret_cast<const uint8_t *>(hdr) + sizeof(mach_header_64); 478 for (uint32_t i = 0, n = hdr->ncmds; i < n; ++i) { 479 auto *cmd = reinterpret_cast<const load_command *>(p); 480 p += cmd->cmdsize; 481 if (cmd->cmd != LC_REEXPORT_DYLIB) 482 continue; 483 484 auto *c = reinterpret_cast<const dylib_command *>(cmd); 485 StringRef reexportPath = 486 reinterpret_cast<const char *>(c) + read32le(&c->dylib.name); 487 if (Optional<DylibFile *> reexport = loadReexport(reexportPath, umbrella)) 488 reexported.push_back(*reexport); 489 } 490 } 491 492 DylibFile::DylibFile(const InterfaceFile &interface, DylibFile *umbrella) 493 : InputFile(DylibKind, interface) { 494 if (umbrella == nullptr) 495 umbrella = this; 496 497 dylibName = saver.save(interface.getInstallName()); 498 auto addSymbol = [&](const Twine &name) -> void { 499 symbols.push_back(symtab->addDylib(saver.save(name), umbrella, 500 /*isWeakDef=*/false, 501 /*isTlv=*/false)); 502 }; 503 // TODO(compnerd) filter out symbols based on the target platform 504 // TODO: handle weak defs, thread locals 505 for (const auto symbol : interface.symbols()) { 506 if (!symbol->getArchitectures().has(config->arch)) 507 continue; 508 509 switch (symbol->getKind()) { 510 case SymbolKind::GlobalSymbol: 511 addSymbol(symbol->getName()); 512 break; 513 case SymbolKind::ObjectiveCClass: 514 // XXX ld64 only creates these symbols when -ObjC is passed in. We may 515 // want to emulate that. 516 addSymbol(objc::klass + symbol->getName()); 517 addSymbol(objc::metaclass + symbol->getName()); 518 break; 519 case SymbolKind::ObjectiveCClassEHType: 520 addSymbol(objc::ehtype + symbol->getName()); 521 break; 522 case SymbolKind::ObjectiveCInstanceVariable: 523 addSymbol(objc::ivar + symbol->getName()); 524 break; 525 } 526 } 527 528 bool isTopLevelTapi = false; 529 if (currentTopLevelTapi == nullptr) { 530 currentTopLevelTapi = &interface; 531 isTopLevelTapi = true; 532 } 533 534 for (InterfaceFileRef intfRef : interface.reexportedLibraries()) 535 if (Optional<DylibFile *> reexport = 536 loadReexport(intfRef.getInstallName(), umbrella)) 537 reexported.push_back(*reexport); 538 539 if (isTopLevelTapi) 540 currentTopLevelTapi = nullptr; 541 } 542 543 ArchiveFile::ArchiveFile(std::unique_ptr<llvm::object::Archive> &&f) 544 : InputFile(ArchiveKind, f->getMemoryBufferRef()), file(std::move(f)) { 545 for (const object::Archive::Symbol &sym : file->symbols()) 546 symtab->addLazy(sym.getName(), this, sym); 547 } 548 549 void ArchiveFile::fetch(const object::Archive::Symbol &sym) { 550 object::Archive::Child c = 551 CHECK(sym.getMember(), toString(this) + 552 ": could not get the member for symbol " + 553 sym.getName()); 554 555 if (!seen.insert(c.getChildOffset()).second) 556 return; 557 558 MemoryBufferRef mb = 559 CHECK(c.getMemoryBufferRef(), 560 toString(this) + 561 ": could not get the buffer for the member defining symbol " + 562 sym.getName()); 563 auto file = make<ObjFile>(mb); 564 symbols.insert(symbols.end(), file->symbols.begin(), file->symbols.end()); 565 subsections.insert(subsections.end(), file->subsections.begin(), 566 file->subsections.end()); 567 } 568 569 BitcodeFile::BitcodeFile(MemoryBufferRef mbref) 570 : InputFile(BitcodeKind, mbref) { 571 obj = check(lto::InputFile::create(mbref)); 572 } 573 574 // Returns "<internal>" or "baz.o". 575 std::string lld::toString(const InputFile *file) { 576 return file ? std::string(file->getName()) : "<internal>"; 577 } 578