llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-clang-driver Author: Daniel Chen (DanielCChen) <details> <summary>Changes</summary> The PR is to generalize the re-use of the `compilerRT` code of adding the path of `libflang_rt.runtime.a (so)` from AIX and LoP only to all platforms via a new function `addFlangRTLibPath`. Also, PR #<!-- -->134320 exposed an issue in PR #<!-- -->131041 that the the overriding `addFortranRuntimeLibs` is missing the link to `libquadmath`. This PR also fixed that and restored the test case that PR #<!-- -->131041 broke. --- Full diff: https://github.com/llvm/llvm-project/pull/134362.diff 7 Files Affected: - (modified) clang/include/clang/Driver/ToolChain.h (+4) - (modified) clang/lib/Driver/ToolChain.cpp (+18-2) - (modified) clang/lib/Driver/ToolChains/AIX.cpp (-8) - (modified) clang/lib/Driver/ToolChains/AIX.h (-3) - (modified) clang/lib/Driver/ToolChains/PPCLinux.cpp (-16) - (modified) clang/lib/Driver/ToolChains/PPCLinux.h (-3) - (modified) flang/test/Driver/linker-flags.f90 (+1-1) ``````````diff diff --git a/clang/include/clang/Driver/ToolChain.h b/clang/include/clang/Driver/ToolChain.h index 076e4296c3090..d0059673d6a67 100644 --- a/clang/include/clang/Driver/ToolChain.h +++ b/clang/include/clang/Driver/ToolChain.h @@ -521,6 +521,10 @@ class ToolChain { addFortranRuntimeLibraryPath(const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs) const; + /// Add the path for libflang_rt.runtime.a + void addFlangRTLibPath(const llvm::opt::ArgList &Args, + llvm::opt::ArgStringList &CmdArgs) const; + const char *getCompilerRTArgString(const llvm::opt::ArgList &Args, StringRef Component, FileType Type = ToolChain::FT_Static, diff --git a/clang/lib/Driver/ToolChain.cpp b/clang/lib/Driver/ToolChain.cpp index 36d0ae34dec86..054618a44d7bc 100644 --- a/clang/lib/Driver/ToolChain.cpp +++ b/clang/lib/Driver/ToolChain.cpp @@ -816,8 +816,7 @@ void ToolChain::addFortranRuntimeLibs(const ArgList &Args, if (AsNeeded) addAsNeededOption(*this, Args, CmdArgs, /*as_needed=*/false); } - CmdArgs.push_back("-lflang_rt.runtime"); - addArchSpecificRPath(*this, Args, CmdArgs); + addFlangRTLibPath(Args, CmdArgs); // needs libexecinfo for backtrace functions if (getTriple().isOSFreeBSD() || getTriple().isOSNetBSD() || @@ -850,6 +849,23 @@ void ToolChain::addFortranRuntimeLibraryPath(const llvm::opt::ArgList &Args, CmdArgs.push_back(Args.MakeArgString("-L" + DefaultLibPath)); } +void ToolChain::addFlangRTLibPath(const ArgList &Args, + llvm::opt::ArgStringList &CmdArgs) const { + // Link static flang_rt.runtime.a or shared flang_rt.runtime.so + const char *Path; + if (getVFS().exists(Twine(Path = getCompilerRTArgString( + Args, "runtime", ToolChain::FT_Static, true)))) + CmdArgs.push_back(Path); + else if (getVFS().exists( + Twine(Path = getCompilerRTArgString( + Args, "runtime", ToolChain::FT_Shared, true)))) + CmdArgs.push_back(Path); + else { + CmdArgs.push_back("-lflang_rt.runtime"); + addArchSpecificRPath(*this, Args, CmdArgs); + } +} + // Android target triples contain a target version. If we don't have libraries // for the exact target version, we should fall back to the next newest version // or a versionless path, if any. diff --git a/clang/lib/Driver/ToolChains/AIX.cpp b/clang/lib/Driver/ToolChains/AIX.cpp index 26b9d4c772be6..5dc80bc5a3d25 100644 --- a/clang/lib/Driver/ToolChains/AIX.cpp +++ b/clang/lib/Driver/ToolChains/AIX.cpp @@ -608,14 +608,6 @@ void AIX::addProfileRTLibs(const llvm::opt::ArgList &Args, ToolChain::addProfileRTLibs(Args, CmdArgs); } -void AIX::addFortranRuntimeLibs(const ArgList &Args, - llvm::opt::ArgStringList &CmdArgs) const { - // Link flang_rt.runtime.a. On AIX, the static and shared library are all - // named .a - CmdArgs.push_back( - getCompilerRTArgString(Args, "runtime", ToolChain::FT_Static, true)); -} - ToolChain::CXXStdlibType AIX::GetDefaultCXXStdlibType() const { return ToolChain::CST_Libcxx; } diff --git a/clang/lib/Driver/ToolChains/AIX.h b/clang/lib/Driver/ToolChains/AIX.h index 17e8370cd1218..8f130f6b54547 100644 --- a/clang/lib/Driver/ToolChains/AIX.h +++ b/clang/lib/Driver/ToolChains/AIX.h @@ -87,9 +87,6 @@ class LLVM_LIBRARY_VISIBILITY AIX : public ToolChain { void addProfileRTLibs(const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs) const override; - void addFortranRuntimeLibs(const llvm::opt::ArgList &Args, - llvm::opt::ArgStringList &CmdArgs) const override; - CXXStdlibType GetDefaultCXXStdlibType() const override; RuntimeLibType GetDefaultRuntimeLibType() const override; diff --git a/clang/lib/Driver/ToolChains/PPCLinux.cpp b/clang/lib/Driver/ToolChains/PPCLinux.cpp index 575e88c6ab124..0ed0f91ad166c 100644 --- a/clang/lib/Driver/ToolChains/PPCLinux.cpp +++ b/clang/lib/Driver/ToolChains/PPCLinux.cpp @@ -12,7 +12,6 @@ #include "clang/Driver/Options.h" #include "llvm/Support/FileSystem.h" #include "llvm/Support/Path.h" -#include "llvm/Support/VirtualFileSystem.h" using namespace clang::driver; using namespace clang::driver::toolchains; @@ -102,18 +101,3 @@ bool PPCLinuxToolChain::SupportIEEEFloat128( return GlibcSupportsFloat128((Twine(D.DyldPrefix) + Linker).str()) && !(D.CCCIsCXX() && HasUnsupportedCXXLib); } - -void PPCLinuxToolChain::addFortranRuntimeLibs( - const ArgList &Args, llvm::opt::ArgStringList &CmdArgs) const { - // Link static flang_rt.runtime.a or shared flang_rt.runtime.so - const char *Path; - if (getVFS().exists(Twine(Path = getCompilerRTArgString( - Args, "runtime", ToolChain::FT_Static, true)))) - CmdArgs.push_back(Path); - else if (getVFS().exists( - Twine(Path = getCompilerRTArgString( - Args, "runtime", ToolChain::FT_Shared, true)))) - CmdArgs.push_back(Path); - else - CmdArgs.push_back("-lflang_rt.runtime"); -} diff --git a/clang/lib/Driver/ToolChains/PPCLinux.h b/clang/lib/Driver/ToolChains/PPCLinux.h index 910df3d16e6a5..63adaff6be9c2 100644 --- a/clang/lib/Driver/ToolChains/PPCLinux.h +++ b/clang/lib/Driver/ToolChains/PPCLinux.h @@ -24,9 +24,6 @@ class LLVM_LIBRARY_VISIBILITY PPCLinuxToolChain : public Linux { AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args) const override; - void addFortranRuntimeLibs(const llvm::opt::ArgList &Args, - llvm::opt::ArgStringList &CmdArgs) const override; - private: bool SupportIEEEFloat128(const Driver &D, const llvm::Triple &Triple, const llvm::opt::ArgList &Args) const; diff --git a/flang/test/Driver/linker-flags.f90 b/flang/test/Driver/linker-flags.f90 index 20104276d2e4a..4e62a8c32d360 100644 --- a/flang/test/Driver/linker-flags.f90 +++ b/flang/test/Driver/linker-flags.f90 @@ -2,7 +2,7 @@ ! invocation. These libraries are added on top of other standard runtime ! libraries that the Clang driver will include. -! RUN: %flang -### --target=ppc64le-linux-gnu %S/Inputs/hello.f90 2>&1 | FileCheck %s --check-prefixes=CHECK,UNIX,UNIX-F128NONE +! RUN: %flang -### --target=ppc64le-linux-gnu %S/Inputs/hello.f90 2>&1 | FileCheck %s --check-prefixes=CHECK,UNIX,UNIX-F128%f128-lib ! RUN: %flang -### --target=aarch64-apple-darwin %S/Inputs/hello.f90 2>&1 | FileCheck %s --check-prefixes=CHECK,DARWIN,DARWIN-F128%f128-lib ! RUN: %flang -### --target=sparc-sun-solaris2.11 %S/Inputs/hello.f90 2>&1 | FileCheck %s --check-prefixes=CHECK,UNIX,SOLARIS-F128%f128-lib ! RUN: %flang -### --target=x86_64-unknown-freebsd %S/Inputs/hello.f90 2>&1 | FileCheck %s --check-prefixes=CHECK,BSD,BSD-F128%f128-lib `````````` </details> https://github.com/llvm/llvm-project/pull/134362 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits