Skip to content

Commit 7db1cca

Browse files
committed
[driver] Generalize adding the path of libflang_rt.runtime.a.
1 parent c048073 commit 7db1cca

File tree

7 files changed

+23
-33
lines changed

7 files changed

+23
-33
lines changed

clang/include/clang/Driver/ToolChain.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,10 @@ class ToolChain {
521521
addFortranRuntimeLibraryPath(const llvm::opt::ArgList &Args,
522522
llvm::opt::ArgStringList &CmdArgs) const;
523523

524+
/// Add the path for libflang_rt.runtime.a
525+
void addFlangRTLibPath(const llvm::opt::ArgList &Args,
526+
llvm::opt::ArgStringList &CmdArgs) const;
527+
524528
const char *getCompilerRTArgString(const llvm::opt::ArgList &Args,
525529
StringRef Component,
526530
FileType Type = ToolChain::FT_Static,

clang/lib/Driver/ToolChain.cpp

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -816,8 +816,7 @@ void ToolChain::addFortranRuntimeLibs(const ArgList &Args,
816816
if (AsNeeded)
817817
addAsNeededOption(*this, Args, CmdArgs, /*as_needed=*/false);
818818
}
819-
CmdArgs.push_back("-lflang_rt.runtime");
820-
addArchSpecificRPath(*this, Args, CmdArgs);
819+
addFlangRTLibPath(Args, CmdArgs);
821820

822821
// needs libexecinfo for backtrace functions
823822
if (getTriple().isOSFreeBSD() || getTriple().isOSNetBSD() ||
@@ -850,6 +849,23 @@ void ToolChain::addFortranRuntimeLibraryPath(const llvm::opt::ArgList &Args,
850849
CmdArgs.push_back(Args.MakeArgString("-L" + DefaultLibPath));
851850
}
852851

852+
void ToolChain::addFlangRTLibPath(const ArgList &Args,
853+
llvm::opt::ArgStringList &CmdArgs) const {
854+
// Link static flang_rt.runtime.a or shared flang_rt.runtime.so
855+
const char *Path;
856+
if (getVFS().exists(Twine(Path = getCompilerRTArgString(
857+
Args, "runtime", ToolChain::FT_Static, true))))
858+
CmdArgs.push_back(Path);
859+
else if (getVFS().exists(
860+
Twine(Path = getCompilerRTArgString(
861+
Args, "runtime", ToolChain::FT_Shared, true))))
862+
CmdArgs.push_back(Path);
863+
else {
864+
CmdArgs.push_back("-lflang_rt.runtime");
865+
addArchSpecificRPath(*this, Args, CmdArgs);
866+
}
867+
}
868+
853869
// Android target triples contain a target version. If we don't have libraries
854870
// for the exact target version, we should fall back to the next newest version
855871
// or a versionless path, if any.

clang/lib/Driver/ToolChains/AIX.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -608,14 +608,6 @@ void AIX::addProfileRTLibs(const llvm::opt::ArgList &Args,
608608
ToolChain::addProfileRTLibs(Args, CmdArgs);
609609
}
610610

611-
void AIX::addFortranRuntimeLibs(const ArgList &Args,
612-
llvm::opt::ArgStringList &CmdArgs) const {
613-
// Link flang_rt.runtime.a. On AIX, the static and shared library are all
614-
// named .a
615-
CmdArgs.push_back(
616-
getCompilerRTArgString(Args, "runtime", ToolChain::FT_Static, true));
617-
}
618-
619611
ToolChain::CXXStdlibType AIX::GetDefaultCXXStdlibType() const {
620612
return ToolChain::CST_Libcxx;
621613
}

clang/lib/Driver/ToolChains/AIX.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,6 @@ class LLVM_LIBRARY_VISIBILITY AIX : public ToolChain {
8787
void addProfileRTLibs(const llvm::opt::ArgList &Args,
8888
llvm::opt::ArgStringList &CmdArgs) const override;
8989

90-
void addFortranRuntimeLibs(const llvm::opt::ArgList &Args,
91-
llvm::opt::ArgStringList &CmdArgs) const override;
92-
9390
CXXStdlibType GetDefaultCXXStdlibType() const override;
9491

9592
RuntimeLibType GetDefaultRuntimeLibType() const override;

clang/lib/Driver/ToolChains/PPCLinux.cpp

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
#include "clang/Driver/Options.h"
1313
#include "llvm/Support/FileSystem.h"
1414
#include "llvm/Support/Path.h"
15-
#include "llvm/Support/VirtualFileSystem.h"
1615

1716
using namespace clang::driver;
1817
using namespace clang::driver::toolchains;
@@ -102,18 +101,3 @@ bool PPCLinuxToolChain::SupportIEEEFloat128(
102101
return GlibcSupportsFloat128((Twine(D.DyldPrefix) + Linker).str()) &&
103102
!(D.CCCIsCXX() && HasUnsupportedCXXLib);
104103
}
105-
106-
void PPCLinuxToolChain::addFortranRuntimeLibs(
107-
const ArgList &Args, llvm::opt::ArgStringList &CmdArgs) const {
108-
// Link static flang_rt.runtime.a or shared flang_rt.runtime.so
109-
const char *Path;
110-
if (getVFS().exists(Twine(Path = getCompilerRTArgString(
111-
Args, "runtime", ToolChain::FT_Static, true))))
112-
CmdArgs.push_back(Path);
113-
else if (getVFS().exists(
114-
Twine(Path = getCompilerRTArgString(
115-
Args, "runtime", ToolChain::FT_Shared, true))))
116-
CmdArgs.push_back(Path);
117-
else
118-
CmdArgs.push_back("-lflang_rt.runtime");
119-
}

clang/lib/Driver/ToolChains/PPCLinux.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,6 @@ class LLVM_LIBRARY_VISIBILITY PPCLinuxToolChain : public Linux {
2424
AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,
2525
llvm::opt::ArgStringList &CC1Args) const override;
2626

27-
void addFortranRuntimeLibs(const llvm::opt::ArgList &Args,
28-
llvm::opt::ArgStringList &CmdArgs) const override;
29-
3027
private:
3128
bool SupportIEEEFloat128(const Driver &D, const llvm::Triple &Triple,
3229
const llvm::opt::ArgList &Args) const;

flang/test/Driver/linker-flags.f90

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
! invocation. These libraries are added on top of other standard runtime
33
! libraries that the Clang driver will include.
44

5-
! RUN: %flang -### --target=ppc64le-linux-gnu %S/Inputs/hello.f90 2>&1 | FileCheck %s --check-prefixes=CHECK,UNIX,UNIX-F128NONE
5+
! RUN: %flang -### --target=ppc64le-linux-gnu %S/Inputs/hello.f90 2>&1 | FileCheck %s --check-prefixes=CHECK,UNIX,UNIX-F128%f128-lib
66
! RUN: %flang -### --target=aarch64-apple-darwin %S/Inputs/hello.f90 2>&1 | FileCheck %s --check-prefixes=CHECK,DARWIN,DARWIN-F128%f128-lib
77
! RUN: %flang -### --target=sparc-sun-solaris2.11 %S/Inputs/hello.f90 2>&1 | FileCheck %s --check-prefixes=CHECK,UNIX,SOLARIS-F128%f128-lib
88
! RUN: %flang -### --target=x86_64-unknown-freebsd %S/Inputs/hello.f90 2>&1 | FileCheck %s --check-prefixes=CHECK,BSD,BSD-F128%f128-lib

0 commit comments

Comments
 (0)