Lines Matching +full:- +full:- +full:with +full:- +full:config

1 //===- Driver.cpp ---------------------------------------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
10 #include "Config.h"
39 #include "llvm/Config/llvm-config.h"
65 std::unique_ptr<Configuration> macho::config; member in macho
69 // TODO: -r, -dylinker, -preload... in getOutputType()
74 switch (outputArg->getOption().getID()) { in getOutputType()
91 return entry->second; in findLibrary()
97 return findPathCombination(name, config->librarySearchPaths, {""}); in findLibrary()
98 if (config->searchDylibsFirst) { in findLibrary()
100 findPathCombination("lib" + name, config->librarySearchPaths, in findLibrary()
103 return findPathCombination("lib" + name, config->librarySearchPaths, in findLibrary()
106 return findPathCombination("lib" + name, config->librarySearchPaths, in findLibrary()
122 return entry->second; in findFramework()
127 for (StringRef dir : config->frameworkSearchPaths) { in findFramework()
141 // Suffix lookup failed, fall through to the no-suffix case. in findFramework()
152 warn("directory not found for option -" + option + path); in warnIfNotDirectory()
155 warn("option -" + option + path + " references a non-directory path"); in warnIfNotDirectory()
168 // NOTE: only absolute paths are re-rooted to syslibroot(s) in getSearchPaths()
185 // `-Z` suppresses the standard "system" search paths. in getSearchPaths()
203 roots.push_back(arg->getValue()); in getSystemLibraryRoots()
204 // NOTE: the final `-syslibroot` being `/` will ignore all roots in getSystemLibraryRoots()
207 // NOTE: roots can never be empty - add an empty root to simplify the library in getSystemLibraryRoots()
236 switch (arg->getOption().getID()) { in getLTOCachePolicy()
238 add(arg->getValue()); in getLTOCachePolicy()
241 if (!strcmp("-1", arg->getValue())) in getLTOCachePolicy()
244 add(Twine("prune_interval=") + arg->getValue() + "s"); in getLTOCachePolicy()
247 add(Twine("prune_after=") + arg->getValue() + "s"); in getLTOCachePolicy()
250 add(Twine("cache_size=") + arg->getValue() + "%"); in getLTOCachePolicy()
263 CommandLineForce, // Library was passed via `-force_load`
275 assert(tar && file->getArchive().isThin()); in saveThinArchiveToRepro()
278 for (const object::Archive::Child &c : file->getArchive().children(e)) { in saveThinArchiveToRepro()
281 tar->append(relativeToRoot(CHECK(c.getFullName(), file)), mb.getBuffer()); in saveThinArchiveToRepro()
302 // Avoid loading archives twice. If the archives are being force-loaded, in addFile()
304 // non-force-loading case, this is just a minor performance optimization. in addFile()
316 if (!archive->isEmpty() && !archive->hasSymbolTable()) in addFile()
320 if (tar && file->getArchive().isThin()) in addFile()
323 file = entry->second.file; in addFile()
324 // Command-line loads take precedence. If file is previously loaded via in addFile()
327 if (entry->second.isCommandLineLoad || !isCommandLineLoad) in addFile()
332 config->forceLoadSwift && in addFile()
334 if ((isCommandLineLoad && config->allLoad) || in addFile()
338 for (const object::Archive::Child &c : file->getArchive().children(e)) { in addFile()
345 reason = "-force_load"; in addFile()
348 reason = "-all_load"; in addFile()
351 if (Error e = file->fetch(c, reason)) { in addFile()
352 if (config->warnThinArchiveMissingMembers) in addFile()
363 } else if (isCommandLineLoad && config->forceLoadObjC) { in addFile()
364 for (const object::Archive::Symbol &sym : file->getArchive().symbols()) in addFile()
366 file->fetch(sym); in addFile()
372 for (const object::Archive::Child &c : file->getArchive().children(e)) { in addFile()
377 if (config->warnThinArchiveMissingMembers) in addFile()
378 warn(toString(file) + ": -ObjC failed to open archive member: " + in addFile()
387 if (Error e = file->fetch(c, "-ObjC")) in addFile()
388 error(toString(file) + ": -ObjC failed to load archive member: " + in addFile()
397 file->addLazySymbols(); in addFile()
428 if ((isa<ObjFile>(newFile) || isa<BitcodeFile>(newFile)) && newFile->lazy && in addFile()
429 config->forceLoadObjC) { in addFile()
430 for (Symbol *sym : newFile->symbols) in addFile()
431 if (sym && sym->getName().starts_with(objc::symbol_names::klass)) { in addFile()
432 extract(*newFile, "-ObjC"); in addFile()
435 if (newFile->lazy && hasObjCSection(mbref)) in addFile()
436 extract(*newFile, "-ObjC"); in addFile()
441 if (config->printEachFile && magic != file_magic::archive && !isLazy) in addFile()
457 dylibFile->forceNeeded = true; in addLibrary()
459 dylibFile->forceWeakImport = true; in addLibrary()
461 config->hasReexports = true; in addLibrary()
462 dylibFile->reexport = true; in addLibrary()
469 saver().save("auto-linked library not found for -l" + name)); in addLibrary()
472 error("library not found for -l" + name); in addLibrary()
486 dylibFile->forceNeeded = true; in addFramework()
488 dylibFile->forceWeakImport = true; in addFramework()
490 config->hasReexports = true; in addFramework()
491 dylibFile->reexport = true; in addFramework()
497 // in addFile() to share caching with libraries, and frameworks in addFramework()
506 saver().save("auto-linked framework not found for -framework " + name)); in addFramework()
509 error("framework not found for -framework " + name); in addFramework()
518 if (config->ignoreAutoLink) in parseLCLinkerOption()
532 if (arg.consume_front("-l")) { in parseLCLinkerOption()
533 if (config->ignoreAutoLinkOptions.contains(arg)) in parseLCLinkerOption()
535 } else if (arg == "-framework") { in parseLCLinkerOption()
537 if (config->ignoreAutoLinkOptions.contains(name)) in parseLCLinkerOption()
553 if (arg.consume_front("-l")) { in resolveLCLinkerOptions()
554 assert(!config->ignoreAutoLinkOptions.contains(arg)); in resolveLCLinkerOptions()
558 } else if (arg == "-framework") { in resolveLCLinkerOptions()
560 assert(!config->ignoreAutoLinkOptions.contains(name)); in resolveLCLinkerOptions()
580 // We expect sub-library names of the form "libfoo", which will match a dylib
581 // with a path of .*/libfoo.{dylib, tbd}.
582 // XXX ld64 seems to ignore the extension entirely when matching sub-libraries;
587 StringRef filename = path::filename(dylibFile->getName()); in markReexport()
590 dylibFile->reexport = true; in markReexport()
614 if (!file->lazy) in compileBitcodeFiles()
615 lto->add(*bitcodeFile); in compileBitcodeFiles()
617 std::vector<ObjFile *> compiled = lto->compile(); in compileBitcodeFiles()
624 // Replaces common symbols with defined symbols residing in __common sections.
631 for (Symbol *sym : symtab->getSymbols()) { in replaceCommonSymbols()
636 // Casting to size_t will truncate large values on 32-bit architectures, in replaceCommonSymbols()
637 // but it's not really worth supporting the linking of 64-bit programs on in replaceCommonSymbols()
638 // 32-bit archs. in replaceCommonSymbols()
639 ArrayRef<uint8_t> data = {nullptr, static_cast<size_t>(common->size)}; in replaceCommonSymbols()
642 make<Section>(common->getFile(), segment_names::data, in replaceCommonSymbols()
644 auto *isec = make<ConcatInputSection>(*section, data, common->align); in replaceCommonSymbols()
647 isec->parent = osec; in replaceCommonSymbols()
653 sym, sym->getName(), common->getFile(), isec, /*value=*/0, common->size, in replaceCommonSymbols()
654 /*isWeakDef=*/false, /*isExternal=*/true, common->privateExtern, in replaceCommonSymbols()
661 if (config->dataConst) { in initializeSectionRenameMap()
677 config->sectionRenameMap[{segment_names::data, s}] = { in initializeSectionRenameMap()
680 config->sectionRenameMap[{segment_names::text, section_names::staticInit}] = { in initializeSectionRenameMap()
682 config->sectionRenameMap[{segment_names::import, section_names::pointers}] = { in initializeSectionRenameMap()
683 config->dataConst ? segment_names::dataConst : segment_names::data, in initializeSectionRenameMap()
689 return x - 'A' + 'a'; in toLowerDash()
691 return '-'; in toLowerDash()
707 assert(arg->getOption().getID() == OPT_platform_version); in parsePlatformVersion()
708 StringRef platformStr = arg->getValue(0); in parsePlatformVersion()
709 StringRef minVersionStr = arg->getValue(1); in parsePlatformVersion()
710 StringRef sdkVersionStr = arg->getValue(2); in parsePlatformVersion()
722 .Cases("mac-catalyst", "6", PLATFORM_MACCATALYST) in parsePlatformVersion()
723 .Cases("ios-simulator", "7", PLATFORM_IOSSIMULATOR) in parsePlatformVersion()
724 .Cases("tvos-simulator", "8", PLATFORM_TVOSSIMULATOR) in parsePlatformVersion()
725 .Cases("watchos-simulator", "9", PLATFORM_WATCHOSSIMULATOR) in parsePlatformVersion()
728 .Cases("xros-simulator", "12", PLATFORM_XROS_SIMULATOR) in parsePlatformVersion()
733 // NOTE: ld64 accepts version strings with 5 components in parsePlatformVersion()
735 // Has Apple ever published version strings with 5 components? in parsePlatformVersion()
743 // Has the side-effect of setting Config::platformInfo and
744 // potentially Config::secondaryPlatformInfo.
752 // `-platform_version macos 2 3 -platform_version macos 4 5` has the same in setPlatformVersions()
753 // effect as just passing `-platform_version macos 4 5`. in setPlatformVersions()
760 error("must specify -platform_version"); in setPlatformVersions()
764 error("must specify -platform_version at most twice"); in setPlatformVersions()
773 "macos and mac-catalyst"); in setPlatformVersions()
774 } else if (config->outputType != MH_DYLIB && in setPlatformVersions()
775 config->outputType != MH_BUNDLE) { in setPlatformVersions()
776 error("writing zippered outputs only valid for -dylib and -bundle"); in setPlatformVersions()
779 config->platformInfo = { in setPlatformVersions()
783 config->secondaryPlatformInfo = { in setPlatformVersions()
790 config->platformInfo = {MachO::Target(getArchitectureFromName(archName), in setPlatformVersions()
791 lastVersionInfo->platform, in setPlatformVersions()
792 lastVersionInfo->minimum), in setPlatformVersions()
793 lastVersionInfo->sdk}; in setPlatformVersions()
796 // Has the side-effect of setting Config::target.
800 error("must specify -arch"); in createTargetInfo()
805 auto [cpuType, cpuSubtype] = getCPUTypeFromArchitecture(config->arch()); in createTargetInfo()
814 error("missing or unsupported -arch " + archName); in createTargetInfo()
830 warn(Twine("unknown -undefined TREATMENT '") + treatmentStr + in getUndefinedSymbolTreatment()
833 } else if (config->namespaceKind == NamespaceKind::twolevel && in getUndefinedSymbolTreatment()
837 fatal("'-undefined warning' only valid with '-flat_namespace'"); in getUndefinedSymbolTreatment()
839 fatal("'-undefined suppress' only valid with '-flat_namespace'"); in getUndefinedSymbolTreatment()
853 warn(Twine("unknown --icf=OPTION `") + icfLevelStr + in getICFLevel()
865 if (arg->getOption().getID() == OPT_objc_stubs_small) { in getObjCStubsMode()
866 if (is_contained({AK_arm64e, AK_arm64}, config->arch())) in getObjCStubsMode()
869 warn("-objc_stubs_small is not yet implemented, defaulting to " in getObjCStubsMode()
870 "-objc_stubs_fast"); in getObjCStubsMode()
913 return arg->getValue(); in getReproduceOption()
924 StringRef s = arg->getValue(); in getOldNewOptions()
927 error(arg->getSpelling() + " expects 'old;new' format, but got " + s); in getOldNewOptions()
955 if (config->outputType != MH_DYLIB) { in parseDylibVersion()
956 error(arg->getAsString(args) + ": only valid with -dylib"); in parseDylibVersion()
961 if (!version.parse32(arg->getValue())) { in parseDylibVersion()
962 error(arg->getAsString(args) + ": malformed version"); in parseDylibVersion()
982 case '-': in parseProtection()
985 error("unknown -segprot letter '" + Twine(c) + "' in " + protStr); in parseProtection()
995 StringRef segName = arg->getValue(0); in parseSectAlign()
996 StringRef sectName = arg->getValue(1); in parseSectAlign()
997 StringRef alignStr = arg->getValue(2); in parseSectAlign()
1001 error("-sectalign: failed to parse '" + StringRef(arg->getValue(2)) + in parseSectAlign()
1006 error("-sectalign: '" + StringRef(arg->getValue(2)) + in parseSectAlign()
1031 return !(config->arch() == AK_arm64 || config->arch() == AK_arm64e || in supportsNoPie()
1032 config->arch() == AK_arm64_32); in supportsNoPie()
1053 PlatformType platform = removeSimulator(config->platformInfo.target.Platform); in dataConstDefault()
1057 if (config->platformInfo.target.MinDeployment < it->second) in dataConstDefault()
1060 switch (config->outputType) { in dataConstDefault()
1064 // FIXME: return false when -final_name ... in dataConstDefault()
1074 "unsupported output type for determining data-const default"); in dataConstDefault()
1081 if (arg && arg->getOption().matches(OPT_no_fixup_chains)) in shouldEmitChainedFixups()
1084 bool requested = arg && arg->getOption().matches(OPT_fixup_chains); in shouldEmitChainedFixups()
1085 if (!config->isPic) { in shouldEmitChainedFixups()
1087 error("-fixup_chains is incompatible with -no_pie"); in shouldEmitChainedFixups()
1092 if (!is_contained({AK_x86_64, AK_x86_64h, AK_arm64}, config->arch())) { in shouldEmitChainedFixups()
1094 error("-fixup_chains is only supported on x86_64 and arm64 targets"); in shouldEmitChainedFixups()
1101 error("-fixup_chains is incompatible with -preload"); in shouldEmitChainedFixups()
1121 PlatformType platform = config->platformInfo.target.Platform; in shouldEmitChainedFixups()
1129 if (it->second > config->platformInfo.target.MinDeployment) in shouldEmitChainedFixups()
1138 if (arg && arg->getOption().getID() == OPT_objc_relative_method_lists) in shouldEmitRelativeMethodLists()
1140 if (arg && arg->getOption().getID() == OPT_no_objc_relative_method_lists) in shouldEmitRelativeMethodLists()
1144 // - default false on < ios14 in shouldEmitRelativeMethodLists()
1145 // - default true on >= ios14 in shouldEmitRelativeMethodLists()
1162 error("invalid symbol-name pattern: " + symbolName); in insert()
1182 StringRef path = arg->getValue(); in parseSymbolPatternsFile()
1201 symbolPatterns.insert(arg->getValue()); in handleSymbolPatterns()
1211 // If we've processed an opening --start-lib, without a matching --end-lib in createFiles()
1214 const Option &opt = arg->getOption(); in createFiles()
1220 addFile(rerootPath(arg->getValue()), LoadType::CommandLine, isLazy); in createFiles()
1224 addFile(rerootPath(arg->getValue()), LoadType::CommandLine))) in createFiles()
1225 dylibFile->forceNeeded = true; in createFiles()
1229 addFile(rerootPath(arg->getValue()), LoadType::CommandLine))) { in createFiles()
1230 config->hasReexports = true; in createFiles()
1231 dylibFile->reexport = true; in createFiles()
1236 addFile(rerootPath(arg->getValue()), LoadType::CommandLine))) in createFiles()
1237 dylibFile->forceWeakImport = true; in createFiles()
1240 addFileList(arg->getValue(), isLazy); in createFiles()
1243 addFile(rerootPath(arg->getValue()), LoadType::CommandLineForce); in createFiles()
1246 addFile(rerootPath(arg->getValue()), LoadType::CommandLine, in createFiles()
1255 addLibrary(arg->getValue(), opt.getID() == OPT_needed_l, in createFiles()
1264 addFramework(arg->getValue(), opt.getID() == OPT_needed_framework, in createFiles()
1271 error("nested --start-lib"); in createFiles()
1273 if (!config->allLoad) in createFiles()
1278 error("stray --end-lib"); in createFiles()
1291 for (const Section *section : file->sections) { in gatherInputSections()
1294 if (section->name == section_names::compactUnwind) in gatherInputSections()
1297 if (section->name == section_names::addrSig) in gatherInputSections()
1299 for (const Subsection &subsection : section->subsections) in gatherInputSections()
1302 if (!file->objCImageInfo.empty()) in gatherInputSections()
1303 in.objCImageInfo->addFile(file); in gatherInputSections()
1310 // true. If it isn't, we simply create a non-deduplicating CStringSection. in foldIdenticalLiterals()
1312 in.cStringSection->finalizeContents(); in foldIdenticalLiterals()
1313 in.objcMethnameSection->finalizeContents(); in foldIdenticalLiterals()
1314 in.wordLiteralSection->finalizeContents(); in foldIdenticalLiterals()
1320 for (Symbol *sym : symtab->getSymbols()) in addSynthenticMethnames()
1336 isec->splitIntoPieces(); in addSynthenticMethnames()
1337 for (auto &piece : isec->pieces) in addSynthenticMethnames()
1340 in.objcMethnameSection->addInput(isec); in addSynthenticMethnames()
1341 in.objcMethnameSection->isec->markLive(0); in addSynthenticMethnames()
1345 bool needsStubHelper = config->outputType == MH_DYLIB || in referenceStubBinder()
1346 config->outputType == MH_EXECUTE || in referenceStubBinder()
1347 config->outputType == MH_BUNDLE; in referenceStubBinder()
1348 if (!needsStubHelper || !symtab->find("dyld_stub_binder")) in referenceStubBinder()
1358 symtab->addUndefined("dyld_stub_binder", /*file=*/nullptr, /*isWeak=*/false); in referenceStubBinder()
1362 for (const auto &pair : config->aliasedSymbols) { in createAliases()
1363 if (const auto &sym = symtab->find(pair.first)) { in createAliases()
1365 symtab->aliasDefined(defined, pair.second, defined->getFile()) in createAliases()
1366 ->noDeadStrip = true; in createAliases()
1369 Twine(sym->kind())); in createAliases()
1379 for (const AliasSymbol *alias : objFile->aliases) { in createAliases()
1380 if (const auto &aliased = symtab->find(alias->getAliasedName())) { in createAliases()
1382 symtab->aliasDefined(defined, alias->getName(), alias->getFile(), in createAliases()
1383 alias->privateExtern); in createAliases()
1389 Twine(aliased->kind())); in createAliases()
1395 fatal("unable to find alias referent " + alias->getAliasedName() + in createAliases()
1396 " for " + alias->getName()); in createAliases()
1405 if (config->hasExplicitExports) { in handleExplicitExports()
1407 parallelForEach(symtab->getSymbols(), [&warningsCount](Symbol *sym) { in handleExplicitExports()
1409 if (config->exportedSymbols.match(sym->getName())) { in handleExplicitExports()
1410 if (defined->privateExtern) { in handleExplicitExports()
1411 if (defined->weakDefCanBeHidden) { in handleExplicitExports()
1416 defined->privateExtern = false; in handleExplicitExports()
1423 "\n>>> defined in " + toString(defined->getFile())); in handleExplicitExports()
1427 defined->privateExtern = true; in handleExplicitExports()
1430 dysym->shouldReexport = config->exportedSymbols.match(sym->getName()); in handleExplicitExports()
1434 warn("<... " + Twine(warningsCount - kMaxWarnings) + in handleExplicitExports()
1436 } else if (!config->unexportedSymbols.empty()) { in handleExplicitExports()
1437 parallelForEach(symtab->getSymbols(), [](Symbol *sym) { in handleExplicitExports()
1439 if (config->unexportedSymbols.match(defined->getName())) in handleExplicitExports()
1440 defined->privateExtern = true; in handleExplicitExports()
1446 for (ConcatInputSection *isec : in.initOffsets->inputs()) in eraseInitializerSymbols()
1447 for (Defined *sym : isec->symbols) in eraseInitializerSymbols()
1448 sym->used = false; in eraseInitializerSymbols()
1455 StringRef val = arg->getValue(); in getRuntimePaths()
1458 else if (config->warnDuplicateRpath) in getRuntimePaths()
1459 warn("duplicate -rpath '" + val + "' ignored [--warn-duplicate-rpath]"); in getRuntimePaths()
1468 // This driver-specific context will be freed later by lldMain(). in link()
1471 ctx->e.initialize(stdoutOS, stderrOS, exitEarly, disableOutput); in link()
1472 ctx->e.cleanupCallback = []() { in link()
1500 ctx->e.logName = args::getFilenameWithoutExe(argsArr[0]); in link()
1505 ctx->e.errorLimitExceededMsg = "too many errors emitted, stopping now " in link()
1506 "(use --error-limit=0 to see all errors)"; in link()
1507 ctx->e.errorLimit = args::getInteger(args, OPT_error_limit_eq, 20); in link()
1508 ctx->e.verbose = args.hasArg(OPT_verbose); in link()
1523 config = std::make_unique<Configuration>(); in link()
1525 config->outputType = getOutputType(args); in link()
1530 config->ltoo = args::getInteger(args, OPT_lto_O, 2); in link()
1531 if (config->ltoo > 3) in link()
1532 error("--lto-O: invalid optimization level: " + Twine(config->ltoo)); in link()
1534 args::getInteger(args, OPT_lto_CGO, args::getCGOptLevel(config->ltoo)); in link()
1536 config->ltoCgo = *level; in link()
1538 error("--lto-CGO: invalid codegen optimization level: " + Twine(ltoCgo)); in link()
1547 // page size, but assumes the page size is 4K. This doesn't work with most in link()
1550 // probably only happened because no one using this arg with anything other in link()
1555 if (!isAligned(Align(target->getPageSize()), pagezeroSize)) { in link()
1556 pagezeroSize -= pagezeroSize % target->getPageSize(); in link()
1561 target->pageZeroSize = pagezeroSize; in link()
1564 config->osoPrefix = args.getLastArgValue(OPT_oso_prefix); in link()
1565 if (!config->osoPrefix.empty()) { in link()
1575 if (!fs::real_path(config->osoPrefix, expanded, in link()
1583 if (config->osoPrefix == "." || config->osoPrefix.ends_with(sep)) in link()
1585 config->osoPrefix = saver().save(expanded.str()); in link()
1591 warn("-no_pie ignored for arm64"); in link()
1595 config->isPic = config->outputType == MH_DYLIB || in link()
1596 config->outputType == MH_BUNDLE || in link()
1597 (config->outputType == MH_EXECUTE && pie); in link()
1600 config->deadStrip = args.hasArg(OPT_dead_strip); in link()
1602 config->systemLibraryRoots = getSystemLibraryRoots(args); in link()
1604 // Note that --reproduce is a debug option so you can ignore it in link()
1610 tar->append("response.txt", createResponseFile(args)); in link()
1611 tar->append("version.txt", getLLDVersion() + "\n"); in link()
1613 error("--reproduce: " + toString(errOrWriter.takeError())); in link()
1618 StringRef v(arg->getValue()); in link()
1621 error(arg->getSpelling() + ": expected a positive integer, but got '" + in link()
1622 arg->getValue() + "'"); in link()
1624 config->thinLTOJobs = v; in link()
1627 config->thinLTOJobs = arg->getValue(); in link()
1628 if (!get_threadpool_strategy(config->thinLTOJobs)) in link()
1629 error("--thinlto-jobs: invalid job count: " + config->thinLTOJobs); in link()
1632 config->explicitUndefineds.push_back(symtab->addUndefined( in link()
1633 arg->getValue(), /*file=*/nullptr, /*isWeakRef=*/false)); in link()
1637 config->explicitDynamicLookups.insert(arg->getValue()); in link()
1639 config->mapFile = args.getLastArgValue(OPT_map); in link()
1640 config->optimize = args::getInteger(args, OPT_O, 1); in link()
1641 config->outputFile = args.getLastArgValue(OPT_o, "a.out"); in link()
1642 config->finalOutput = in link()
1643 args.getLastArgValue(OPT_final_output, config->outputFile); in link()
1644 config->astPaths = args.getAllArgValues(OPT_add_ast_path); in link()
1645 config->headerPad = args::getHex(args, OPT_headerpad, /*Default=*/32); in link()
1646 config->headerPadMaxInstallNames = in link()
1648 config->printDylibSearch = in link()
1650 config->printEachFile = args.hasArg(OPT_t); in link()
1651 config->printWhyLoad = args.hasArg(OPT_why_load); in link()
1652 config->omitDebugInfo = args.hasArg(OPT_S); in link()
1653 config->errorForArchMismatch = args.hasArg(OPT_arch_errors_fatal); in link()
1655 if (config->outputType != MH_BUNDLE) in link()
1656 error("-bundle_loader can only be used with MachO bundle output"); in link()
1657 addFile(arg->getValue(), LoadType::CommandLine, /*isLazy=*/false, in link()
1661 StringRef envPair(arg->getValue()); in link()
1663 error("-dyld_env's argument is malformed. Expected " in link()
1664 "-dyld_env <ENV_VAR>=<VALUE>, got `" + in link()
1666 config->dyldEnvs.push_back(envPair); in link()
1668 if (!config->dyldEnvs.empty() && config->outputType != MH_EXECUTE) in link()
1669 error("-dyld_env can only be used when creating executable output"); in link()
1672 if (config->outputType != MH_DYLIB) in link()
1673 warn("-umbrella used, but not creating dylib"); in link()
1674 config->umbrella = arg->getValue(); in link()
1676 config->ltoObjPath = args.getLastArgValue(OPT_object_path_lto); in link()
1677 config->thinLTOCacheDir = args.getLastArgValue(OPT_cache_path_lto); in link()
1678 config->thinLTOCachePolicy = getLTOCachePolicy(args); in link()
1679 config->thinLTOEmitImportsFiles = args.hasArg(OPT_thinlto_emit_imports_files); in link()
1680 config->thinLTOEmitIndexFiles = args.hasArg(OPT_thinlto_emit_index_files) || in link()
1683 config->thinLTOIndexOnly = args.hasArg(OPT_thinlto_index_only) || in link()
1685 config->thinLTOIndexOnlyArg = args.getLastArgValue(OPT_thinlto_index_only_eq); in link()
1686 config->thinLTOObjectSuffixReplace = in link()
1688 std::tie(config->thinLTOPrefixReplaceOld, config->thinLTOPrefixReplaceNew, in link()
1689 config->thinLTOPrefixReplaceNativeObject) = in link()
1691 if (config->thinLTOEmitIndexFiles && !config->thinLTOIndexOnly) { in link()
1693 error("--thinlto-object-suffix-replace is not supported with " in link()
1694 "--thinlto-emit-index-files"); in link()
1696 error("--thinlto-prefix-replace is not supported with " in link()
1697 "--thinlto-emit-index-files"); in link()
1699 if (!config->thinLTOPrefixReplaceNativeObject.empty() && in link()
1700 config->thinLTOIndexOnlyArg.empty()) { in link()
1701 error("--thinlto-prefix-replace=old_dir;new_dir;obj_dir must be used with " in link()
1702 "--thinlto-index-only="); in link()
1704 config->warnDuplicateRpath = in link()
1706 config->runtimePaths = getRuntimePaths(args); in link()
1707 config->allLoad = args.hasFlag(OPT_all_load, OPT_noall_load, false); in link()
1708 config->archMultiple = args.hasArg(OPT_arch_multiple); in link()
1709 config->applicationExtension = args.hasFlag( in link()
1711 config->exportDynamic = args.hasArg(OPT_export_dynamic); in link()
1712 config->forceLoadObjC = args.hasArg(OPT_ObjC); in link()
1713 config->forceLoadSwift = args.hasArg(OPT_force_load_swift_libs); in link()
1714 config->deadStripDylibs = args.hasArg(OPT_dead_strip_dylibs); in link()
1715 config->demangle = args.hasArg(OPT_demangle); in link()
1716 config->implicitDylibs = !args.hasArg(OPT_no_implicit_dylibs); in link()
1717 config->emitFunctionStarts = in link()
1719 config->emitDataInCodeInfo = in link()
1721 config->emitChainedFixups = shouldEmitChainedFixups(args); in link()
1722 config->emitInitOffsets = in link()
1723 config->emitChainedFixups || args.hasArg(OPT_init_offsets); in link()
1724 config->emitRelativeMethodLists = shouldEmitRelativeMethodLists(args); in link()
1725 config->icfLevel = getICFLevel(args); in link()
1726 config->keepICFStabs = args.hasArg(OPT_keep_icf_stabs); in link()
1727 config->dedupStrings = in link()
1729 config->deadStripDuplicates = args.hasArg(OPT_dead_strip_duplicates); in link()
1730 config->warnDylibInstallName = args.hasFlag( in link()
1732 config->ignoreOptimizationHints = args.hasArg(OPT_ignore_optimization_hints); in link()
1733 config->callGraphProfileSort = args.hasFlag( in link()
1735 config->printSymbolOrder = args.getLastArgValue(OPT_print_symbol_order_eq); in link()
1736 config->forceExactCpuSubtypeMatch = in link()
1738 config->objcStubsMode = getObjCStubsMode(args); in link()
1739 config->ignoreAutoLink = args.hasArg(OPT_ignore_auto_link); in link()
1741 config->ignoreAutoLinkOptions.insert(arg->getValue()); in link()
1742 config->strictAutoLink = args.hasArg(OPT_strict_auto_link); in link()
1743 config->ltoDebugPassManager = args.hasArg(OPT_lto_debug_pass_manager); in link()
1744 config->csProfileGenerate = args.hasArg(OPT_cs_profile_generate); in link()
1745 config->csProfilePath = args.getLastArgValue(OPT_cs_profile_path); in link()
1746 config->pgoWarnMismatch = in link()
1748 config->warnThinArchiveMissingMembers = in link()
1751 config->generateUuid = !args.hasArg(OPT_no_uuid); in link()
1754 config->aliasedSymbols.push_back( in link()
1755 std::make_pair(arg->getValue(0), arg->getValue(1))); in link()
1759 config->zeroModTime = strcmp(zero, "0") != 0; in link()
1761 config->zeroModTime = true; in link()
1765 config->emitEncryptionInfo = in link()
1767 is_contained(encryptablePlatforms, config->platform())); in link()
1770 if (config->warnDylibInstallName && config->outputType != MH_DYLIB) in link()
1772 arg->getAsString(args) + in link()
1773 ": ignored, only has effect with -dylib [--warn-dylib-install-name]"); in link()
1775 config->installName = arg->getValue(); in link()
1776 } else if (config->outputType == MH_DYLIB) { in link()
1777 config->installName = config->finalOutput; in link()
1781 if (config->outputType != MH_DYLIB) in link()
1782 warn("-mark_dead_strippable_dylib: ignored, only has effect with -dylib"); in link()
1784 config->markDeadStrippableDylib = true; in link()
1788 config->staticLink = (arg->getOption().getID() == OPT_static); in link()
1792 config->namespaceKind = arg->getOption().getID() == OPT_twolevel_namespace in link()
1796 config->undefinedSymbolTreatment = getUndefinedSymbolTreatment(args); in link()
1798 if (config->outputType == MH_EXECUTE) in link()
1799 config->entry = symtab->addUndefined(args.getLastArgValue(OPT_e, "_main"), in link()
1803 config->librarySearchPaths = in link()
1804 getLibrarySearchPaths(args, config->systemLibraryRoots); in link()
1805 config->frameworkSearchPaths = in link()
1806 getFrameworkSearchPaths(args, config->systemLibraryRoots); in link()
1809 config->searchDylibsFirst = in link()
1810 arg->getOption().getID() == OPT_search_dylibs_first; in link()
1812 config->dylibCompatibilityVersion = in link()
1814 config->dylibCurrentVersion = parseDylibVersion(args, OPT_current_version); in link()
1816 config->dataConst = in link()
1818 // Populate config->sectionRenameMap with builtin default renames. in link()
1819 // Options -rename_section and -rename_segment are able to override. in link()
1823 StringRef invalidNameChars("!\"#%&'()*+,-/:;<=>?@[\\]^`{|}~"); in link()
1830 config->sectionRenameMap[{validName(arg->getValue(0)), in link()
1831 validName(arg->getValue(1))}] = { in link()
1832 validName(arg->getValue(2)), validName(arg->getValue(3))}; in link()
1835 config->segmentRenameMap[validName(arg->getValue(0))] = in link()
1836 validName(arg->getValue(1)); in link()
1839 config->sectionAlignments = parseSectAlign(args); in link()
1842 StringRef segName = arg->getValue(0); in link()
1843 uint32_t maxProt = parseProtection(arg->getValue(1)); in link()
1844 uint32_t initProt = parseProtection(arg->getValue(2)); in link()
1845 if (maxProt != initProt && config->arch() != AK_i386) in link()
1846 error("invalid argument '" + arg->getAsString(args) + in link()
1847 "': max and init must be the same for non-i386 archs"); in link()
1849 error("-segprot cannot be used to change __LINKEDIT's protections"); in link()
1850 config->segmentProtections.push_back({segName, maxProt, initProt}); in link()
1853 config->hasExplicitExports = in link()
1856 handleSymbolPatterns(args, config->exportedSymbols, OPT_exported_symbol, in link()
1858 handleSymbolPatterns(args, config->unexportedSymbols, OPT_unexported_symbol, in link()
1860 if (config->hasExplicitExports && !config->unexportedSymbols.empty()) in link()
1861 error("cannot use both -exported_symbol* and -unexported_symbol* options"); in link()
1863 if (args.hasArg(OPT_no_exported_symbols) && !config->exportedSymbols.empty()) in link()
1864 error("cannot use both -exported_symbol* and -no_exported_symbols options"); in link()
1867 // -non_global_symbols_no_strip_list and -non_global_symbols_strip_list can't in link()
1869 // But -x can be used with either of these two, in which case, the last arg in link()
1871 // (TODO: This is kind of confusing - considering disallowing using them in link()
1879 switch (arg->getOption().getID()) { in link()
1881 config->localSymbolsPresence = SymtabPresence::None; in link()
1885 error("cannot use both -non_global_symbols_no_strip_list and " in link()
1886 "-non_global_symbols_strip_list"); in link()
1889 config->localSymbolsPresence = SymtabPresence::SelectivelyIncluded; in link()
1890 parseSymbolPatternsFile(arg, config->localSymbolPatterns); in link()
1895 error("cannot use both -non_global_symbols_no_strip_list and " in link()
1896 "-non_global_symbols_strip_list"); in link()
1899 config->localSymbolsPresence = SymtabPresence::SelectivelyExcluded; in link()
1900 parseSymbolPatternsFile(arg, config->localSymbolPatterns); in link()
1908 // Explicitly-exported literal symbols must be defined, but might in link()
1910 // non-global strip list. Light a fire under those lazy symbols! in link()
1911 for (const CachedHashStringRef &cachedName : config->exportedSymbols.literals) in link()
1912 symtab->addUndefined(cachedName.val(), /*file=*/nullptr, in link()
1916 config->whyLive.insert(arg->getValue()); in link()
1917 if (!config->whyLive.empty() && !config->deadStrip) in link()
1918 warn("-why_live has no effect without -dead_strip, ignoring"); in link()
1920 config->saveTemps = args.hasArg(OPT_save_temps); in link()
1922 config->adhocCodesign = args.hasFlag( in link()
1924 shouldAdhocSignByDefault(config->arch(), config->platform())); in link()
1929 (config->librarySearchPaths.empty() in link()
1931 : "\n\t" + join(config->librarySearchPaths, "\n\t")), in link()
1934 (config->frameworkSearchPaths.empty() in link()
1936 : "\n\t" + join(config->frameworkSearchPaths, "\n\t")), in link()
1940 config->progName = argsArr[0]; in link()
1942 config->timeTraceEnabled = args.hasArg(OPT_time_trace_eq); in link()
1943 config->timeTraceGranularity = in link()
1947 if (config->timeTraceEnabled) in link()
1948 timeTraceProfilerInitialize(config->timeTraceGranularity, config->progName); in link()
1957 // re-exported. in link()
1961 config->hasReexports = true; in link()
1962 StringRef searchName = arg->getValue(); in link()
1964 error(arg->getSpelling() + " " + searchName + in link()
1980 parseClangOption(saver().save("-mcpu=" + StringRef(arg->getValue())), in link()
1981 arg->getSpelling()); in link()
1984 parseClangOption(arg->getValue(), arg->getSpelling()); in link()
1985 config->mllvmOpts.emplace_back(arg->getValue()); in link()
2002 // If --thinlto-index-only is given, we should create only "index in link()
2005 if (config->thinLTOIndexOnly) in link()
2008 // LTO may emit a non-hidden (extern) object file symbol even if the in link()
2010 // cross-module references to hidden symbols under ThinLTO. Thus, if we in link()
2026 StringRef segName = arg->getValue(0); in link()
2027 StringRef sectName = arg->getValue(1); in link()
2028 StringRef fileName = arg->getValue(2); in link()
2035 StringRef segName = arg->getValue(0); in link()
2036 StringRef sectName = arg->getValue(1); in link()
2041 if (config->callGraphProfileSort) in link()
2044 if (config->deadStrip) in link()
2048 // removed due to -init_offsets. This must run after dead stripping. in link()
2049 if (config->emitInitOffsets) in link()
2052 // Categories are not subject to dead-strip. The __objc_catlist section is in link()
2057 // Category merging uses "->live = false" to erase old category data, so in link()
2058 // it has to run after dead-stripping (markLive). in link()
2066 if (config->icfLevel != ICFLevel::none) { in link()
2067 if (config->icfLevel == ICFLevel::safe) in link()
2070 } else if (config->dedupStrings) { in link()
2075 if (target->wordSize == 8) in link()
2080 depTracker->write(getLLDVersion(), inputFiles, config->outputFile); in link()
2083 if (config->timeTraceEnabled) { in link()
2085 args.getLastArgValue(OPT_time_trace_eq).str(), config->outputFile)); in link()
2090 if (errorCount() != 0 || config->strictAutoLink) in link()