Skip to content

[Flang] Search flang_rt in clang_rt path #151954

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 17 additions & 8 deletions clang/lib/Driver/ToolChain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -855,17 +855,26 @@ void ToolChain::addFortranRuntimeLibs(const ArgList &Args,

void ToolChain::addFortranRuntimeLibraryPath(const llvm::opt::ArgList &Args,
ArgStringList &CmdArgs) const {
// Default to the <driver-path>/../lib directory. This works fine on the
// platforms that we have tested so far. We will probably have to re-fine
// this in the future. In particular, on some platforms, we may need to use
// lib64 instead of lib.
auto AddLibrarySearchPath = [&](const Twine &Path) {
if (getTriple().isKnownWindowsMSVCEnvironment())
CmdArgs.push_back(Args.MakeArgString("-libpath:" + Path));
else
CmdArgs.push_back(Args.MakeArgString("-L" + Path));
};

// Search for flang_rt.* at the same ___location as clang_rt.* with
// LLVM_ENABLE_PER_TARGET_RUNTIME_DIR=0. On most platforms, flang_rt is
// located at the path returned by getRuntimePath() which is already added to
// the library search path. This exception is for Apple-Darwin.
AddLibrarySearchPath(getCompilerRTPath());

// Fall back to the non-resource directory <driver-path>/../lib. We will
// probably have to re-fine this in the future. In particular, on some
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit

Suggested change
// probably have to re-fine this in the future. In particular, on some
// probably have to refine this in the future. In particular, on some

// platforms, we may need to use lib64 instead of lib.
SmallString<256> DefaultLibPath =
llvm::sys::path::parent_path(getDriver().Dir);
llvm::sys::path::append(DefaultLibPath, "lib");
if (getTriple().isKnownWindowsMSVCEnvironment())
CmdArgs.push_back(Args.MakeArgString("-libpath:" + DefaultLibPath));
else
CmdArgs.push_back(Args.MakeArgString("-L" + DefaultLibPath));
AddLibrarySearchPath(DefaultLibPath);
}

void ToolChain::addFlangRTLibPath(const ArgList &Args,
Expand Down