[llvm-branch-commits] [clang] b29813f - [OpenMP] Use executable path when searching for lld

Tom Stellard via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Mon Feb 28 15:20:38 PST 2022


Author: Joseph Huber
Date: 2022-02-28T15:16:01-08:00
New Revision: b29813fbbbaf222d80e422320fe67f4e3c0992be

URL: https://github.com/llvm/llvm-project/commit/b29813fbbbaf222d80e422320fe67f4e3c0992be
DIFF: https://github.com/llvm/llvm-project/commit/b29813fbbbaf222d80e422320fe67f4e3c0992be.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.

(cherry picked from commit 7ee8bd60f225b36623114f52103b0ecb91e2fb64)

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)


        


More information about the llvm-branch-commits mailing list