Skip to content

Commit 8a233d8

Browse files
authored
[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.
1 parent 9d25b28 commit 8a233d8

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

clang/tools/libclang/CIndexer.cpp

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "clang/Driver/Driver.h"
1818
#include "llvm/ADT/STLExtras.h"
1919
#include "llvm/ADT/SmallString.h"
20+
#include "llvm/Config/config.h"
2021
#include "llvm/Support/FileSystem.h"
2122
#include "llvm/Support/MD5.h"
2223
#include "llvm/Support/Path.h"
@@ -125,21 +126,28 @@ const std::string &CIndexer::getClangResourcesPath() {
125126
#elif defined(_AIX)
126127
getClangResourcesPathImplAIX(LibClangPath);
127128
#else
129+
bool PathFound = false;
130+
#if defined(HAVE_DLFCN_H) && defined(HAVE_DLADDR)
128131
Dl_info info;
129-
std::string Path;
130132
// This silly cast below avoids a C++ warning.
131133
if (dladdr((void *)(uintptr_t)clang_createTranslationUnit, &info) != 0) {
132134
// We now have the CIndex directory, locate clang relative to it.
133135
LibClangPath += info.dli_fname;
134-
} else if (!(Path = llvm::sys::fs::getMainExecutable(nullptr, nullptr)).empty()) {
135-
// If we can't get the path using dladdr, try to get the main executable
136-
// path. This may be needed when we're statically linking libclang with
137-
// musl libc, for example.
138-
LibClangPath += Path;
139-
} else {
140-
// It's rather unlikely we end up here. But it could happen, so report an
141-
// error instead of crashing.
142-
llvm::report_fatal_error("could not locate Clang resource path");
136+
PathFound = true;
137+
}
138+
#endif
139+
std::string Path;
140+
if (!PathFound) {
141+
if (!(Path = llvm::sys::fs::getMainExecutable(nullptr, nullptr)).empty()) {
142+
// If we can't get the path using dladdr, try to get the main executable
143+
// path. This may be needed when we're statically linking libclang with
144+
// musl libc, for example.
145+
LibClangPath += Path;
146+
} else {
147+
// It's rather unlikely we end up here. But it could happen, so report an
148+
// error instead of crashing.
149+
llvm::report_fatal_error("could not locate Clang resource path");
150+
}
143151
}
144152

145153
#endif

0 commit comments

Comments
 (0)