Skip to content

Commit ddd3e9a

Browse files
author
git apple-llvm automerger
committed
Merge commit '9ec748cfb155' from llvm.org/release/21.x into stable/21.x
2 parents 63f9d2e + 9ec748c commit ddd3e9a

File tree

1 file changed

+21
-8
lines changed

1 file changed

+21
-8
lines changed

clang/lib/Driver/ToolChain.cpp

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -839,17 +839,30 @@ void ToolChain::addFortranRuntimeLibs(const ArgList &Args,
839839

840840
void ToolChain::addFortranRuntimeLibraryPath(const llvm::opt::ArgList &Args,
841841
ArgStringList &CmdArgs) const {
842-
// Default to the <driver-path>/../lib directory. This works fine on the
843-
// platforms that we have tested so far. We will probably have to re-fine
844-
// this in the future. In particular, on some platforms, we may need to use
845-
// lib64 instead of lib.
842+
auto AddLibSearchPathIfExists = [&](const Twine &Path) {
843+
// Linker may emit warnings about non-existing directories
844+
if (!llvm::sys::fs::is_directory(Path))
845+
return;
846+
847+
if (getTriple().isKnownWindowsMSVCEnvironment())
848+
CmdArgs.push_back(Args.MakeArgString("-libpath:" + Path));
849+
else
850+
CmdArgs.push_back(Args.MakeArgString("-L" + Path));
851+
};
852+
853+
// Search for flang_rt.* at the same location as clang_rt.* with
854+
// LLVM_ENABLE_PER_TARGET_RUNTIME_DIR=0. On most platforms, flang_rt is
855+
// located at the path returned by getRuntimePath() which is already added to
856+
// the library search path. This exception is for Apple-Darwin.
857+
AddLibSearchPathIfExists(getCompilerRTPath());
858+
859+
// Fall back to the non-resource directory <driver-path>/../lib. We will
860+
// probably have to refine this in the future. In particular, on some
861+
// platforms, we may need to use lib64 instead of lib.
846862
SmallString<256> DefaultLibPath =
847863
llvm::sys::path::parent_path(getDriver().Dir);
848864
llvm::sys::path::append(DefaultLibPath, "lib");
849-
if (getTriple().isKnownWindowsMSVCEnvironment())
850-
CmdArgs.push_back(Args.MakeArgString("-libpath:" + DefaultLibPath));
851-
else
852-
CmdArgs.push_back(Args.MakeArgString("-L" + DefaultLibPath));
865+
AddLibSearchPathIfExists(DefaultLibPath);
853866
}
854867

855868
void ToolChain::addFlangRTLibPath(const ArgList &Args,

0 commit comments

Comments
 (0)