Skip to content

[SystemZ][z/OS] Add guard for dl_info and dladdr #75637

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 18, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a private LLVM header, see the comment at the top of the file. It cannot be included in other subprojects.

You either have to export this macro from llvm-config.h, or you have to add it to clang's config.h.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I created a fix for it here #75928

#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