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

Abhina Sree via cfe-commits cfe-commits at lists.llvm.org
Fri Dec 15 10:45:06 PST 2023


https://github.com/abhina-sree updated https://github.com/llvm/llvm-project/pull/75637

>From 6b102c50136b8f49b2d678b06fb8f14f866cca70 Mon Sep 17 00:00:00 2001
From: Abhina Sreeskantharajan <Abhina.Sreeskantharajan at ibm.com>
Date: Fri, 15 Dec 2023 13:13:24 -0500
Subject: [PATCH 1/3] check if we have dlfcn.h and dladdr

---
 clang/tools/libclang/CIndexer.cpp | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/clang/tools/libclang/CIndexer.cpp b/clang/tools/libclang/CIndexer.cpp
index 77da2e4fa5ead0..41f8a6f2dac5fb 100644
--- a/clang/tools/libclang/CIndexer.cpp
+++ b/clang/tools/libclang/CIndexer.cpp
@@ -125,13 +125,19 @@ const std::string &CIndexer::getClangResourcesPath() {
 #elif defined(_AIX)
   getClangResourcesPathImplAIX(LibClangPath);
 #else
+  bool pathNotFound = 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()) {
+  } else
+    pathNotFound = true;
+#endif
+  if (pathNotFound &&
+      !(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.

>From a31b44ad737709a4550d622bb12565aa5acd6b76 Mon Sep 17 00:00:00 2001
From: Abhina Sreeskantharajan <Abhina.Sreeskantharajan at ibm.com>
Date: Fri, 15 Dec 2023 13:30:52 -0500
Subject: [PATCH 2/3] move Path down

---
 clang/tools/libclang/CIndexer.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/tools/libclang/CIndexer.cpp b/clang/tools/libclang/CIndexer.cpp
index 41f8a6f2dac5fb..41c55b59e19ca7 100644
--- a/clang/tools/libclang/CIndexer.cpp
+++ b/clang/tools/libclang/CIndexer.cpp
@@ -128,7 +128,6 @@ const std::string &CIndexer::getClangResourcesPath() {
   bool pathNotFound = 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.
@@ -136,6 +135,7 @@ const std::string &CIndexer::getClangResourcesPath() {
   } else
     pathNotFound = true;
 #endif
+  std::string Path;
   if (pathNotFound &&
       !(Path = llvm::sys::fs::getMainExecutable(nullptr, nullptr)).empty()) {
     // If we can't get the path using dladdr, try to get the main executable

>From 4954b4cc8be660c1682dec976677b922d530f1ac Mon Sep 17 00:00:00 2001
From: Abhina Sreeskantharajan <Abhina.Sreeskantharajan at ibm.com>
Date: Fri, 15 Dec 2023 13:44:56 -0500
Subject: [PATCH 3/3] add include

---
 clang/tools/libclang/CIndexer.cpp | 1 +
 1 file changed, 1 insertion(+)

diff --git a/clang/tools/libclang/CIndexer.cpp b/clang/tools/libclang/CIndexer.cpp
index 41c55b59e19ca7..30b799b1d69475 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"



More information about the cfe-commits mailing list