[clang] 8a233d8 - [SystemZ][z/OS] Add guard for dl_info and dladdr (#75637)

via cfe-commits cfe-commits at lists.llvm.org
Mon Dec 18 07:33:27 PST 2023


Author: Abhina Sree
Date: 2023-12-18T10:33:23-05:00
New Revision: 8a233d8cfde4cd026b5dd12b56ea029749a02329

URL: https://github.com/llvm/llvm-project/commit/8a233d8cfde4cd026b5dd12b56ea029749a02329
DIFF: https://github.com/llvm/llvm-project/commit/8a233d8cfde4cd026b5dd12b56ea029749a02329.diff

LOG: [SystemZ][z/OS] Add guard for dl_info and dladdr (#75637)

This patch fixes the following build error on z/OS `error: unknown type name 'Dl_info'` by adding a guard to check if we have dladdr.

Added: 
    

Modified: 
    clang/tools/libclang/CIndexer.cpp

Removed: 
    


################################################################################
diff  --git a/clang/tools/libclang/CIndexer.cpp b/clang/tools/libclang/CIndexer.cpp
index 77da2e4fa5ead0..0623ae69fe01ed 100644
--- a/clang/tools/libclang/CIndexer.cpp
+++ b/clang/tools/libclang/CIndexer.cpp
@@ -17,6 +17,7 @@
 #include "clang/Driver/Driver.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/SmallString.h"
+#include "llvm/Config/config.h"
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/MD5.h"
 #include "llvm/Support/Path.h"
@@ -125,21 +126,28 @@ const std::string &CIndexer::getClangResourcesPath() {
 #elif defined(_AIX)
   getClangResourcesPathImplAIX(LibClangPath);
 #else
+  bool PathFound = false;
+#if defined(HAVE_DLFCN_H) && defined(HAVE_DLADDR)
   Dl_info info;
-  std::string Path;
   // This silly cast below avoids a C++ warning.
   if (dladdr((void *)(uintptr_t)clang_createTranslationUnit, &info) != 0) {
     // We now have the CIndex directory, locate clang relative to it.
     LibClangPath += info.dli_fname;
-  } else if (!(Path = llvm::sys::fs::getMainExecutable(nullptr, nullptr)).empty()) {
-    // If we can't get the path using dladdr, try to get the main executable
-    // path. This may be needed when we're statically linking libclang with
-    // musl libc, for example.
-    LibClangPath += Path;
-  } else {
-    // It's rather unlikely we end up here. But it could happen, so report an
-    // error instead of crashing.
-    llvm::report_fatal_error("could not locate Clang resource path");
+    PathFound = true;
+  }
+#endif
+  std::string Path;
+  if (!PathFound) {
+    if (!(Path = llvm::sys::fs::getMainExecutable(nullptr, nullptr)).empty()) {
+      // If we can't get the path using dladdr, try to get the main executable
+      // path. This may be needed when we're statically linking libclang with
+      // musl libc, for example.
+      LibClangPath += Path;
+    } else {
+      // It's rather unlikely we end up here. But it could happen, so report an
+      // error instead of crashing.
+      llvm::report_fatal_error("could not locate Clang resource path");
+    }
   }
 
 #endif


        


More information about the cfe-commits mailing list