From: Joseph Huber Date: Mon, 7 Feb 2022 19:59:03 +0000 (-0500) Subject: [OpenMP] Use executable path when searching for lld X-Git-Tag: upstream/15.0.7~17494 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=7ee8bd60f225b36623114f52103b0ecb91e2fb64;p=platform%2Fupstream%2Fllvm.git [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. --- diff --git a/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp b/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp index 2f5ddb7..65c9a87 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 '-=.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 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 link(ArrayRef InputFiles, Triple TheTriple, namespace amdgcn { Expected link(ArrayRef InputFiles, Triple TheTriple, StringRef Arch) { - // AMDGPU uses the lld binary to link device object files. + // AMDGPU uses lld to link device object files. ErrorOr LLDPath = - sys::findProgramByName("lld", sys::path::parent_path(LinkerExecutable)); + sys::findProgramByName("lld", {getMainExecutable("lld")}); if (!LLDPath) LLDPath = sys::findProgramByName("lld"); if (!LLDPath)