https://github.com/DanielCChen updated https://github.com/llvm/llvm-project/pull/131041
>From c394e25b3af722d76338bf7ab02d87de2a23074b Mon Sep 17 00:00:00 2001 From: Daniel Chen <cdc...@ca.ibm.com> Date: Wed, 12 Mar 2025 18:23:14 -0400 Subject: [PATCH 01/11] [flang-rt] Pass the whole path of libflang_rt.runtime.a to linker on AIX. --- clang/lib/Driver/ToolChains/CommonArgs.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp b/clang/lib/Driver/ToolChains/CommonArgs.cpp index b43472a52038b..21f934cdba468 100644 --- a/clang/lib/Driver/ToolChains/CommonArgs.cpp +++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp @@ -1345,7 +1345,16 @@ void tools::addFortranRuntimeLibs(const ToolChain &TC, const ArgList &Args, if (AsNeeded) addAsNeededOption(TC, Args, CmdArgs, /*as_needed=*/false); } - CmdArgs.push_back("-lflang_rt.runtime"); + if (TC.getTriple().isOSAIX()) { + // On AIX, pass the whole path of flang_rt.runtime.a to be consistent + // with clang. + std::string CRTBasename = "libflang_rt.runtime.a"; + SmallString<128> Path(TC.getCompilerRTPath()); + llvm::sys::path::append(Path, CRTBasename); + if (TC.getVFS().exists(Path)) + CmdArgs.push_back(Args.MakeArgString(std::string(Path))); + } else + CmdArgs.push_back("-lflang_rt.runtime"); addArchSpecificRPath(TC, Args, CmdArgs); // needs libexecinfo for backtrace functions >From e2363ddb6df42e1c40153fb3263c179279c397cd Mon Sep 17 00:00:00 2001 From: Daniel Chen <cdc...@ca.ibm.com> Date: Sat, 15 Mar 2025 16:27:08 -0400 Subject: [PATCH 02/11] [flang-rt] Re-implement driver code of how flang-rt path is built. --- clang/include/clang/Driver/ToolChain.h | 23 ++++-- clang/lib/Driver/ToolChain.cpp | 80 ++++++++++++++++--- clang/lib/Driver/ToolChains/AIX.cpp | 27 ++++++- clang/lib/Driver/ToolChains/AIX.h | 7 ++ clang/lib/Driver/ToolChains/AVR.cpp | 3 +- clang/lib/Driver/ToolChains/AVR.h | 3 +- clang/lib/Driver/ToolChains/CommonArgs.cpp | 64 --------------- clang/lib/Driver/ToolChains/CommonArgs.h | 9 --- clang/lib/Driver/ToolChains/Darwin.cpp | 8 +- clang/lib/Driver/ToolChains/Darwin.h | 6 +- clang/lib/Driver/ToolChains/DragonFly.cpp | 4 +- clang/lib/Driver/ToolChains/FreeBSD.cpp | 4 +- clang/lib/Driver/ToolChains/Gnu.cpp | 4 +- clang/lib/Driver/ToolChains/Haiku.cpp | 4 +- clang/lib/Driver/ToolChains/MSVC.cpp | 4 +- clang/lib/Driver/ToolChains/MinGW.cpp | 4 +- clang/lib/Driver/ToolChains/MipsLinux.cpp | 3 +- clang/lib/Driver/ToolChains/MipsLinux.h | 3 +- clang/lib/Driver/ToolChains/NetBSD.cpp | 4 +- clang/lib/Driver/ToolChains/OHOS.cpp | 2 +- clang/lib/Driver/ToolChains/OHOS.h | 3 +- clang/lib/Driver/ToolChains/OpenBSD.cpp | 11 +-- clang/lib/Driver/ToolChains/OpenBSD.h | 3 +- clang/lib/Driver/ToolChains/PPCLinux.cpp | 35 ++++++++ clang/lib/Driver/ToolChains/PPCLinux.h | 7 ++ clang/lib/Driver/ToolChains/Solaris.cpp | 4 +- flang-rt/cmake/modules/GetToolchainDirs.cmake | 2 + 27 files changed, 206 insertions(+), 125 deletions(-) diff --git a/clang/include/clang/Driver/ToolChain.h b/clang/include/clang/Driver/ToolChain.h index 90004c64a694a..dc23bdf2ffd05 100644 --- a/clang/include/clang/Driver/ToolChain.h +++ b/clang/include/clang/Driver/ToolChain.h @@ -216,8 +216,8 @@ class ToolChain { virtual std::string buildCompilerRTBasename(const llvm::opt::ArgList &Args, StringRef Component, - FileType Type, - bool AddArch) const; + FileType Type, bool AddArch, + bool IsFortran = false) const; /// Find the target-specific subdirectory for the current target triple under /// \p BaseDir, doing fallback triple searches as necessary. @@ -509,11 +509,22 @@ class ToolChain { virtual std::string getCompilerRT(const llvm::opt::ArgList &Args, StringRef Component, - FileType Type = ToolChain::FT_Static) const; + FileType Type = ToolChain::FT_Static, + bool IsFortran = false) const; + + /// Adds Fortran runtime libraries to \p CmdArgs. + virtual void addFortranRuntimeLibs(const llvm::opt::ArgList &Args, + llvm::opt::ArgStringList &CmdArgs) const; + + /// Adds the path for the Fortran runtime libraries to \p CmdArgs. + virtual void + addFortranRuntimeLibraryPath(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) const; + const char *getCompilerRTArgString(const llvm::opt::ArgList &Args, + StringRef Component, + FileType Type = ToolChain::FT_Static, + bool IsFortran = false) const; std::string getCompilerRTBasename(const llvm::opt::ArgList &Args, StringRef Component, diff --git a/clang/lib/Driver/ToolChain.cpp b/clang/lib/Driver/ToolChain.cpp index 5f75d004eede0..029d8114d9282 100644 --- a/clang/lib/Driver/ToolChain.cpp +++ b/clang/lib/Driver/ToolChain.cpp @@ -733,8 +733,8 @@ std::string ToolChain::getCompilerRTBasename(const ArgList &Args, std::string ToolChain::buildCompilerRTBasename(const llvm::opt::ArgList &Args, StringRef Component, - FileType Type, - bool AddArch) const { + FileType Type, bool AddArch, + bool IsFortran) const { const llvm::Triple &TT = getTriple(); bool IsITANMSVCWindows = TT.isWindowsMSVCEnvironment() || TT.isWindowsItaniumEnvironment(); @@ -762,14 +762,16 @@ std::string ToolChain::buildCompilerRTBasename(const llvm::opt::ArgList &Args, const char *Env = TT.isAndroid() ? "-android" : ""; ArchAndEnv = ("-" + Arch + Env).str(); } - return (Prefix + Twine("clang_rt.") + Component + ArchAndEnv + Suffix).str(); + + std::string LibName = IsFortran ? "flang_rt." : "clang_rt."; + return (Prefix + Twine(LibName) + Component + ArchAndEnv + Suffix).str(); } std::string ToolChain::getCompilerRT(const ArgList &Args, StringRef Component, - FileType Type) const { + FileType Type, bool IsFortran) const { // Check for runtime files in the new layout without the architecture first. - std::string CRTBasename = - buildCompilerRTBasename(Args, Component, Type, /*AddArch=*/false); + std::string CRTBasename = buildCompilerRTBasename( + Args, Component, Type, /*AddArch=*/false, IsFortran); SmallString<128> Path; for (const auto &LibPath : getLibraryPaths()) { SmallString<128> P(LibPath); @@ -783,8 +785,8 @@ std::string ToolChain::getCompilerRT(const ArgList &Args, StringRef Component, Path.clear(); // Check the filename for the old layout if the new one does not exist. - CRTBasename = - buildCompilerRTBasename(Args, Component, Type, /*AddArch=*/true); + CRTBasename = buildCompilerRTBasename(Args, Component, Type, + /*AddArch=*/!IsFortran, IsFortran); SmallString<128> OldPath(getCompilerRTPath()); llvm::sys::path::append(OldPath, CRTBasename); if (Path.empty() || getVFS().exists(OldPath)) @@ -798,8 +800,66 @@ std::string ToolChain::getCompilerRT(const ArgList &Args, StringRef Component, const char *ToolChain::getCompilerRTArgString(const llvm::opt::ArgList &Args, StringRef Component, - FileType Type) const { - return Args.MakeArgString(getCompilerRT(Args, Component, Type)); + FileType Type, + bool isFortran) const { + return Args.MakeArgString(getCompilerRT(Args, Component, Type, isFortran)); +} + +/// Add Fortran runtime libs +void ToolChain::addFortranRuntimeLibs(const ArgList &Args, + llvm::opt::ArgStringList &CmdArgs) const { + // Link flang_rt.runtime + // These are handled earlier on Windows by telling the frontend driver to + // add the correct libraries to link against as dependents in the object + // file. + if (!getTriple().isKnownWindowsMSVCEnvironment()) { + StringRef F128LibName = getDriver().getFlangF128MathLibrary(); + F128LibName.consume_front_insensitive("lib"); + if (!F128LibName.empty()) { + bool AsNeeded = !getTriple().isOSAIX(); + CmdArgs.push_back("-lflang_rt.quadmath"); + if (AsNeeded) + addAsNeededOption(*this, Args, CmdArgs, /*as_needed=*/true); + CmdArgs.push_back(Args.MakeArgString("-l" + F128LibName)); + if (AsNeeded) + addAsNeededOption(*this, Args, CmdArgs, /*as_needed=*/false); + } + if (const char *res = getCompilerRTArgString( + Args, "runtime", ToolChain::FT_Static, getDriver().IsFlangMode())) + CmdArgs.push_back(res); + else + CmdArgs.push_back("-lflang_rt.runtime"); + addArchSpecificRPath(*this, Args, CmdArgs); + + // needs libexecinfo for backtrace functions + if (getTriple().isOSFreeBSD() || getTriple().isOSNetBSD() || + getTriple().isOSOpenBSD() || getTriple().isOSDragonFly()) + CmdArgs.push_back("-lexecinfo"); + } + + // libomp needs libatomic for atomic operations if using libgcc + if (Args.hasFlag(options::OPT_fopenmp, options::OPT_fopenmp_EQ, + options::OPT_fno_openmp, false)) { + Driver::OpenMPRuntimeKind OMPRuntime = getDriver().getOpenMPRuntime(Args); + ToolChain::RuntimeLibType RuntimeLib = GetRuntimeLibType(Args); + if (OMPRuntime == Driver::OMPRT_OMP && RuntimeLib == ToolChain::RLT_Libgcc) + CmdArgs.push_back("-latomic"); + } +} + +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. + 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)); } // Android target triples contain a target version. If we don't have libraries diff --git a/clang/lib/Driver/ToolChains/AIX.cpp b/clang/lib/Driver/ToolChains/AIX.cpp index 001f3a5178943..f2adcc0725c58 100644 --- a/clang/lib/Driver/ToolChains/AIX.cpp +++ b/clang/lib/Driver/ToolChains/AIX.cpp @@ -16,8 +16,11 @@ #include "llvm/Option/ArgList.h" #include "llvm/ProfileData/InstrProf.h" #include "llvm/Support/Path.h" +#include "llvm/Support/VirtualFileSystem.h" +#include <iostream> #include <set> +using namespace std; using AIX = clang::driver::toolchains::AIX; using namespace clang::driver; @@ -358,8 +361,8 @@ void aix::Linker::ConstructJob(Compilation &C, const JobAction &JA, if (D.IsFlangMode() && !Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs)) { - addFortranRuntimeLibraryPath(ToolChain, Args, CmdArgs); - addFortranRuntimeLibs(ToolChain, Args, CmdArgs); + ToolChain.addFortranRuntimeLibraryPath(Args, CmdArgs); + // ToolChain.addFortranRuntimeLibs(Args, CmdArgs); CmdArgs.push_back("-lm"); CmdArgs.push_back("-lpthread"); } @@ -608,6 +611,26 @@ void AIX::addProfileRTLibs(const llvm::opt::ArgList &Args, ToolChain::addProfileRTLibs(Args, CmdArgs); } +std::string AIX::getCompilerRT(const ArgList &Args, StringRef Component, + FileType Type, bool IsFortran) const { + // On AIX, build the filename for the layout as if + // LLVM_ENABLE_PER_TARGET_RUNTIME_DIR=OFF (e.g. lib/${os_dirname}) + std::string CRTBasename = + buildCompilerRTBasename(Args, Component, Type, + /*AddArch=*/!IsFortran, IsFortran); + SmallString<128> Path(getCompilerRTPath()); + llvm::sys::path::append(Path, CRTBasename); + return std::string(Path); +} + +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, getDriver().IsFlangMode())); +} + 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 8f130f6b54547..05435896e84b0 100644 --- a/clang/lib/Driver/ToolChains/AIX.h +++ b/clang/lib/Driver/ToolChains/AIX.h @@ -87,6 +87,13 @@ class LLVM_LIBRARY_VISIBILITY AIX : public ToolChain { void addProfileRTLibs(const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs) const override; + std::string getCompilerRT(const llvm::opt::ArgList &Args, StringRef Component, + FileType Type = ToolChain::FT_Static, + bool IsFortran = false) 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/AVR.cpp b/clang/lib/Driver/ToolChains/AVR.cpp index 08e906ac9e806..931be0c95bdcb 100644 --- a/clang/lib/Driver/ToolChains/AVR.cpp +++ b/clang/lib/Driver/ToolChains/AVR.cpp @@ -426,7 +426,8 @@ Tool *AVRToolChain::buildLinker() const { std::string AVRToolChain::getCompilerRT(const llvm::opt::ArgList &Args, StringRef Component, - FileType Type = ToolChain::FT_Static) const { + FileType Type = ToolChain::FT_Static, + bool IsFortran) const { assert(Type == ToolChain::FT_Static && "AVR only supports static libraries"); // Since AVR can never be a host environment, its compiler-rt library files // should always have ".a" suffix, even on windows. diff --git a/clang/lib/Driver/ToolChains/AVR.h b/clang/lib/Driver/ToolChains/AVR.h index 247188b7eaad7..f4d74eb944257 100644 --- a/clang/lib/Driver/ToolChains/AVR.h +++ b/clang/lib/Driver/ToolChains/AVR.h @@ -34,7 +34,8 @@ class LLVM_LIBRARY_VISIBILITY AVRToolChain : public Generic_ELF { std::optional<std::string> findAVRLibcInstallation() const; StringRef getGCCInstallPath() const { return GCCInstallPath; } std::string getCompilerRT(const llvm::opt::ArgList &Args, StringRef Component, - FileType Type) const override; + FileType Type, + bool IsFortran = false) const override; bool HasNativeLLVMSupport() const override { return true; } diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp b/clang/lib/Driver/ToolChains/CommonArgs.cpp index 21f934cdba468..9b4817bd2b97a 100644 --- a/clang/lib/Driver/ToolChains/CommonArgs.cpp +++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp @@ -1326,70 +1326,6 @@ void tools::addOpenMPHostOffloadingArgs(const Compilation &C, Args.MakeArgString(Twine(Targets) + llvm::join(Triples, ","))); } -/// Add Fortran runtime libs -void tools::addFortranRuntimeLibs(const ToolChain &TC, const ArgList &Args, - llvm::opt::ArgStringList &CmdArgs) { - // Link flang_rt.runtime - // These are handled earlier on Windows by telling the frontend driver to - // add the correct libraries to link against as dependents in the object - // file. - if (!TC.getTriple().isKnownWindowsMSVCEnvironment()) { - StringRef F128LibName = TC.getDriver().getFlangF128MathLibrary(); - F128LibName.consume_front_insensitive("lib"); - if (!F128LibName.empty()) { - bool AsNeeded = !TC.getTriple().isOSAIX(); - CmdArgs.push_back("-lflang_rt.quadmath"); - if (AsNeeded) - addAsNeededOption(TC, Args, CmdArgs, /*as_needed=*/true); - CmdArgs.push_back(Args.MakeArgString("-l" + F128LibName)); - if (AsNeeded) - addAsNeededOption(TC, Args, CmdArgs, /*as_needed=*/false); - } - if (TC.getTriple().isOSAIX()) { - // On AIX, pass the whole path of flang_rt.runtime.a to be consistent - // with clang. - std::string CRTBasename = "libflang_rt.runtime.a"; - SmallString<128> Path(TC.getCompilerRTPath()); - llvm::sys::path::append(Path, CRTBasename); - if (TC.getVFS().exists(Path)) - CmdArgs.push_back(Args.MakeArgString(std::string(Path))); - } else - CmdArgs.push_back("-lflang_rt.runtime"); - addArchSpecificRPath(TC, Args, CmdArgs); - - // needs libexecinfo for backtrace functions - if (TC.getTriple().isOSFreeBSD() || TC.getTriple().isOSNetBSD() || - TC.getTriple().isOSOpenBSD() || TC.getTriple().isOSDragonFly()) - CmdArgs.push_back("-lexecinfo"); - } - - // libomp needs libatomic for atomic operations if using libgcc - if (Args.hasFlag(options::OPT_fopenmp, options::OPT_fopenmp_EQ, - options::OPT_fno_openmp, false)) { - Driver::OpenMPRuntimeKind OMPRuntime = - TC.getDriver().getOpenMPRuntime(Args); - ToolChain::RuntimeLibType RuntimeLib = TC.GetRuntimeLibType(Args); - if (OMPRuntime == Driver::OMPRT_OMP && RuntimeLib == ToolChain::RLT_Libgcc) - CmdArgs.push_back("-latomic"); - } -} - -void tools::addFortranRuntimeLibraryPath(const ToolChain &TC, - const llvm::opt::ArgList &Args, - ArgStringList &CmdArgs) { - // 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. - SmallString<256> DefaultLibPath = - llvm::sys::path::parent_path(TC.getDriver().Dir); - llvm::sys::path::append(DefaultLibPath, "lib"); - if (TC.getTriple().isKnownWindowsMSVCEnvironment()) - CmdArgs.push_back(Args.MakeArgString("-libpath:" + DefaultLibPath)); - else - CmdArgs.push_back(Args.MakeArgString("-L" + DefaultLibPath)); -} - static void addSanitizerRuntime(const ToolChain &TC, const ArgList &Args, ArgStringList &CmdArgs, StringRef Sanitizer, bool IsShared, bool IsWhole) { diff --git a/clang/lib/Driver/ToolChains/CommonArgs.h b/clang/lib/Driver/ToolChains/CommonArgs.h index 783a1f834b33d..b58dcd4ec6ae7 100644 --- a/clang/lib/Driver/ToolChains/CommonArgs.h +++ b/clang/lib/Driver/ToolChains/CommonArgs.h @@ -121,15 +121,6 @@ void addOpenMPHostOffloadingArgs(const Compilation &C, const JobAction &JA, const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs); -/// Adds Fortran runtime libraries to \p CmdArgs. -void addFortranRuntimeLibs(const ToolChain &TC, const llvm::opt::ArgList &Args, - llvm::opt::ArgStringList &CmdArgs); - -/// Adds the path for the Fortran runtime libraries to \p CmdArgs. -void addFortranRuntimeLibraryPath(const ToolChain &TC, - const llvm::opt::ArgList &Args, - llvm::opt::ArgStringList &CmdArgs); - void addHIPRuntimeLibArgs(const ToolChain &TC, Compilation &C, const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs); diff --git a/clang/lib/Driver/ToolChains/Darwin.cpp b/clang/lib/Driver/ToolChains/Darwin.cpp index e67997314da36..7dffc0f28623e 100644 --- a/clang/lib/Driver/ToolChains/Darwin.cpp +++ b/clang/lib/Driver/ToolChains/Darwin.cpp @@ -706,8 +706,8 @@ void darwin::Linker::ConstructJob(Compilation &C, const JobAction &JA, // to generate executables. if (getToolChain().getDriver().IsFlangMode() && !Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs)) { - addFortranRuntimeLibraryPath(getToolChain(), Args, CmdArgs); - addFortranRuntimeLibs(getToolChain(), Args, CmdArgs); + getToolChain().addFortranRuntimeLibraryPath(Args, CmdArgs); + getToolChain().addFortranRuntimeLibs(Args, CmdArgs); } if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs)) @@ -1341,7 +1341,7 @@ void MachO::AddLinkRuntimeLib(const ArgList &Args, ArgStringList &CmdArgs, } std::string MachO::getCompilerRT(const ArgList &, StringRef Component, - FileType Type) const { + FileType Type, bool IsFortran) const { assert(Type != ToolChain::FT_Object && "it doesn't make sense to ask for the compiler-rt library name as an " "object file"); @@ -1360,7 +1360,7 @@ std::string MachO::getCompilerRT(const ArgList &, StringRef Component, } std::string Darwin::getCompilerRT(const ArgList &, StringRef Component, - FileType Type) const { + FileType Type, bool IsFortran) const { assert(Type != ToolChain::FT_Object && "it doesn't make sense to ask for the compiler-rt library name as an " "object file"); diff --git a/clang/lib/Driver/ToolChains/Darwin.h b/clang/lib/Driver/ToolChains/Darwin.h index c44780c577f4f..b3023eaa81318 100644 --- a/clang/lib/Driver/ToolChains/Darwin.h +++ b/clang/lib/Driver/ToolChains/Darwin.h @@ -229,7 +229,8 @@ class LLVM_LIBRARY_VISIBILITY MachO : public ToolChain { // <resourcedir>/lib/darwin/macho_embedded/<...>(.dylib|.a). std::string getCompilerRT(const llvm::opt::ArgList &Args, StringRef Component, - FileType Type = ToolChain::FT_Static) const override; + FileType Type = ToolChain::FT_Static, + bool IsFortran = false) const override; /// } /// @name ToolChain Implementation @@ -409,7 +410,8 @@ class LLVM_LIBRARY_VISIBILITY Darwin : public AppleMachO { // Those are under <resourcedir>/lib/darwin/<...>(.dylib|.a). std::string getCompilerRT(const llvm::opt::ArgList &Args, StringRef Component, - FileType Type = ToolChain::FT_Static) const override; + FileType Type = ToolChain::FT_Static, + bool IsFortran = false) const override; protected: /// } diff --git a/clang/lib/Driver/ToolChains/DragonFly.cpp b/clang/lib/Driver/ToolChains/DragonFly.cpp index 1e0a4159bf4ad..38a29ae49e8d9 100644 --- a/clang/lib/Driver/ToolChains/DragonFly.cpp +++ b/clang/lib/Driver/ToolChains/DragonFly.cpp @@ -153,8 +153,8 @@ void dragonfly::Linker::ConstructJob(Compilation &C, const JobAction &JA, // AddRunTimeLibs). if (D.IsFlangMode() && !Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs)) { - addFortranRuntimeLibraryPath(ToolChain, Args, CmdArgs); - addFortranRuntimeLibs(ToolChain, Args, CmdArgs); + ToolChain.addFortranRuntimeLibraryPath(Args, CmdArgs); + ToolChain.addFortranRuntimeLibs(Args, CmdArgs); CmdArgs.push_back("-lm"); } diff --git a/clang/lib/Driver/ToolChains/FreeBSD.cpp b/clang/lib/Driver/ToolChains/FreeBSD.cpp index 62206c5fb3c59..e7efe22aa59a8 100644 --- a/clang/lib/Driver/ToolChains/FreeBSD.cpp +++ b/clang/lib/Driver/ToolChains/FreeBSD.cpp @@ -319,8 +319,8 @@ void freebsd::Linker::ConstructJob(Compilation &C, const JobAction &JA, // AddRunTimeLibs). if (D.IsFlangMode() && !Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs)) { - addFortranRuntimeLibraryPath(ToolChain, Args, CmdArgs); - addFortranRuntimeLibs(ToolChain, Args, CmdArgs); + ToolChain.addFortranRuntimeLibraryPath(Args, CmdArgs); + ToolChain.addFortranRuntimeLibs(Args, CmdArgs); if (Profiling) CmdArgs.push_back("-lm_p"); else diff --git a/clang/lib/Driver/ToolChains/Gnu.cpp b/clang/lib/Driver/ToolChains/Gnu.cpp index f56eeda3cb5f6..77079f2a0f8b1 100644 --- a/clang/lib/Driver/ToolChains/Gnu.cpp +++ b/clang/lib/Driver/ToolChains/Gnu.cpp @@ -572,8 +572,8 @@ void tools::gnutools::Linker::ConstructJob(Compilation &C, const JobAction &JA, // AddRunTimeLibs). if (D.IsFlangMode() && !Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs)) { - addFortranRuntimeLibraryPath(ToolChain, Args, CmdArgs); - addFortranRuntimeLibs(ToolChain, Args, CmdArgs); + ToolChain.addFortranRuntimeLibraryPath(Args, CmdArgs); + ToolChain.addFortranRuntimeLibs(Args, CmdArgs); CmdArgs.push_back("-lm"); } diff --git a/clang/lib/Driver/ToolChains/Haiku.cpp b/clang/lib/Driver/ToolChains/Haiku.cpp index af74f43e48364..861d69710e091 100644 --- a/clang/lib/Driver/ToolChains/Haiku.cpp +++ b/clang/lib/Driver/ToolChains/Haiku.cpp @@ -121,8 +121,8 @@ void haiku::Linker::ConstructJob(Compilation &C, const JobAction &JA, // AddRunTimeLibs). if (D.IsFlangMode() && !Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs)) { - addFortranRuntimeLibraryPath(ToolChain, Args, CmdArgs); - addFortranRuntimeLibs(ToolChain, Args, CmdArgs); + ToolChain.addFortranRuntimeLibraryPath(Args, CmdArgs); + ToolChain.addFortranRuntimeLibs(Args, CmdArgs); } CmdArgs.push_back("-lgcc"); diff --git a/clang/lib/Driver/ToolChains/MSVC.cpp b/clang/lib/Driver/ToolChains/MSVC.cpp index d5a7fc7e85230..9ae61a528eb12 100644 --- a/clang/lib/Driver/ToolChains/MSVC.cpp +++ b/clang/lib/Driver/ToolChains/MSVC.cpp @@ -146,8 +146,8 @@ void visualstudio::Linker::ConstructJob(Compilation &C, const JobAction &JA, if (C.getDriver().IsFlangMode() && !Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs)) { - addFortranRuntimeLibraryPath(TC, Args, CmdArgs); - addFortranRuntimeLibs(TC, Args, CmdArgs); + TC.addFortranRuntimeLibraryPath(Args, CmdArgs); + TC.addFortranRuntimeLibs(Args, CmdArgs); // Inform the MSVC linker that we're generating a console application, i.e. // one with `main` as the "user-defined" entry point. The `main` function is diff --git a/clang/lib/Driver/ToolChains/MinGW.cpp b/clang/lib/Driver/ToolChains/MinGW.cpp index 9f0c6160a309e..031240610eef3 100644 --- a/clang/lib/Driver/ToolChains/MinGW.cpp +++ b/clang/lib/Driver/ToolChains/MinGW.cpp @@ -259,8 +259,8 @@ void tools::MinGW::Linker::ConstructJob(Compilation &C, const JobAction &JA, if (C.getDriver().IsFlangMode() && !Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs)) { - addFortranRuntimeLibraryPath(TC, Args, CmdArgs); - addFortranRuntimeLibs(TC, Args, CmdArgs); + TC.addFortranRuntimeLibraryPath(Args, CmdArgs); + TC.addFortranRuntimeLibs(Args, CmdArgs); } // TODO: Add profile stuff here diff --git a/clang/lib/Driver/ToolChains/MipsLinux.cpp b/clang/lib/Driver/ToolChains/MipsLinux.cpp index f61ae471b86d5..af77b2ebb9011 100644 --- a/clang/lib/Driver/ToolChains/MipsLinux.cpp +++ b/clang/lib/Driver/ToolChains/MipsLinux.cpp @@ -119,7 +119,8 @@ void MipsLLVMToolChain::AddCXXStdlibLibArgs(const ArgList &Args, std::string MipsLLVMToolChain::getCompilerRT(const ArgList &Args, StringRef Component, - FileType Type) const { + FileType Type, + bool IsFortran) const { SmallString<128> Path(getDriver().ResourceDir); llvm::sys::path::append(Path, SelectedMultilibs.back().osSuffix(), "lib" + LibSuffix, getOS()); diff --git a/clang/lib/Driver/ToolChains/MipsLinux.h b/clang/lib/Driver/ToolChains/MipsLinux.h index a968804f2a6ec..0ec23e3d65bb3 100644 --- a/clang/lib/Driver/ToolChains/MipsLinux.h +++ b/clang/lib/Driver/ToolChains/MipsLinux.h @@ -39,7 +39,8 @@ class LLVM_LIBRARY_VISIBILITY MipsLLVMToolChain : public Linux { std::string getCompilerRT(const llvm::opt::ArgList &Args, StringRef Component, - FileType Type = ToolChain::FT_Static) const override; + FileType Type = ToolChain::FT_Static, + bool IsFortran = false) const override; std::string computeSysRoot() const override; diff --git a/clang/lib/Driver/ToolChains/NetBSD.cpp b/clang/lib/Driver/ToolChains/NetBSD.cpp index c5469f32ac80b..ae164be1b4e8b 100644 --- a/clang/lib/Driver/ToolChains/NetBSD.cpp +++ b/clang/lib/Driver/ToolChains/NetBSD.cpp @@ -328,8 +328,8 @@ void netbsd::Linker::ConstructJob(Compilation &C, const JobAction &JA, // AddRunTimeLibs). if (D.IsFlangMode() && !Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs)) { - addFortranRuntimeLibraryPath(ToolChain, Args, CmdArgs); - addFortranRuntimeLibs(ToolChain, Args, CmdArgs); + ToolChain.addFortranRuntimeLibraryPath(Args, CmdArgs); + ToolChain.addFortranRuntimeLibs(Args, CmdArgs); CmdArgs.push_back("-lm"); } diff --git a/clang/lib/Driver/ToolChains/OHOS.cpp b/clang/lib/Driver/ToolChains/OHOS.cpp index e213c695a9fef..1cfa2a8f43b9d 100644 --- a/clang/lib/Driver/ToolChains/OHOS.cpp +++ b/clang/lib/Driver/ToolChains/OHOS.cpp @@ -341,7 +341,7 @@ std::string OHOS::getDynamicLinker(const ArgList &Args) const { } std::string OHOS::getCompilerRT(const ArgList &Args, StringRef Component, - FileType Type) const { + FileType Type, bool IsFortran) const { SmallString<128> Path(getDriver().ResourceDir); llvm::sys::path::append(Path, "lib", getMultiarchTriple(getTriple()), SelectedMultilib.gccSuffix()); diff --git a/clang/lib/Driver/ToolChains/OHOS.h b/clang/lib/Driver/ToolChains/OHOS.h index 2a380420922de..81b9e63679660 100644 --- a/clang/lib/Driver/ToolChains/OHOS.h +++ b/clang/lib/Driver/ToolChains/OHOS.h @@ -58,7 +58,8 @@ class LLVM_LIBRARY_VISIBILITY OHOS : public Generic_ELF { std::string getCompilerRT(const llvm::opt::ArgList &Args, StringRef Component, - FileType Type = ToolChain::FT_Static) const override; + FileType Type = ToolChain::FT_Static, + bool IsFortran = false) const override; const char *getDefaultLinker() const override { return "ld.lld"; diff --git a/clang/lib/Driver/ToolChains/OpenBSD.cpp b/clang/lib/Driver/ToolChains/OpenBSD.cpp index f668a11e78f81..6d9db5b3d4515 100644 --- a/clang/lib/Driver/ToolChains/OpenBSD.cpp +++ b/clang/lib/Driver/ToolChains/OpenBSD.cpp @@ -241,8 +241,8 @@ void openbsd::Linker::ConstructJob(Compilation &C, const JobAction &JA, // AddRunTimeLibs). if (D.IsFlangMode() && !Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs)) { - addFortranRuntimeLibraryPath(ToolChain, Args, CmdArgs); - addFortranRuntimeLibs(ToolChain, Args, CmdArgs); + ToolChain.addFortranRuntimeLibraryPath(Args, CmdArgs); + ToolChain.addFortranRuntimeLibs(Args, CmdArgs); if (Profiling) CmdArgs.push_back("-lm_p"); else @@ -372,7 +372,7 @@ void OpenBSD::AddCXXStdlibLibArgs(const ArgList &Args, } std::string OpenBSD::getCompilerRT(const ArgList &Args, StringRef Component, - FileType Type) const { + FileType Type, bool IsFortran) const { if (Component == "builtins") { SmallString<128> Path(getDriver().SysRoot); llvm::sys::path::append(Path, "/usr/lib/libcompiler_rt.a"); @@ -381,12 +381,13 @@ std::string OpenBSD::getCompilerRT(const ArgList &Args, StringRef Component, } SmallString<128> P(getDriver().ResourceDir); std::string CRTBasename = - buildCompilerRTBasename(Args, Component, Type, /*AddArch=*/false); + buildCompilerRTBasename(Args, Component, Type, /*AddArch=*/false, + IsFortran); llvm::sys::path::append(P, "lib", CRTBasename); // Checks if this is the base system case which uses a different location. if (getVFS().exists(P)) return std::string(P); - return ToolChain::getCompilerRT(Args, Component, Type); + return ToolChain::getCompilerRT(Args, Component, Type, IsFortran); } Tool *OpenBSD::buildAssembler() const { diff --git a/clang/lib/Driver/ToolChains/OpenBSD.h b/clang/lib/Driver/ToolChains/OpenBSD.h index b4350e72d5d26..11b873cb30032 100644 --- a/clang/lib/Driver/ToolChains/OpenBSD.h +++ b/clang/lib/Driver/ToolChains/OpenBSD.h @@ -80,7 +80,8 @@ class LLVM_LIBRARY_VISIBILITY OpenBSD : public Generic_ELF { llvm::opt::ArgStringList &CmdArgs) const override; std::string getCompilerRT(const llvm::opt::ArgList &Args, StringRef Component, - FileType Type = ToolChain::FT_Static) const override; + FileType Type = ToolChain::FT_Static, + bool IsFortran = false) const override; UnwindTableLevel getDefaultUnwindTableLevel(const llvm::opt::ArgList &Args) const override; diff --git a/clang/lib/Driver/ToolChains/PPCLinux.cpp b/clang/lib/Driver/ToolChains/PPCLinux.cpp index 0ed0f91ad166c..f8f97e222204b 100644 --- a/clang/lib/Driver/ToolChains/PPCLinux.cpp +++ b/clang/lib/Driver/ToolChains/PPCLinux.cpp @@ -12,6 +12,7 @@ #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; @@ -101,3 +102,37 @@ bool PPCLinuxToolChain::SupportIEEEFloat128( return GlibcSupportsFloat128((Twine(D.DyldPrefix) + Linker).str()) && !(D.CCCIsCXX() && HasUnsupportedCXXLib); } + +std::string PPCLinuxToolChain::getCompilerRT(const ArgList &Args, + StringRef Component, FileType Type, + bool IsFortran) const { + // Check for runtime files in the new layout without the architecture first. + std::string CRTBasename = buildCompilerRTBasename( + Args, Component, Type, /*AddArch=*/false, IsFortran); + SmallString<128> Path; + for (const auto &LibPath : getLibraryPaths()) { + SmallString<128> P(LibPath); + llvm::sys::path::append(P, CRTBasename); + if (getVFS().exists(P)) + return std::string(P); + if (Path.empty()) + Path = P; + } + return std::string(Path); +} + +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, + getDriver().IsFlangMode())))) + CmdArgs.push_back(Path); + else if (getVFS().exists(Twine(Path = getCompilerRTArgString( + Args, "runtime", ToolChain::FT_Shared, + getDriver().IsFlangMode())))) + 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 63adaff6be9c2..346f0ba2122b8 100644 --- a/clang/lib/Driver/ToolChains/PPCLinux.h +++ b/clang/lib/Driver/ToolChains/PPCLinux.h @@ -24,6 +24,13 @@ class LLVM_LIBRARY_VISIBILITY PPCLinuxToolChain : public Linux { AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args) const override; + std::string getCompilerRT(const llvm::opt::ArgList &Args, StringRef Component, + FileType Type = ToolChain::FT_Static, + bool IsFortran = false) 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/clang/lib/Driver/ToolChains/Solaris.cpp b/clang/lib/Driver/ToolChains/Solaris.cpp index fd3232b7c1b06..639497b8fbad2 100644 --- a/clang/lib/Driver/ToolChains/Solaris.cpp +++ b/clang/lib/Driver/ToolChains/Solaris.cpp @@ -225,8 +225,8 @@ void solaris::Linker::ConstructJob(Compilation &C, const JobAction &JA, // these dependencies need to be listed before the C runtime below. if (D.IsFlangMode() && !Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs)) { - addFortranRuntimeLibraryPath(getToolChain(), Args, CmdArgs); - addFortranRuntimeLibs(getToolChain(), Args, CmdArgs); + ToolChain.addFortranRuntimeLibraryPath(Args, CmdArgs); + ToolChain.addFortranRuntimeLibs(Args, CmdArgs); CmdArgs.push_back("-lm"); } if (Args.hasArg(options::OPT_fstack_protector) || diff --git a/flang-rt/cmake/modules/GetToolchainDirs.cmake b/flang-rt/cmake/modules/GetToolchainDirs.cmake index 8b384180bcc31..69c3f51ecda8f 100644 --- a/flang-rt/cmake/modules/GetToolchainDirs.cmake +++ b/flang-rt/cmake/modules/GetToolchainDirs.cmake @@ -119,6 +119,8 @@ function (get_toolchain_arch_dirname outvar) set(target "amdgcn-amd-amdhsa") elseif("${arch}" MATCHES "^nvptx") set(target "nvptx64-nvidia-cuda") + elseif(UNIX AND CMAKE_SYSTEM_NAME MATCHES "AIX") + string(TOLOWER "${CMAKE_SYSTEM_NAME}" target) else() set(target "${arch}${triple_suffix}") endif() >From ada4bea336933ac1e51795289f02703f631e39bb Mon Sep 17 00:00:00 2001 From: Daniel Chen <cdc...@ca.ibm.com> Date: Sat, 15 Mar 2025 16:32:17 -0400 Subject: [PATCH 03/11] [flang-rt] Fix a typo. --- clang/lib/Driver/ToolChains/AIX.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang/lib/Driver/ToolChains/AIX.cpp b/clang/lib/Driver/ToolChains/AIX.cpp index f2adcc0725c58..b02c870d257f6 100644 --- a/clang/lib/Driver/ToolChains/AIX.cpp +++ b/clang/lib/Driver/ToolChains/AIX.cpp @@ -362,7 +362,7 @@ void aix::Linker::ConstructJob(Compilation &C, const JobAction &JA, if (D.IsFlangMode() && !Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs)) { ToolChain.addFortranRuntimeLibraryPath(Args, CmdArgs); - // ToolChain.addFortranRuntimeLibs(Args, CmdArgs); + ToolChain.addFortranRuntimeLibs(Args, CmdArgs); CmdArgs.push_back("-lm"); CmdArgs.push_back("-lpthread"); } >From 56d8aaec2e30c56d94dfc9716f16bfc5d6f3ff93 Mon Sep 17 00:00:00 2001 From: Daniel Chen <cdc...@ca.ibm.com> Date: Sat, 15 Mar 2025 16:36:42 -0400 Subject: [PATCH 04/11] [flang-rt] Fix aother unintended change. --- clang/lib/Driver/ToolChain.cpp | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/clang/lib/Driver/ToolChain.cpp b/clang/lib/Driver/ToolChain.cpp index 029d8114d9282..4b9deba4fbeb3 100644 --- a/clang/lib/Driver/ToolChain.cpp +++ b/clang/lib/Driver/ToolChain.cpp @@ -824,11 +824,7 @@ void ToolChain::addFortranRuntimeLibs(const ArgList &Args, if (AsNeeded) addAsNeededOption(*this, Args, CmdArgs, /*as_needed=*/false); } - if (const char *res = getCompilerRTArgString( - Args, "runtime", ToolChain::FT_Static, getDriver().IsFlangMode())) - CmdArgs.push_back(res); - else - CmdArgs.push_back("-lflang_rt.runtime"); + CmdArgs.push_back("-lflang_rt.runtime"); addArchSpecificRPath(*this, Args, CmdArgs); // needs libexecinfo for backtrace functions >From 3acecf7c633c59eb48e4b15285d2e9c65adaf50e Mon Sep 17 00:00:00 2001 From: Daniel Chen <cdc...@ca.ibm.com> Date: Sat, 15 Mar 2025 17:01:08 -0400 Subject: [PATCH 05/11] [flang-rt] Fix format. --- clang/lib/Driver/ToolChain.cpp | 2 -- clang/lib/Driver/ToolChains/AVR.cpp | 8 ++++---- clang/lib/Driver/ToolChains/Darwin.h | 14 ++++++-------- clang/lib/Driver/ToolChains/MipsLinux.cpp | 3 +-- clang/lib/Driver/ToolChains/MipsLinux.h | 7 +++---- clang/lib/Driver/ToolChains/OHOS.h | 7 +++---- clang/lib/Driver/ToolChains/OpenBSD.cpp | 5 ++--- 7 files changed, 19 insertions(+), 27 deletions(-) diff --git a/clang/lib/Driver/ToolChain.cpp b/clang/lib/Driver/ToolChain.cpp index 4b9deba4fbeb3..5e08fbce59d5d 100644 --- a/clang/lib/Driver/ToolChain.cpp +++ b/clang/lib/Driver/ToolChain.cpp @@ -781,8 +781,6 @@ std::string ToolChain::getCompilerRT(const ArgList &Args, StringRef Component, if (Path.empty()) Path = P; } - if (getTriple().isOSAIX()) - Path.clear(); // Check the filename for the old layout if the new one does not exist. CRTBasename = buildCompilerRTBasename(Args, Component, Type, diff --git a/clang/lib/Driver/ToolChains/AVR.cpp b/clang/lib/Driver/ToolChains/AVR.cpp index 931be0c95bdcb..8b8956a0a15ef 100644 --- a/clang/lib/Driver/ToolChains/AVR.cpp +++ b/clang/lib/Driver/ToolChains/AVR.cpp @@ -424,10 +424,10 @@ Tool *AVRToolChain::buildLinker() const { return new tools::AVR::Linker(getTriple(), *this); } -std::string -AVRToolChain::getCompilerRT(const llvm::opt::ArgList &Args, StringRef Component, - FileType Type = ToolChain::FT_Static, - bool IsFortran) const { +std::string AVRToolChain::getCompilerRT(const llvm::opt::ArgList &Args, + StringRef Component, + FileType Type = ToolChain::FT_Static, + bool IsFortran) const { assert(Type == ToolChain::FT_Static && "AVR only supports static libraries"); // Since AVR can never be a host environment, its compiler-rt library files // should always have ".a" suffix, even on windows. diff --git a/clang/lib/Driver/ToolChains/Darwin.h b/clang/lib/Driver/ToolChains/Darwin.h index b3023eaa81318..4fa96d4cd892a 100644 --- a/clang/lib/Driver/ToolChains/Darwin.h +++ b/clang/lib/Driver/ToolChains/Darwin.h @@ -227,10 +227,9 @@ class LLVM_LIBRARY_VISIBILITY MachO : public ToolChain { // Return the full path of the compiler-rt library on a non-Darwin MachO // system. Those are under // <resourcedir>/lib/darwin/macho_embedded/<...>(.dylib|.a). - std::string - getCompilerRT(const llvm::opt::ArgList &Args, StringRef Component, - FileType Type = ToolChain::FT_Static, - bool IsFortran = false) const override; + std::string getCompilerRT(const llvm::opt::ArgList &Args, StringRef Component, + FileType Type = ToolChain::FT_Static, + bool IsFortran = false) const override; /// } /// @name ToolChain Implementation @@ -408,10 +407,9 @@ class LLVM_LIBRARY_VISIBILITY Darwin : public AppleMachO { // Return the full path of the compiler-rt library on a Darwin MachO system. // Those are under <resourcedir>/lib/darwin/<...>(.dylib|.a). - std::string - getCompilerRT(const llvm::opt::ArgList &Args, StringRef Component, - FileType Type = ToolChain::FT_Static, - bool IsFortran = false) const override; + std::string getCompilerRT(const llvm::opt::ArgList &Args, StringRef Component, + FileType Type = ToolChain::FT_Static, + bool IsFortran = false) const override; protected: /// } diff --git a/clang/lib/Driver/ToolChains/MipsLinux.cpp b/clang/lib/Driver/ToolChains/MipsLinux.cpp index af77b2ebb9011..0d025937cec9a 100644 --- a/clang/lib/Driver/ToolChains/MipsLinux.cpp +++ b/clang/lib/Driver/ToolChains/MipsLinux.cpp @@ -118,8 +118,7 @@ void MipsLLVMToolChain::AddCXXStdlibLibArgs(const ArgList &Args, } std::string MipsLLVMToolChain::getCompilerRT(const ArgList &Args, - StringRef Component, - FileType Type, + StringRef Component, FileType Type, bool IsFortran) const { SmallString<128> Path(getDriver().ResourceDir); llvm::sys::path::append(Path, SelectedMultilibs.back().osSuffix(), "lib" + LibSuffix, diff --git a/clang/lib/Driver/ToolChains/MipsLinux.h b/clang/lib/Driver/ToolChains/MipsLinux.h index 0ec23e3d65bb3..f9bf2e1fcd363 100644 --- a/clang/lib/Driver/ToolChains/MipsLinux.h +++ b/clang/lib/Driver/ToolChains/MipsLinux.h @@ -37,10 +37,9 @@ class LLVM_LIBRARY_VISIBILITY MipsLLVMToolChain : public Linux { void AddCXXStdlibLibArgs(const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs) const override; - std::string - getCompilerRT(const llvm::opt::ArgList &Args, StringRef Component, - FileType Type = ToolChain::FT_Static, - bool IsFortran = false) const override; + std::string getCompilerRT(const llvm::opt::ArgList &Args, StringRef Component, + FileType Type = ToolChain::FT_Static, + bool IsFortran = false) const override; std::string computeSysRoot() const override; diff --git a/clang/lib/Driver/ToolChains/OHOS.h b/clang/lib/Driver/ToolChains/OHOS.h index 81b9e63679660..0e0543b406069 100644 --- a/clang/lib/Driver/ToolChains/OHOS.h +++ b/clang/lib/Driver/ToolChains/OHOS.h @@ -56,10 +56,9 @@ class LLVM_LIBRARY_VISIBILITY OHOS : public Generic_ELF { std::string computeSysRoot() const override; std::string getDynamicLinker(const llvm::opt::ArgList &Args) const override; - std::string - getCompilerRT(const llvm::opt::ArgList &Args, StringRef Component, - FileType Type = ToolChain::FT_Static, - bool IsFortran = false) const override; + std::string getCompilerRT(const llvm::opt::ArgList &Args, StringRef Component, + FileType Type = ToolChain::FT_Static, + bool IsFortran = false) const override; const char *getDefaultLinker() const override { return "ld.lld"; diff --git a/clang/lib/Driver/ToolChains/OpenBSD.cpp b/clang/lib/Driver/ToolChains/OpenBSD.cpp index 6d9db5b3d4515..a5b1f06449b73 100644 --- a/clang/lib/Driver/ToolChains/OpenBSD.cpp +++ b/clang/lib/Driver/ToolChains/OpenBSD.cpp @@ -380,9 +380,8 @@ std::string OpenBSD::getCompilerRT(const ArgList &Args, StringRef Component, return std::string(Path); } SmallString<128> P(getDriver().ResourceDir); - std::string CRTBasename = - buildCompilerRTBasename(Args, Component, Type, /*AddArch=*/false, - IsFortran); + std::string CRTBasename = buildCompilerRTBasename( + Args, Component, Type, /*AddArch=*/false, IsFortran); llvm::sys::path::append(P, "lib", CRTBasename); // Checks if this is the base system case which uses a different location. if (getVFS().exists(P)) >From 2c898b039c3088eb94f21e476dfc71c39050078e Mon Sep 17 00:00:00 2001 From: Daniel Chen <cdc...@ca.ibm.com> Date: Sat, 15 Mar 2025 17:04:26 -0400 Subject: [PATCH 06/11] Undo unintended change to flang-rt cmake file. --- flang-rt/cmake/modules/GetToolchainDirs.cmake | 2 -- 1 file changed, 2 deletions(-) diff --git a/flang-rt/cmake/modules/GetToolchainDirs.cmake b/flang-rt/cmake/modules/GetToolchainDirs.cmake index 69c3f51ecda8f..8b384180bcc31 100644 --- a/flang-rt/cmake/modules/GetToolchainDirs.cmake +++ b/flang-rt/cmake/modules/GetToolchainDirs.cmake @@ -119,8 +119,6 @@ function (get_toolchain_arch_dirname outvar) set(target "amdgcn-amd-amdhsa") elseif("${arch}" MATCHES "^nvptx") set(target "nvptx64-nvidia-cuda") - elseif(UNIX AND CMAKE_SYSTEM_NAME MATCHES "AIX") - string(TOLOWER "${CMAKE_SYSTEM_NAME}" target) else() set(target "${arch}${triple_suffix}") endif() >From 6ebad499ddcd41816eb6709316cbc641e172c7b9 Mon Sep 17 00:00:00 2001 From: Daniel Chen <cdc...@ca.ibm.com> Date: Sat, 15 Mar 2025 17:10:05 -0400 Subject: [PATCH 07/11] Remove the leftover debug code. --- clang/lib/Driver/ToolChains/AIX.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/clang/lib/Driver/ToolChains/AIX.cpp b/clang/lib/Driver/ToolChains/AIX.cpp index b02c870d257f6..41bcc3f9d6cd1 100644 --- a/clang/lib/Driver/ToolChains/AIX.cpp +++ b/clang/lib/Driver/ToolChains/AIX.cpp @@ -18,9 +18,7 @@ #include "llvm/Support/Path.h" #include "llvm/Support/VirtualFileSystem.h" -#include <iostream> #include <set> -using namespace std; using AIX = clang::driver::toolchains::AIX; using namespace clang::driver; >From 5c7a7874ce5a173406df05c0c77c8b7b106cf2a7 Mon Sep 17 00:00:00 2001 From: Daniel Chen <cdc...@ca.ibm.com> Date: Sun, 16 Mar 2025 11:05:53 -0400 Subject: [PATCH 08/11] Evern though flang-rt only supports LLVM_ENABLE_PER_TARGET_RUNTIME_DIR=ON, LoP should still be able to handle both to be consistent with clang-rt. --- clang/lib/Driver/ToolChains/PPCLinux.cpp | 18 ------------------ clang/lib/Driver/ToolChains/PPCLinux.h | 4 ---- 2 files changed, 22 deletions(-) diff --git a/clang/lib/Driver/ToolChains/PPCLinux.cpp b/clang/lib/Driver/ToolChains/PPCLinux.cpp index f8f97e222204b..fe085078886dd 100644 --- a/clang/lib/Driver/ToolChains/PPCLinux.cpp +++ b/clang/lib/Driver/ToolChains/PPCLinux.cpp @@ -103,24 +103,6 @@ bool PPCLinuxToolChain::SupportIEEEFloat128( !(D.CCCIsCXX() && HasUnsupportedCXXLib); } -std::string PPCLinuxToolChain::getCompilerRT(const ArgList &Args, - StringRef Component, FileType Type, - bool IsFortran) const { - // Check for runtime files in the new layout without the architecture first. - std::string CRTBasename = buildCompilerRTBasename( - Args, Component, Type, /*AddArch=*/false, IsFortran); - SmallString<128> Path; - for (const auto &LibPath : getLibraryPaths()) { - SmallString<128> P(LibPath); - llvm::sys::path::append(P, CRTBasename); - if (getVFS().exists(P)) - return std::string(P); - if (Path.empty()) - Path = P; - } - return std::string(Path); -} - void PPCLinuxToolChain::addFortranRuntimeLibs( const ArgList &Args, llvm::opt::ArgStringList &CmdArgs) const { // Link static flang_rt.runtime.a or shared flang_rt.runtime.so diff --git a/clang/lib/Driver/ToolChains/PPCLinux.h b/clang/lib/Driver/ToolChains/PPCLinux.h index 346f0ba2122b8..910df3d16e6a5 100644 --- a/clang/lib/Driver/ToolChains/PPCLinux.h +++ b/clang/lib/Driver/ToolChains/PPCLinux.h @@ -24,10 +24,6 @@ class LLVM_LIBRARY_VISIBILITY PPCLinuxToolChain : public Linux { AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args) const override; - std::string getCompilerRT(const llvm::opt::ArgList &Args, StringRef Component, - FileType Type = ToolChain::FT_Static, - bool IsFortran = false) const override; - void addFortranRuntimeLibs(const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs) const override; >From f6879913ef7334183cd8e170dd889172f334f2f8 Mon Sep 17 00:00:00 2001 From: Daniel Chen <cdc...@ca.ibm.com> Date: Mon, 17 Mar 2025 20:45:47 -0400 Subject: [PATCH 09/11] Change IsFlangMode to literal true as it was checked already. --- clang/lib/Driver/ToolChains/AIX.cpp | 2 +- clang/lib/Driver/ToolChains/PPCLinux.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/clang/lib/Driver/ToolChains/AIX.cpp b/clang/lib/Driver/ToolChains/AIX.cpp index 41bcc3f9d6cd1..055385bd567c0 100644 --- a/clang/lib/Driver/ToolChains/AIX.cpp +++ b/clang/lib/Driver/ToolChains/AIX.cpp @@ -626,7 +626,7 @@ void AIX::addFortranRuntimeLibs(const ArgList &Args, // 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, getDriver().IsFlangMode())); + Args, "runtime", ToolChain::FT_Static, true)); } ToolChain::CXXStdlibType AIX::GetDefaultCXXStdlibType() const { diff --git a/clang/lib/Driver/ToolChains/PPCLinux.cpp b/clang/lib/Driver/ToolChains/PPCLinux.cpp index fe085078886dd..62ac6509c3549 100644 --- a/clang/lib/Driver/ToolChains/PPCLinux.cpp +++ b/clang/lib/Driver/ToolChains/PPCLinux.cpp @@ -109,7 +109,7 @@ void PPCLinuxToolChain::addFortranRuntimeLibs( const char *Path; if (getVFS().exists(Twine( Path = getCompilerRTArgString(Args, "runtime", ToolChain::FT_Static, - getDriver().IsFlangMode())))) + true)))) CmdArgs.push_back(Path); else if (getVFS().exists(Twine(Path = getCompilerRTArgString( Args, "runtime", ToolChain::FT_Shared, >From b0b738561171390f57ae148696488c11f21a2e69 Mon Sep 17 00:00:00 2001 From: Daniel Chen <cdc...@ca.ibm.com> Date: Mon, 17 Mar 2025 20:49:26 -0400 Subject: [PATCH 10/11] Change IsFlangMode to literal true as it was checked already - missed one. --- clang/lib/Driver/ToolChains/PPCLinux.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/clang/lib/Driver/ToolChains/PPCLinux.cpp b/clang/lib/Driver/ToolChains/PPCLinux.cpp index 62ac6509c3549..284f3b045306d 100644 --- a/clang/lib/Driver/ToolChains/PPCLinux.cpp +++ b/clang/lib/Driver/ToolChains/PPCLinux.cpp @@ -111,9 +111,9 @@ void PPCLinuxToolChain::addFortranRuntimeLibs( Path = getCompilerRTArgString(Args, "runtime", ToolChain::FT_Static, true)))) CmdArgs.push_back(Path); - else if (getVFS().exists(Twine(Path = getCompilerRTArgString( - Args, "runtime", ToolChain::FT_Shared, - getDriver().IsFlangMode())))) + else if (getVFS().exists( + Twine(Path = getCompilerRTArgString( + Args, "runtime", ToolChain::FT_Shared, true)))) CmdArgs.push_back(Path); else CmdArgs.push_back("-lflang_rt.runtime"); >From 19bdc525db7a523d12a8dfcca41e452b3ce055ee Mon Sep 17 00:00:00 2001 From: Daniel Chen <cdc...@ca.ibm.com> Date: Mon, 17 Mar 2025 20:54:12 -0400 Subject: [PATCH 11/11] Fixing format. --- clang/lib/Driver/ToolChains/AIX.cpp | 4 ++-- clang/lib/Driver/ToolChains/PPCLinux.cpp | 5 ++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/clang/lib/Driver/ToolChains/AIX.cpp b/clang/lib/Driver/ToolChains/AIX.cpp index 055385bd567c0..b37563bd85453 100644 --- a/clang/lib/Driver/ToolChains/AIX.cpp +++ b/clang/lib/Driver/ToolChains/AIX.cpp @@ -625,8 +625,8 @@ 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)); + CmdArgs.push_back( + getCompilerRTArgString(Args, "runtime", ToolChain::FT_Static, true)); } ToolChain::CXXStdlibType AIX::GetDefaultCXXStdlibType() const { diff --git a/clang/lib/Driver/ToolChains/PPCLinux.cpp b/clang/lib/Driver/ToolChains/PPCLinux.cpp index 284f3b045306d..575e88c6ab124 100644 --- a/clang/lib/Driver/ToolChains/PPCLinux.cpp +++ b/clang/lib/Driver/ToolChains/PPCLinux.cpp @@ -107,9 +107,8 @@ 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)))) + if (getVFS().exists(Twine(Path = getCompilerRTArgString( + Args, "runtime", ToolChain::FT_Static, true)))) CmdArgs.push_back(Path); else if (getVFS().exists( Twine(Path = getCompilerRTArgString( _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits