Author: Joseph Huber Date: 2022-02-07T15:09:51-05:00 New Revision: 7ee8bd60f225b36623114f52103b0ecb91e2fb64
URL: https://github.com/llvm/llvm-project/commit/7ee8bd60f225b36623114f52103b0ecb91e2fb64 DIFF: https://github.com/llvm/llvm-project/commit/7ee8bd60f225b36623114f52103b0ecb91e2fb64.diff LOG: [OpenMP] Use executable path when searching for lld Summary: This patch changes the ClangLinkerWrapper to use the executable path when searching for the lld binary. Previously we relied on the program name. Also not finding 'llvm-strip' is not considered an error anymore because it is an optional optimization. Added: Modified: clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp Removed: ################################################################################ diff --git a/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp b/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp index 2f5ddb77b7b3f..65c9a87edf3f1 100644 --- a/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp +++ b/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp @@ -174,6 +174,12 @@ static StringRef getDeviceFileExtension(StringRef DeviceTriple, return "o"; } +std::string getMainExecutable(const char *Name) { + void *Ptr = (void *)(intptr_t)&getMainExecutable; + auto COWPath = sys::fs::getMainExecutable(Name, Ptr); + return sys::path::parent_path(COWPath).str(); +} + /// Extract the device file from the string '<triple>-<arch>=<library>.bc'. DeviceFile getBitcodeLibrary(StringRef LibraryStr) { auto DeviceAndPath = StringRef(LibraryStr).split('='); @@ -310,16 +316,12 @@ extractFromBinary(const ObjectFile &Obj, // We will use llvm-strip to remove the now unneeded section containing the // offloading code. - void *P = (void *)(intptr_t)&Help; - StringRef COWDir = ""; - auto COWPath = sys::fs::getMainExecutable("llvm-strip", P); - if (!COWPath.empty()) - COWDir = sys::path::parent_path(COWPath); ErrorOr<std::string> StripPath = - sys::findProgramByName("llvm-strip", {COWDir}); + sys::findProgramByName("llvm-strip", {getMainExecutable("llvm-strip")}); if (!StripPath) - return createStringError(StripPath.getError(), - "Unable to find 'llvm-strip' in path"); + StripPath = sys::findProgramByName("llvm-strip"); + if (!StripPath) + return None; SmallString<128> TempFile; if (Error Err = createOutputFile(Prefix + "-host", Extension, TempFile)) @@ -608,9 +610,9 @@ Expected<std::string> link(ArrayRef<std::string> InputFiles, Triple TheTriple, namespace amdgcn { Expected<std::string> link(ArrayRef<std::string> InputFiles, Triple TheTriple, StringRef Arch) { - // AMDGPU uses the lld binary to link device object files. + // AMDGPU uses lld to link device object files. ErrorOr<std::string> LLDPath = - sys::findProgramByName("lld", sys::path::parent_path(LinkerExecutable)); + sys::findProgramByName("lld", {getMainExecutable("lld")}); if (!LLDPath) LLDPath = sys::findProgramByName("lld"); if (!LLDPath) _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits