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

Conversation

abhina-sree
Copy link
Contributor

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.

@abhina-sree abhina-sree self-assigned this Dec 15, 2023
@llvmbot llvmbot added the clang Clang issues not falling into any other category label Dec 15, 2023
@llvmbot
Copy link
Member

llvmbot commented Dec 15, 2023

@llvm/pr-subscribers-clang

Author: Abhina Sree (abhina-sree)

Changes

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.


Full diff: https://github.com/llvm/llvm-project/pull/75637.diff

1 Files Affected:

  • (modified) clang/tools/libclang/CIndexer.cpp (+7-1)
diff --git a/clang/tools/libclang/CIndexer.cpp b/clang/tools/libclang/CIndexer.cpp
index 77da2e4fa5ead0..41f8a6f2dac5fb 100644
--- a/clang/tools/libclang/CIndexer.cpp
+++ b/clang/tools/libclang/CIndexer.cpp
@@ -125,13 +125,19 @@ const std::string &CIndexer::getClangResourcesPath() {
 #elif defined(_AIX)
   getClangResourcesPathImplAIX(LibClangPath);
 #else
+  bool pathNotFound = 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()) {
+  } else
+    pathNotFound = true;
+#endif
+  if (pathNotFound &&
+      !(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.

Copy link
Contributor

@fanbo-meng fanbo-meng left a comment

Choose a reason for hiding this comment

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

LGTM with nit

@abhina-sree abhina-sree merged commit 8a233d8 into llvm:main Dec 18, 2023
@abhina-sree abhina-sree deleted the abhina/fix_dl_info branch December 18, 2023 15:33
@@ -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

@chapuni
Copy link
Contributor

chapuni commented Dec 21, 2023

Could we take other ways? I think they don't affect external API.

  1. Detect stuff in clang/Config/config.h
  2. Migrate the special logic to llvm/Support.

@abhina-sree
Copy link
Contributor Author

Could we take other ways? I think they don't affect external API.

  1. Detect stuff in clang/Config/config.h
  2. Migrate the special logic to llvm/Support.

Thanks, I've created a patch here that detects the header in clang's config.h. Please let me know if this is a good approach

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants