diff options
author | Abhina Sree <69635948+abhina-sree@users.noreply.github.com> | 2023-12-18 10:33:23 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-12-18 10:33:23 -0500 |
commit | 8a233d8cfde4cd026b5dd12b56ea029749a02329 (patch) | |
tree | 4084cb4a595146cf79bee4a6ccaf0a84ee2fafb8 | |
parent | 9d25b28b9e412b66bb58993dff6646a8f08b8c8c (diff) | |
download | llvm-8a233d8cfde4cd026b5dd12b56ea029749a02329.zip llvm-8a233d8cfde4cd026b5dd12b56ea029749a02329.tar.gz llvm-8a233d8cfde4cd026b5dd12b56ea029749a02329.tar.bz2 |
[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.
-rw-r--r-- | clang/tools/libclang/CIndexer.cpp | 28 |
1 files changed, 18 insertions, 10 deletions
diff --git a/clang/tools/libclang/CIndexer.cpp b/clang/tools/libclang/CIndexer.cpp index 77da2e4..0623ae6 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 |