@@ -1581,18 +1581,39 @@ toolchains::Windows::constructInvocation(const LinkJobAction &job,
15811581 Arguments.push_back (context.Args .MakeArgString (Target));
15821582 }
15831583
1584+
15841585 SmallString<128 > SharedRuntimeLibPath;
15851586 getRuntimeLibraryPath (SharedRuntimeLibPath, context.Args , *this );
1586-
1587- // Add the runtime library link path, which is platform-specific and found
1588- // relative to the compiler.
1587+
1588+ // Link the standard library.
15891589 Arguments.push_back (" -L" );
1590- Arguments.push_back (context.Args .MakeArgString (SharedRuntimeLibPath + " /"
1590+ if (context.Args .hasFlag (options::OPT_static_stdlib,
1591+ options::OPT_no_static_stdlib,
1592+ false )) {
1593+ SmallString<128 > StaticRuntimeLibPath;
1594+ getRuntimeStaticLibraryPath (StaticRuntimeLibPath, context.Args , *this );
1595+
1596+ // Since Windows has separate libraries per architecture, link against the
1597+ // architecture specific version of the static library.
1598+ Arguments.push_back (context.Args .MakeArgString (StaticRuntimeLibPath + " /"
1599+ + getTriple ().getArchName ()));
1600+
1601+ Arguments.push_back (" -Xlinker" );
1602+ Arguments.push_back (" /NODEFAULTLIB:libcmt" );
1603+ } else {
1604+ Arguments.push_back (context.Args .MakeArgString (SharedRuntimeLibPath + " /"
15911605 + getTriple ().getArchName ()));
1606+ }
15921607
1608+ SmallString<128 > swiftrtPath = SharedRuntimeLibPath;
1609+ llvm::sys::path::append (swiftrtPath,
1610+ swift::getMajorArchitectureName (getTriple ()));
1611+ llvm::sys::path::append (swiftrtPath, " swiftrt.o" );
1612+ Arguments.push_back (context.Args .MakeArgString (swiftrtPath));
1613+
15931614 addPrimaryInputsOfType (Arguments, context.Inputs , types::TY_Object);
15941615 addInputsOfType (Arguments, context.InputActions , types::TY_Object);
1595-
1616+
15961617 for (const Arg *arg : context.Args .filtered (options::OPT_F,
15971618 options::OPT_Fsystem)) {
15981619 if (arg->getOption ().matches (options::OPT_Fsystem))
0 commit comments