Skip to content

Commit

Permalink
[SystemZ][z/OS] Add guard for dl_info and dladdr (#75637)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
abhina-sree committed Dec 18, 2023
1 parent 9d25b28 commit 8a233d8
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions clang/tools/libclang/CIndexer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 8a233d8

Please sign in to comment.