diff --git a/clang/lib/Driver/ToolChains/AIX.cpp b/clang/lib/Driver/ToolChains/AIX.cpp index a8acf9cfc44c9..03f12f7e6d690 100644 --- a/clang/lib/Driver/ToolChains/AIX.cpp +++ b/clang/lib/Driver/ToolChains/AIX.cpp @@ -297,6 +297,7 @@ void aix::Linker::ConstructJob(Compilation &C, const JobAction &JA, } // Add directory to library search path. + bool hasFOpenMP = false; Args.AddAllArgs(CmdArgs, options::OPT_L); if (!Args.hasArg(options::OPT_r)) { ToolChain.AddFilePathLibArgs(Args, CmdArgs); @@ -309,8 +310,9 @@ void aix::Linker::ConstructJob(Compilation &C, const JobAction &JA, AddRunTimeLibs(ToolChain, D, CmdArgs, Args); // Add OpenMP runtime if -fopenmp is specified. - if (Args.hasFlag(options::OPT_fopenmp, options::OPT_fopenmp_EQ, - options::OPT_fno_openmp, false)) { + hasFOpenMP = Args.hasFlag(options::OPT_fopenmp, options::OPT_fopenmp_EQ, + options::OPT_fno_openmp, false); + if (hasFOpenMP) { switch (ToolChain.getDriver().getOpenMPRuntime(Args)) { case Driver::OMPRT_OMP: CmdArgs.push_back("-lomp"); @@ -325,10 +327,13 @@ void aix::Linker::ConstructJob(Compilation &C, const JobAction &JA, // Already diagnosed. break; } + + CmdArgs.push_back("-lperfstat"); } // Support POSIX threads if "-pthreads" or "-pthread" is present. - if (Args.hasArg(options::OPT_pthreads, options::OPT_pthread)) + if (hasFOpenMP || + Args.hasArg(options::OPT_pthreads, options::OPT_pthread)) CmdArgs.push_back("-lpthreads"); if (D.CCCIsCXX()) @@ -350,7 +355,9 @@ void aix::Linker::ConstructJob(Compilation &C, const JobAction &JA, ToolChain.addFortranRuntimeLibraryPath(Args, CmdArgs); ToolChain.addFortranRuntimeLibs(Args, CmdArgs); CmdArgs.push_back("-lm"); - CmdArgs.push_back("-lpthread"); + // If the -fopenmp option is specified, no need to add it again. + if (!hasFOpenMP) + CmdArgs.push_back("-lpthreads"); } const char *Exec = Args.MakeArgString(ToolChain.GetLinkerPath()); C.addCommand(std::make_unique(JA, *this, ResponseFileSupport::None(),