@@ -851,17 +851,30 @@ void ToolChain::addFortranRuntimeLibs(const ArgList &Args,
851851
852852void ToolChain::addFortranRuntimeLibraryPath (const llvm::opt::ArgList &Args,
853853 ArgStringList &CmdArgs) const {
854- // Default to the <driver-path>/../lib directory. This works fine on the
855- // platforms that we have tested so far. We will probably have to re-fine
856- // this in the future. In particular, on some platforms, we may need to use
857- // lib64 instead of lib.
854+ auto AddLibSearchPathIfExists = [&](const Twine &Path) {
855+ // Linker may emit warnings about non-existing directories
856+ if (!llvm::sys::fs::is_directory (Path))
857+ return ;
858+
859+ if (getTriple ().isKnownWindowsMSVCEnvironment ())
860+ CmdArgs.push_back (Args.MakeArgString (" -libpath:" + Path));
861+ else
862+ CmdArgs.push_back (Args.MakeArgString (" -L" + Path));
863+ };
864+
865+ // Search for flang_rt.* at the same location as clang_rt.* with
866+ // LLVM_ENABLE_PER_TARGET_RUNTIME_DIR=0. On most platforms, flang_rt is
867+ // located at the path returned by getRuntimePath() which is already added to
868+ // the library search path. This exception is for Apple-Darwin.
869+ AddLibSearchPathIfExists (getCompilerRTPath ());
870+
871+ // Fall back to the non-resource directory <driver-path>/../lib. We will
872+ // probably have to refine this in the future. In particular, on some
873+ // platforms, we may need to use lib64 instead of lib.
858874 SmallString<256 > DefaultLibPath =
859875 llvm::sys::path::parent_path (getDriver ().Dir );
860876 llvm::sys::path::append (DefaultLibPath, " lib" );
861- if (getTriple ().isKnownWindowsMSVCEnvironment ())
862- CmdArgs.push_back (Args.MakeArgString (" -libpath:" + DefaultLibPath));
863- else
864- CmdArgs.push_back (Args.MakeArgString (" -L" + DefaultLibPath));
877+ AddLibSearchPathIfExists (DefaultLibPath);
865878}
866879
867880void ToolChain::addFlangRTLibPath (const ArgList &Args,
0 commit comments