--- tools/clang/lib/Driver/Tools.cpp.orig 2017-01-26 08:40:33.955918000 +0000 +++ tools/clang/lib/Driver/Tools.cpp 2017-01-26 09:41:36.791095000 +0000 @@ -3216,13 +3216,22 @@ switch (TC.getDriver().getOpenMPRuntime(Args)) { case Driver::OMPRT_OMP: - CmdArgs.push_back("-lomp"); + if (TC.getTriple().getOS() != llvm::Triple::FreeBSD || TC.isCrossCompiling() || !llvm::sys::fs::exists("/usr/local/llvm40/lib/libomp.so")) + CmdArgs.push_back("-lomp"); + else + CmdArgs.push_back("/usr/local/llvm40/lib/libomp.so"); break; case Driver::OMPRT_GOMP: - CmdArgs.push_back("-lgomp"); + if (TC.getTriple().getOS() != llvm::Triple::FreeBSD || TC.isCrossCompiling() || !llvm::sys::fs::exists("/usr/local/llvm40/lib/libgomp.so")) + CmdArgs.push_back("-lgomp"); + else + CmdArgs.push_back("/usr/local/llvm40/lib/libgomp.so"); break; case Driver::OMPRT_IOMP5: - CmdArgs.push_back("-liomp5"); + if (TC.getTriple().getOS() != llvm::Triple::FreeBSD || TC.isCrossCompiling() || !llvm::sys::fs::exists("/usr/local/llvm40/lib/libiomp5.so")) + CmdArgs.push_back("-liomp5"); + else + CmdArgs.push_back("/usr/local/llvm40/lib/libiomp5.so"); break; case Driver::OMPRT_Unknown: // Already diagnosed. @@ -10235,17 +10244,26 @@ // Also link the particular OpenMP runtimes. switch (ToolChain.getDriver().getOpenMPRuntime(Args)) { case Driver::OMPRT_OMP: - CmdArgs.push_back("-lomp"); + if (ToolChain.getTriple().getOS() != llvm::Triple::FreeBSD || ToolChain.isCrossCompiling() || !llvm::sys::fs::exists("/usr/local/llvm40/lib/libomp.so")) + CmdArgs.push_back("-lomp"); + else + CmdArgs.push_back("/usr/local/llvm40/lib/libomp.so"); break; case Driver::OMPRT_GOMP: - CmdArgs.push_back("-lgomp"); + if (ToolChain.getTriple().getOS() != llvm::Triple::FreeBSD || ToolChain.isCrossCompiling( ) || !llvm::sys::fs::exists("/usr/local/llvm40/lib/libgomp.so")) { + CmdArgs.push_back("-lgomp"); - // FIXME: Exclude this for platforms with libgomp that don't require - // librt. Most modern Linux platforms require it, but some may not. - CmdArgs.push_back("-lrt"); + // FIXME: Exclude this for platforms with libgomp that don't require + // librt. Most modern Linux platforms require it, but some may not. + CmdArgs.push_back("-lrt"); + } else + CmdArgs.push_back("/usr/local/llvm40/lib/libgomp.so"); break; case Driver::OMPRT_IOMP5: - CmdArgs.push_back("-liomp5"); + if (ToolChain.getTriple().getOS() != llvm::Triple::FreeBSD || ToolChain.isCrossCompiling( ) || !llvm::sys::fs::exists("/usr/local/llvm40/lib/libiomp5.so")) + CmdArgs.push_back("-liomp5"); + else + CmdArgs.push_back("/usr/local/llvm40/lib/libiomp5.so"); break; case Driver::OMPRT_Unknown: // Already diagnosed.