This revision was landed with ongoing or failed builds. This revision was automatically updated to reflect the committed changes. Closed by commit rG75d12e49c729: [libclang] Fall back to getMainExecutable when dladdr fails (authored by aykevl).
Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D124815/new/ https://reviews.llvm.org/D124815 Files: clang/tools/libclang/CIndexer.cpp Index: clang/tools/libclang/CIndexer.cpp =================================================================== --- clang/tools/libclang/CIndexer.cpp +++ clang/tools/libclang/CIndexer.cpp @@ -125,13 +125,23 @@ #elif defined(_AIX) getClangResourcesPathImplAIX(LibClangPath); #else - // This silly cast below avoids a C++ warning. Dl_info info; - if (dladdr((void *)(uintptr_t)clang_createTranslationUnit, &info) == 0) - llvm_unreachable("Call to dladdr() failed"); + 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"); + } - // We now have the CIndex directory, locate clang relative to it. - LibClangPath += info.dli_fname; #endif // Cache our result.
Index: clang/tools/libclang/CIndexer.cpp =================================================================== --- clang/tools/libclang/CIndexer.cpp +++ clang/tools/libclang/CIndexer.cpp @@ -125,13 +125,23 @@ #elif defined(_AIX) getClangResourcesPathImplAIX(LibClangPath); #else - // This silly cast below avoids a C++ warning. Dl_info info; - if (dladdr((void *)(uintptr_t)clang_createTranslationUnit, &info) == 0) - llvm_unreachable("Call to dladdr() failed"); + 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"); + } - // We now have the CIndex directory, locate clang relative to it. - LibClangPath += info.dli_fname; #endif // Cache our result.
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits