Lines Matching +full:dll +full:- +full:config
1 //===- Driver.cpp ---------------------------------------------------------===//
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
11 #include "Config.h"
29 #include "llvm/Config/llvm-config.h"
51 #include "llvm/ToolDrivers/llvm-lib/LibDriver.h"
67 // This driver-specific context will be freed later by unsafeLldMain().
70 ctx->e.initialize(stdoutOS, stderrOS, exitEarly, disableOutput);
71 ctx->e.logName = args::getFilenameWithoutExe(args[0]);
72 ctx->e.errorLimitExceededMsg = "too many errors emitted, stopping now"
75 ctx->driver.linkerMain(args);
87 StringRef s = arg->getValue();
90 error(arg->getSpelling() + " expects 'old;new' format, but got " + s);
103 // ".exe", ".dll" or ".sys".
107 ext = ".dll";
136 // asynchronously. But 32-bit has issues with potentially launching tons
153 assert(ctx.config.machine != IMAGE_FILE_MACHINE_UNKNOWN);
154 if (ctx.config.machine == I386)
160 return getMachineArchType(ctx.config.machine);
173 ctx.driver.tar->append(relativeToRoot(mbref.getBufferIdentifier()),
180 StringRef filename = mb->getBufferIdentifier();
199 addArchiveBuffer(m, "<whole-archive>", filename, memberIndex++);
218 if (ctx.config.mingw) {
222 if (filename.ends_with_insensitive(".dll")) {
223 error(filename + ": bad file type. Did you specify a DLL instead of an "
240 auto [mb, ec] = future->get();
283 imp->parentName = parentName;
303 obj->parentName = parentName;
318 if (!c.getParent()->isThin()) {
339 auto mbOrErr = future->get();
343 mbOrErr.first->getBufferIdentifier());
354 (!ctx.config.mingw && sym.contains('@'));
360 StringRef s = file->getDirectives();
380 if (ctx.config.machine == I386 && ctx.config.mingw) {
387 ctx.config.exports.push_back(exp);
394 // Handle /exclude-symbols: in bulk.
402 // https://docs.microsoft.com/en-us/cpp/preprocessor/comment-c-cpp?view=msvc-160
404 switch (arg->getOption().getID()) {
406 parseAligncomm(arg->getValue());
409 parseAlternateName(arg->getValue());
412 if (std::optional<StringRef> path = findLibIfNew(arg->getValue()))
416 if (!arg->getValue()[0])
418 ctx.config.entry = addUndefined(mangle(arg->getValue()));
421 checkFailIfMismatch(arg->getValue(), file);
424 addUndefined(arg->getValue());
427 ctx.config.manifestDependencies.insert(arg->getValue());
430 parseMerge(arg->getValue());
433 ctx.config.noDefaultLibs.insert(findLib(arg->getValue()).lower());
436 ctx.config.writeCheckSum = true;
439 parseSection(arg->getValue());
442 parseNumbers(arg->getValue(), &ctx.config.stackReserve,
443 &ctx.config.stackCommit);
447 parseSubsystem(arg->getValue(), &ctx.config.subsystem,
448 &ctx.config.majorSubsystemVersion,
449 &ctx.config.minorSubsystemVersion, &gotVersion);
451 ctx.config.majorOSVersion = ctx.config.majorSubsystemVersion;
452 ctx.config.minorOSVersion = ctx.config.minorSubsystemVersion;
457 // `#pragma comment(linker, "/flag")`-generated sections.
465 error(arg->getSpelling() + " is not allowed in .drectve (" +
474 auto getFilename = [this](StringRef filename) -> StringRef {
475 if (ctx.config.vfs)
476 if (auto statOrErr = ctx.config.vfs->status(filename))
477 return saver().save(statOrErr->getName());
544 if (ctx.config.mingw && ret == filename)
553 if (ctx.config.noDefaultLibAll)
559 if (ctx.config.noDefaultLibs.count(path.lower()))
577 VCToolsDir = A->getValue();
579 VCToolsVersion = A->getValue();
581 WinSysRoot = A->getValue();
596 diaPath = A->getValue();
597 if (A->getOption().getID() == OPT_winsysroot)
607 WinSdkDir = A->getValue();
609 WinSdkVersion = A->getValue();
638 sys::path::remove_filename(binDir); // remove lld-link.exe
701 if (!b->isGCRoot) {
702 b->isGCRoot = true;
703 ctx.config.gcroot.push_back(b);
715 Symbol *mangled = ctx.symtab.findMangle(unmangled->getName());
721 log(unmangled->getName() + " aliased to " + mangled->getName());
722 unmangled->weakAlias = ctx.symtab.addUndefined(mangled->getName());
723 return mangled->getName();
726 // Windows specific -- find default entry point name.
729 // each of which corresponds to a user-defined "main" function. This function
730 // infers an entry point from a user-defined "main" function.
732 assert(ctx.config.subsystem != IMAGE_SUBSYSTEM_UNKNOWN &&
735 if (ctx.config.mingw)
736 return mangle(ctx.config.subsystem == IMAGE_SUBSYSTEM_WINDOWS_GUI
740 if (ctx.config.subsystem == IMAGE_SUBSYSTEM_WINDOWS_GUI) {
757 if (ctx.config.dll)
759 if (ctx.config.mingw)
782 if (ctx.config.is64())
783 return ctx.config.dll ? 0x180000000 : 0x140000000;
784 return ctx.config.dll ? 0x10000000 : 0x400000;
793 // Reconstructs command line arguments so that so that you can re-run
794 // the same command with the same inputs. This is for --reproduce.
802 switch (arg->getOption().getID()) {
814 os << arg->getSpelling() << quote(rewritePath(arg->getValue())) << '\n';
817 StringRef orderFile = arg->getValue();
819 os << arg->getSpelling() << '@' << quote(rewritePath(orderFile)) << '\n';
824 StringRef(arg->getValue()).split("=");
825 os << arg->getSpelling() << nameFile.first << '='
834 os << arg->getSpelling() << sys::path::filename(arg->getValue()) << "\n";
857 StringRef(a->getValue())
858 .split(types, ',', /*MaxSplit=*/-1, /*KeepEmpty=*/false);
891 if (arg->getOption().getID() == osFile.getID())
892 return arg->getValue();
894 assert(arg->getOption().getID() == os.getID());
895 StringRef outFile = ctx.config.outputFile;
900 if (!ctx.config.implib.empty())
901 return std::string(ctx.config.implib);
902 SmallString<128> out = StringRef(ctx.config.outputFile);
910 // -----+----------------+---------------------+------------------
911 // LINK | {value} | {value}.{.dll/.exe} | {output name}
912 // LIB | {value} | {value}.dll | {output name}.dll
917 if (ctx.config.importName.empty()) {
918 out.assign(sys::path::filename(ctx.config.outputFile));
920 sys::path::replace_extension(out, ".dll");
922 out.assign(ctx.config.importName);
925 (ctx.config.dll || asLib) ? ".dll" : ".exe");
934 for (Export &e1 : ctx.config.exports) {
952 if (!ctx.config.incremental) {
953 checkError(writeImportLibrary(libName, path, exports, ctx.config.machine,
954 ctx.config.mingw));
963 checkError(writeImportLibrary(libName, path, exports, ctx.config.machine,
964 ctx.config.mingw));
970 sys::fs::createUniqueFile(path + ".tmp-%%%%%%%%.lib", tmpName))
975 ctx.config.machine, ctx.config.mingw)) {
982 if ((*oldBuf)->getBuffer() != newBuf->getBuffer()) {
983 oldBuf->reset();
998 mb->getMemBufferRef(), ctx.config.machine, ctx.config.mingw));
1003 if (ctx.config.outputFile.empty())
1004 ctx.config.outputFile = std::string(saver().save(m.OutputFile));
1005 ctx.config.importName = std::string(saver().save(m.ImportName));
1007 ctx.config.imageBase = m.ImageBase;
1009 ctx.config.stackReserve = m.StackReserve;
1011 ctx.config.stackCommit = m.StackCommit;
1013 ctx.config.heapReserve = m.HeapReserve;
1015 ctx.config.heapCommit = m.HeapCommit;
1017 ctx.config.majorImageVersion = m.MajorImageVersion;
1019 ctx.config.minorImageVersion = m.MinorImageVersion;
1021 ctx.config.majorOSVersion = m.MajorOSVersion;
1023 ctx.config.minorOSVersion = m.MinorOSVersion;
1029 // function but a forward to another DLL instead. This is supported
1047 ctx.config.exports.push_back(e2);
1082 if (sec->sym)
1083 set.insert(sec->sym->getName());
1097 for (StringRef arg : args::getLines(mb->getMemBufferRef())) {
1099 if (ctx.config.machine == I386 && !isDecorated(s))
1103 if (ctx.config.warnMissingOrderSymbol)
1106 ctx.config.order[s] = INT_MIN + ctx.config.order.size();
1123 for (Symbol *sym : file->getSymbols())
1125 map[sym->getName()] = sym;
1127 auto findSection = [&](StringRef name) -> SectionChunk * {
1130 if (ctx.config.warnMissingOrderSymbol)
1136 return dyn_cast_or_null<SectionChunk>(dr->getChunk());
1152 ctx.config.callGraphProfile[{from, to}] += count;
1161 if (obj->callgraphSec) {
1164 obj->getCOFFObj()->getSectionContents(obj->callgraphSec, contents));
1170 fatal(toString(obj) + ": Expected 32-bit integer");
1172 fatal(toString(obj) + ": Expected 32-bit integer");
1174 fatal(toString(obj) + ": Expected 64-bit integer");
1175 auto *fromSym = dyn_cast_or_null<Defined>(obj->getSymbol(fromIndex));
1176 auto *toSym = dyn_cast_or_null<Defined>(obj->getSymbol(toIndex));
1179 auto *from = dyn_cast_or_null<SectionChunk>(fromSym->getChunk());
1180 auto *to = dyn_cast_or_null<SectionChunk>(toSym->getChunk());
1182 ctx.config.callGraphProfile[{from, to}] += count;
1190 if (SectionChunk *c = dyn_cast_or_null<SectionChunk>(d->getChunk()))
1191 c->keepUnique = true;
1197 // Exported symbols could be address-significant in other executables or DSOs,
1198 // so we conservatively mark them as address-significant.
1199 for (Export &r : ctx.config.exports)
1202 // Visit the address-significance table in each object file and mark each
1203 // referenced symbol as address-significant.
1205 ArrayRef<Symbol *> syms = obj->getSymbols();
1206 if (obj->addrsigSec) {
1209 obj->getCOFFObj()->getSectionContents(obj->addrsigSec, contents));
1223 // If an object file does not have an address-significance table,
1224 // conservatively mark all of its symbols as address-significant.
1240 sys::path::filename(ctx.config.pdbPath, sys::path::Style::windows);
1242 sys::path::extension(ctx.config.outputFile, sys::path::Style::windows);
1247 // +--------- cursor ('a...' might be the empty string).
1248 // | +----- firstMark
1249 // | | +- secondMark
1253 while (cursor < ctx.config.pdbAltPath.size()) {
1255 if ((firstMark = ctx.config.pdbAltPath.find('%', cursor)) ==
1257 (secondMark = ctx.config.pdbAltPath.find('%', firstMark + 1)) ==
1260 buf.append(ctx.config.pdbAltPath.substr(cursor));
1266 buf.append(ctx.config.pdbAltPath.substr(cursor, firstMark - cursor));
1268 ctx.config.pdbAltPath.substr(firstMark, secondMark - firstMark + 1);
1282 ctx.config.pdbAltPath = buf;
1293 if (f->isResourceObjFile())
1297 if (!ctx.config.mingw &&
1311 f->includeResourceChunks();
1317 f->includeResourceChunks();
1322 // -export-all-symbols option, so that it happens even when exports are
1324 // -exclude-all-symbols option, so that lld-link behaves like link.exe rather
1328 if (!ctx.config.dll)
1331 if (!ctx.config.exports.empty())
1340 if (std::optional<StringRef> path = findFile(arg->getValue()))
1345 StringRef(arg->getValue()).split(vec, ',');
1355 if (!def->isGCRoot) {
1356 def->isGCRoot = true;
1357 ctx.config.gcroot.push_back(def);
1361 e.name = def->getName();
1363 if (Chunk *c = def->getChunk())
1364 if (!(c->getOutputCharacteristics() & IMAGE_SCN_MEM_EXECUTE))
1366 s->isUsedInRegularObj = true;
1367 ctx.config.exports.push_back(e);
1380 return std::string(arg->getValue());
1383 SmallString<64> path = StringRef(arg->getValue());
1404 auto bufOrErr = llvm::MemoryBuffer::getFile(arg->getValue());
1411 /*DiagHandler*/ nullptr, arg->getValue()))
1420 Configuration *config = &ctx.config;
1433 StringRef(argsArr[1]).equals_insensitive("-lib"))) {
1444 config->timeTraceEnabled = args.hasArg(OPT_time_trace_eq);
1445 config->timeTraceGranularity =
1448 if (config->timeTraceEnabled)
1449 timeTraceProfilerInitialize(config->timeTraceGranularity, argsArr[0]);
1453 // Parse and evaluate -mllvm options.
1455 v.push_back("lld-link (LLVM option parsing)");
1457 v.push_back(arg->getValue());
1458 config->mllvmOpts.emplace_back(arg->getValue());
1469 StringRef s = arg->getValue();
1471 error(arg->getSpelling() + " number expected, but got " + s);
1475 config->vfs = getVFS(args);
1486 StringRef v(arg->getValue());
1489 error(arg->getSpelling() + ": expected a positive integer, but got '" +
1490 arg->getValue() + "'");
1492 config->thinLTOJobs = v.str();
1496 config->showTiming = true;
1498 config->showSummary = args.hasArg(OPT_summary);
1499 config->printSearchPaths = args.hasArg(OPT_print_search_paths);
1501 // Handle --version, which is an lld extension. This option is a bit odd
1502 // because it doesn't start with "/", but we deliberately chose "--" to
1503 // avoid conflict with /version and for compatibility with clang-cl.
1511 config->mingw = args.hasArg(OPT_lldmingw);
1512 if (config->mingw)
1514 " (use --error-limit=0 to see all errors)";
1534 config->noEntry = true;
1544 searchPaths.push_back(arg->getValue());
1545 if (!config->mingw) {
1565 StringRef(arg->getValue()).split(vec, ',');
1568 config->warnMissingOrderSymbol = false;
1570 config->warnDebugInfoUnusable = false;
1572 config->warnLocallyDefinedImported = false;
1574 config->warnLongSectionNames = false;
1581 config->outputFile = arg->getValue();
1585 config->verbose = true;
1586 errorHandler().verbose = config->verbose;
1590 config->forceUnresolved = true;
1594 config->forceMultiple = true;
1598 config->forceMultipleRes = true;
1601 // when -debug:dwarf is requested, handled below).
1602 if (config->mingw)
1603 config->warnLongSectionNames = false;
1611 if (arg->getOption().getID() == OPT_debug)
1614 str = StringRef(arg->getValue()).lower();
1623 config->debug = false;
1624 config->incremental = false;
1625 config->includeDwarfChunks = false;
1626 config->debugGHashes = false;
1627 config->writeSymtab = false;
1631 config->debug = true;
1632 config->incremental = true;
1633 config->includeDwarfChunks = true;
1635 config->debugGHashes = true;
1639 config->debug = true;
1640 config->incremental = true;
1641 config->includeDwarfChunks = true;
1642 config->writeSymtab = true;
1643 config->warnLongSectionNames = false;
1646 config->includeDwarfChunks = false;
1648 config->writeSymtab = true;
1651 config->writeSymtab = false;
1659 config->demangle = args.hasFlag(OPT_demangle, OPT_demangle_no, true);
1662 config->debugTypes = parseDebugTypes(args);
1665 config->driverUponly = args.hasArg(OPT_driver_uponly) ||
1668 config->driverWdm = args.hasArg(OPT_driver_wdm) ||
1671 config->driver =
1672 config->driverUponly || config->driverWdm || args.hasArg(OPT_driver);
1677 config->pdbPath = arg->getValue();
1679 config->pdbAltPath = arg->getValue();
1681 parsePDBPageSize(arg->getValue());
1683 config->natvisFiles = args.getAllArgValues(OPT_natvis);
1689 config->namedStreams[name] = file;
1694 config->pdbSourcePath = arg->getValue();
1704 config->noEntry = true;
1706 error("/noentry must be specified with /dll");
1709 // Handle /dll
1711 config->dll = true;
1712 config->manifestID = 2;
1720 dynamicBaseArg->getOption().getID() == OPT_dynamicbase_no)
1721 config->dynamicBase = false;
1723 // MSDN claims "/FIXED:NO is the default setting for a DLL, and /FIXED is the
1729 dynamicBaseArg->getOption().getID() == OPT_dynamicbase) {
1732 config->relocatable = false;
1733 config->dynamicBase = false;
1738 config->appContainer =
1745 config->machine = getMachineType(arg->getValue());
1746 if (config->machine == IMAGE_FILE_MACHINE_UNKNOWN)
1747 fatal(Twine("unknown /machine argument: ") + arg->getValue());
1756 config->noDefaultLibs.insert(findLib(arg->getValue()).lower());
1761 config->noDefaultLibAll = true;
1765 parseNumbers(arg->getValue(), &config->imageBase);
1769 parseNumbers(arg->getValue(), &config->fileAlign);
1770 if (!isPowerOf2_64(config->fileAlign))
1771 error("/filealign: not a power of two: " + Twine(config->fileAlign));
1776 parseNumbers(arg->getValue(), &config->stackReserve, &config->stackCommit);
1780 parseGuard(arg->getValue());
1784 parseNumbers(arg->getValue(), &config->heapReserve, &config->heapCommit);
1788 parseVersion(arg->getValue(), &config->majorImageVersion,
1789 &config->minorImageVersion);
1793 parseSubsystem(arg->getValue(), &config->subsystem,
1794 &config->majorSubsystemVersion,
1795 &config->minorSubsystemVersion);
1799 parseVersion(arg->getValue(), &config->majorOSVersion,
1800 &config->minorOSVersion);
1802 config->majorOSVersion = config->majorSubsystemVersion;
1803 config->minorOSVersion = config->minorSubsystemVersion;
1808 if (arg->getOption().getID() == OPT_repro) {
1809 config->timestamp = 0;
1810 config->repro = true;
1812 config->repro = false;
1813 StringRef value(arg->getValue());
1814 if (value.getAsInteger(0, config->timestamp))
1816 ". Expected 32-bit integer");
1819 config->repro = false;
1823 if (value.getAsInteger(0, config->timestamp))
1825 ". Expected 32-bit integer");
1827 config->timestamp = time(nullptr);
1833 parseAlternateName(arg->getValue());
1837 addUndefined(arg->getValue());
1841 config->implib = arg->getValue();
1843 config->noimplib = args.hasArg(OPT_noimplib);
1854 std::string str = StringRef(arg->getValue()).lower();
1877 if (s.getAsInteger(10, config->ltoo) || config->ltoo > 3)
1880 config->ltoCgo.emplace();
1881 if (s.getAsInteger(10, *config->ltoCgo) || *config->ltoCgo > 3)
1886 config->thinLTOJobs = s.str();
1888 if (s.getAsInteger(10, config->ltoPartitions) ||
1889 config->ltoPartitions == 0)
1898 config->doGC = doGC;
1899 config->doICF = *icfLevel;
1900 config->tailMerge =
1901 (tailMerge == 1 && config->doICF != ICFLevel::None) || tailMerge == 2;
1902 config->ltoDebugPassManager = ltoDebugPM;
1906 config->saveTemps = true;
1910 StringRef s = arg->getValue();
1912 config->emit = EmitKind::Obj;
1914 config->emit = EmitKind::LLVM;
1916 config->emit = EmitKind::ASM;
1921 // Handle /kill-at
1923 config->killAt = true;
1927 config->ltoCache = arg->getValue();
1931 config->ltoCachePolicy = CHECK(
1932 parseCachePruningPolicy(arg->getValue()),
1933 Twine("/lldltocachepolicy: invalid cache policy: ") + arg->getValue());
1937 checkFailIfMismatch(arg->getValue(), nullptr);
1941 parseMerge(arg->getValue());
1952 if (isArm64EC(config->machine))
1955 if (config->mingw) {
1963 parseSection(arg->getValue());
1967 parseNumbers(arg->getValue(), &config->align);
1968 if (!isPowerOf2_64(config->align))
1969 error("/align: not a power of two: " + StringRef(arg->getValue()));
1976 parseAligncomm(arg->getValue());
1980 config->manifestDependencies.insert(arg->getValue());
1984 if (arg->getOption().getID() == OPT_manifest)
1985 config->manifest = Configuration::SideBySide;
1987 parseManifest(arg->getValue());
1992 parseManifestUAC(arg->getValue());
1996 config->manifestFile = arg->getValue();
2000 config->manifestInput.push_back(arg->getValue());
2002 if (!config->manifestInput.empty() &&
2003 config->manifest != Configuration::Embed) {
2008 config->dwoDir = args.getLastArgValue(OPT_dwodir);
2010 config->thinLTOEmitImportsFiles = args.hasArg(OPT_thinlto_emit_imports_files);
2011 config->thinLTOIndexOnly = args.hasArg(OPT_thinlto_index_only) ||
2013 config->thinLTOIndexOnlyArg =
2015 std::tie(config->thinLTOPrefixReplaceOld, config->thinLTOPrefixReplaceNew,
2016 config->thinLTOPrefixReplaceNativeObject) =
2018 config->thinLTOObjectSuffixReplace =
2020 config->ltoObjPath = args.getLastArgValue(OPT_lto_obj_path);
2021 config->ltoCSProfileGenerate = args.hasArg(OPT_lto_cs_profile_generate);
2022 config->ltoCSProfileFile = args.getLastArgValue(OPT_lto_cs_profile_file);
2023 config->ltoSampleProfileName = args.getLastArgValue(OPT_lto_sample_profile);
2025 config->ltoPGOWarnMismatch = args.hasFlag(OPT_lto_pgo_warn_mismatch,
2027 config->allowBind = args.hasFlag(OPT_allowbind, OPT_allowbind_no, true);
2028 config->allowIsolation =
2030 config->incremental =
2032 !config->doGC && config->doICF == ICFLevel::None &&
2034 config->integrityCheck =
2036 config->cetCompat = args.hasFlag(OPT_cetcompat, OPT_cetcompat_no, false);
2037 config->nxCompat = args.hasFlag(OPT_nxcompat, OPT_nxcompat_no, true);
2039 parseSwaprun(arg->getValue());
2040 config->terminalServerAware =
2041 !config->dll && args.hasFlag(OPT_tsaware, OPT_tsaware_no, true);
2042 config->autoImport =
2043 args.hasFlag(OPT_auto_import, OPT_auto_import_no, config->mingw);
2044 config->pseudoRelocs = args.hasFlag(
2045 OPT_runtime_pseudo_reloc, OPT_runtime_pseudo_reloc_no, config->mingw);
2046 config->callGraphProfileSort = args.hasFlag(
2048 config->stdcallFixup =
2049 args.hasFlag(OPT_stdcall_fixup, OPT_stdcall_fixup_no, config->mingw);
2050 config->warnStdcallFixup = !args.hasArg(OPT_stdcall_fixup);
2051 config->allowDuplicateWeak =
2053 OPT_lld_allow_duplicate_weak_no, config->mingw);
2058 if (config->incremental && args.hasArg(OPT_profile)) {
2060 config->incremental = false;
2063 if (config->incremental && args.hasArg(OPT_order)) {
2065 config->incremental = false;
2068 if (config->incremental && config->doGC) {
2071 config->incremental = false;
2074 if (config->incremental && config->doICF != ICFLevel::None) {
2077 config->incremental = false;
2085 if (std::optional<StringRef> path = findFile(arg->getValue()))
2093 auto isWholeArchive = [&](StringRef path) -> bool {
2108 switch (arg->getOption().getID()) {
2111 error("stray " + arg->getSpelling());
2116 error("nested " + arg->getSpelling());
2120 if (std::optional<StringRef> path = findFileIfNew(arg->getValue()))
2124 if (std::optional<StringRef> path = findFileIfNew(arg->getValue()))
2141 if (config->machine == IMAGE_FILE_MACHINE_UNKNOWN) {
2143 config->machine = AMD64;
2146 config->wordsize = config->is64() ? 8 : 4;
2148 if (config->printSearchPaths) {
2165 if (std::optional<StringRef> path = findLibIfNew(arg->getValue()))
2173 config->writeCheckSum = true;
2176 if (config->machine == I386) {
2177 config->safeSEH = args.hasFlag(OPT_safeseh, OPT_safeseh_no, !config->mingw);
2178 config->noSEH = args.hasArg(OPT_noseh);
2192 tar->append("response.txt",
2198 config->largeAddressAware = args.hasFlag(
2199 OPT_largeaddressaware, OPT_largeaddressaware_no, config->is64());
2202 config->highEntropyVA =
2203 config->is64() &&
2206 if (!config->dynamicBase &&
2207 (config->machine == ARMNT || isAnyArm64(config->machine)))
2209 machineToStr(config->machine));
2215 Export e = parseExport(arg->getValue());
2216 if (config->machine == I386) {
2222 config->exports.push_back(e);
2228 // parseModuleDefs mutates Config object.
2229 parseModuleDefs(arg->getValue());
2235 if (!config->noimplib)
2240 // Windows specific -- if no /subsystem is given, we need to infer
2243 if (config->subsystem == IMAGE_SUBSYSTEM_UNKNOWN) {
2245 config->subsystem = inferSubsystem();
2246 if (config->subsystem == IMAGE_SUBSYSTEM_UNKNOWN)
2250 // Handle /entry and /dll
2254 if (!arg->getValue()[0])
2256 config->entry = addUndefined(mangle(arg->getValue()));
2257 } else if (!config->entry && !config->noEntry) {
2259 StringRef s = (config->machine == I386) ? "__DllMainCRTStartup@12"
2261 config->entry = addUndefined(s);
2262 } else if (config->driverWdm) {
2264 config->entry = addUndefined(mangle("_NtProcessStartup"));
2266 // Windows specific -- If entry point name is not given, we need to
2267 // infer that from user-defined entry name.
2271 config->entry = addUndefined(s);
2281 config->delayLoads.insert(StringRef(arg->getValue()).lower());
2282 if (config->machine == I386) {
2283 config->delayLoadHelper = addUndefined("___delayLoadHelper2@8");
2285 config->delayLoadHelper = addUndefined("__delayLoadHelper2");
2291 if (config->outputFile.empty()) {
2292 config->outputFile = getOutputPath(
2293 (*args.filtered(OPT_INPUT, OPT_wholearchive_file).begin())->getValue(),
2294 config->dll, config->driver);
2298 if (auto e = tryCreateFile(config->outputFile)) {
2299 error("cannot open output file " + config->outputFile + ": " + e.message());
2303 config->lldmapFile = getMapFile(args, OPT_lldmap, OPT_lldmap_file);
2304 config->mapFile = getMapFile(args, OPT_map, OPT_map_file);
2306 if (config->mapFile != "" && args.hasArg(OPT_map_info)) {
2308 std::string s = StringRef(arg->getValue()).lower();
2310 config->mapInfo = true;
2316 if (config->lldmapFile != "" && config->lldmapFile == config->mapFile) {
2317 warn("/lldmap and /map have the same output file '" + config->mapFile +
2319 config->lldmapFile.clear();
2325 config->buildIDHash = BuildIDHash::Binary;
2329 if (config->pdbPath.empty()) {
2330 config->pdbPath = config->outputFile;
2331 sys::path::replace_extension(config->pdbPath, ".pdb");
2336 if (config->pdbAltPath.empty()) {
2337 config->pdbAltPath = config->pdbPath;
2342 sys::fs::make_absolute(config->pdbAltPath);
2343 sys::path::remove_dots(config->pdbAltPath);
2348 config->buildIDHash = BuildIDHash::PDB;
2352 if (config->imageBase == uint64_t(-1))
2353 config->imageBase = getDefaultImageBase();
2356 if (config->machine == I386) {
2374 if (isArm64EC(config->machine)) {
2381 if (config->pseudoRelocs) {
2385 if (config->mingw) {
2389 if (config->debug || config->buildIDHash != BuildIDHash::None)
2399 // Windows specific -- if entry point is not found,
2401 if (config->entry)
2402 mangleMaybe(config->entry);
2404 // Windows specific -- Make sure we resolve all dllexported symbols.
2405 for (Export &e : config->exports) {
2415 for (auto pair : config->alternateNames) {
2422 if (!u->weakAlias)
2423 u->weakAlias = ctx.symtab.addUndefined(to);
2433 ctx.bitcodeFileInstances.front()->obj->getTargetTriple());
2438 // Windows specific -- if __load_config_used can be resolved, resolve it.
2445 if (isa_and_nonnull<LazyArchive>(ctx.symtab.find(arg->getValue())))
2446 addUndefined(arg->getValue());
2451 // Create wrapped symbols for -wrap option.
2458 if (config->autoImport || config->stdcallFixup) {
2475 // a DLL without import library, this also just needs running once.
2484 // If we are going to do codegen for link-time optimization, check for
2487 if (!ctx.bitcodeFileInstances.empty() && !config->forceUnresolved)
2492 config->hadExplicitExports = !config->exports.empty();
2493 if (config->mingw) {
2500 // link those files (unless -thinlto-index-only was given, in which case we
2506 config->gcroot.push_back(d);
2508 // If -thinlto-index-only is given, we should create only "index
2512 if (config->emit != EmitKind::Obj || config->thinLTOIndexOnly)
2519 // Apply symbol renames for -wrap.
2528 if (config->mingw) {
2538 if (isCrtend(file->getName())) {
2546 // Windows specific -- when we are creating a .dll file, we also
2548 // -implib option is given explicitly, for compatibility with GNU ld.
2549 if (!config->exports.empty() || config->dll) {
2552 if (!config->noimplib && (!config->mingw || !config->implib.empty()))
2557 // Handle /output-def (MinGW specific).
2559 writeDefFile(arg->getValue(), config->exports);
2562 for (auto pair : config->alignComm) {
2578 CommonChunk *c = dc->getChunk();
2579 c->setAlignment(std::max(c->getAlignment(), alignment));
2582 // Windows specific -- Create an embedded or side-by-side manifest.
2585 if (config->manifest == Configuration::Embed)
2587 else if (config->manifest == Configuration::SideBySide ||
2588 (config->manifest == Configuration::Default &&
2589 !config->manifestDependencies.empty()))
2597 error("/order and /call-graph-order-file may not be used together");
2598 parseOrderFile(arg->getValue());
2599 config->callGraphProfileSort = false;
2602 // Handle /call-graph-ordering-file and /call-graph-profile-sort (default on).
2603 if (config->callGraphProfileSort) {
2606 parseCallGraphFile(arg->getValue());
2611 // Handle /print-symbol-order.
2613 config->printSymbolOrder = arg->getValue();
2618 if (config->doGC) {
2619 if (config->mingw) {
2629 if (d && !d->isGCRoot) {
2630 d->isGCRoot = true;
2631 config->gcroot.push_back(d);
2643 if (config->doICF != ICFLevel::None) {
2653 if (config->showTiming)
2656 if (config->timeTraceEnabled) {
2661 args.getLastArgValue(OPT_time_trace_eq).str(), config->outputFile));