|
17 | 17 | #include "clang/Driver/Driver.h"
|
18 | 18 | #include "llvm/ADT/STLExtras.h"
|
19 | 19 | #include "llvm/ADT/SmallString.h"
|
| 20 | +#include "llvm/Config/config.h" |
20 | 21 | #include "llvm/Support/FileSystem.h"
|
21 | 22 | #include "llvm/Support/MD5.h"
|
22 | 23 | #include "llvm/Support/Path.h"
|
@@ -125,21 +126,28 @@ const std::string &CIndexer::getClangResourcesPath() {
|
125 | 126 | #elif defined(_AIX)
|
126 | 127 | getClangResourcesPathImplAIX(LibClangPath);
|
127 | 128 | #else
|
| 129 | + bool PathFound = false; |
| 130 | +#if defined(HAVE_DLFCN_H) && defined(HAVE_DLADDR) |
128 | 131 | Dl_info info;
|
129 |
| - std::string Path; |
130 | 132 | // This silly cast below avoids a C++ warning.
|
131 | 133 | if (dladdr((void *)(uintptr_t)clang_createTranslationUnit, &info) != 0) {
|
132 | 134 | // We now have the CIndex directory, locate clang relative to it.
|
133 | 135 | 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 | + } |
143 | 151 | }
|
144 | 152 |
|
145 | 153 | #endif
|
|
0 commit comments