@@ -268,6 +268,13 @@ void visualstudio::Linker::ConstructJob(Compilation &C, const JobAction &JA,
268268 }
269269 }
270270
271+ #ifdef ENABLE_CLASSIC_FLANG
272+ if (C.getDriver ().IsFlangMode ()) {
273+ CmdArgs.push_back (Args.MakeArgString (std::string (" -libpath:" ) +
274+ TC.getDriver ().Dir + " /../lib" ));
275+ }
276+ #endif
277+
271278 // Add compiler-rt lib in case if it was explicitly
272279 // specified as an argument for --rtlib option.
273280 if (!Args.hasArg (options::OPT_nostdlib)) {
@@ -513,6 +520,74 @@ void MSVCToolChain::AddHIPRuntimeLibArgs(const ArgList &Args,
513520 " amdhip64.lib" });
514521}
515522
523+ #ifdef ENABLE_CLASSIC_FLANG
524+ void MSVCToolChain::AddFortranStdlibLibArgs (const ArgList &Args,
525+ ArgStringList &CmdArgs) const {
526+ bool staticFlangLibs = false ;
527+ bool useOpenMP = false ;
528+
529+ if (Args.hasArg (options::OPT_staticFlangLibs)) {
530+ for (auto *A: Args.filtered (options::OPT_staticFlangLibs)) {
531+ A->claim ();
532+ staticFlangLibs = true ;
533+ }
534+ }
535+
536+ Arg *A = Args.getLastArg (options::OPT_mp, options::OPT_nomp,
537+ options::OPT_fopenmp, options::OPT_fno_openmp);
538+ if (A &&
539+ (A->getOption ().matches (options::OPT_mp) ||
540+ A->getOption ().matches (options::OPT_fopenmp))) {
541+ useOpenMP = true ;
542+ }
543+
544+ if (needFortranMain (getDriver (), Args)) {
545+ // flangmain is always static
546+ CmdArgs.push_back (" -linker" );
547+ CmdArgs.push_back (" /subsystem:console" );
548+ CmdArgs.push_back (" -linker" );
549+ CmdArgs.push_back (" /defaultlib:flangmain.lib" );
550+ }
551+
552+ if (staticFlangLibs) {
553+ CmdArgs.push_back (" -linker" );
554+ CmdArgs.push_back (" /defaultlib:libflang.lib" );
555+ CmdArgs.push_back (" -linker" );
556+ CmdArgs.push_back (" /defaultlib:libflangrti.lib" );
557+ CmdArgs.push_back (" -linker" );
558+ CmdArgs.push_back (" /defaultlib:libpgmath.lib" );
559+ } else {
560+ CmdArgs.push_back (" -linker" );
561+ CmdArgs.push_back (" /defaultlib:flang.lib" );
562+ CmdArgs.push_back (" -linker" );
563+ CmdArgs.push_back (" /defaultlib:flangrti.lib" );
564+ CmdArgs.push_back (" -linker" );
565+ CmdArgs.push_back (" /defaultlib:pgmath.lib" );
566+ }
567+ if (useOpenMP) {
568+ CmdArgs.push_back (" -linker" );
569+ CmdArgs.push_back (" /nodefaultlib:vcomp.lib" );
570+ CmdArgs.push_back (" -linker" );
571+ CmdArgs.push_back (" /nodefaultlib:vcompd.lib" );
572+ CmdArgs.push_back (" -linker" );
573+ CmdArgs.push_back (" /defaultlib:libomp.lib" );
574+ }
575+
576+ // Allways link Fortran executables with Pthreads
577+ // CmdArgs.push_back("-lpthread");
578+
579+ // These options are added clang-cl in Clang.cpp for C/C++
580+ // In clang-cl.exe -MD and -MT control these options, but in
581+ // flang.exe like clang.exe these are different options for
582+ // dependency tracking. Let's assume that if somebody needs
583+ // static flang libs, they don't need static C runtime libs.
584+ // FIXME: Use LLVM_USE_CRT_<CMAKE_BUILD_TYPE> variable
585+ // to use libcmt.lib or msvcrt.lib
586+ CmdArgs.push_back (" -linker" );
587+ CmdArgs.push_back (" /defaultlib:libcmt.lib" );
588+ }
589+ #endif
590+
516591void MSVCToolChain::printVerboseInfo (raw_ostream &OS) const {
517592 CudaInstallation->print (OS);
518593 RocmInstallation->print (OS);
0 commit comments