Skip to content

Commit d430c14

Browse files
authored
[CMake] Move check for dlfcn.h and dladdr to clang (#76163)
This patch checks for the presence of dlfcn.h and dladdr in clang to be used in clang/tools/libclang/CIndexer.cpp
1 parent 7ab16fb commit d430c14

File tree

5 files changed

+31
-8
lines changed

5 files changed

+31
-8
lines changed

clang/CMakeLists.txt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,23 @@ endif()
167167
include(CheckIncludeFile)
168168
check_include_file(sys/resource.h CLANG_HAVE_RLIMITS)
169169

170+
# This check requires _GNU_SOURCE on linux
171+
check_include_file(dlfcn.h CLANG_HAVE_DLFCN_H)
172+
if( CLANG_HAVE_DLFCN_H )
173+
include(CheckLibraryExists)
174+
include(CheckSymbolExists)
175+
check_library_exists(dl dlopen "" HAVE_LIBDL)
176+
if( HAVE_LIBDL )
177+
list(APPEND CMAKE_REQUIRED_LIBRARIES dl)
178+
endif()
179+
list(APPEND CMAKE_REQUIRED_DEFINITIONS -D_GNU_SOURCE)
180+
check_symbol_exists(dladdr dlfcn.h CLANG_HAVE_DLADDR)
181+
list(REMOVE_ITEM CMAKE_REQUIRED_DEFINITIONS -D_GNU_SOURCE)
182+
if( HAVE_LIBDL )
183+
list(REMOVE_ITEM CMAKE_REQUIRED_LIBRARIES dl)
184+
endif()
185+
endif()
186+
170187
set(CLANG_RESOURCE_DIR "" CACHE STRING
171188
"Relative directory from the Clang binary to its resource files.")
172189

clang/include/clang/Config/config.h.cmake

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,12 @@
5757
/* Define if we have sys/resource.h (rlimits) */
5858
#cmakedefine CLANG_HAVE_RLIMITS ${CLANG_HAVE_RLIMITS}
5959

60+
/* Define if we have dlfcn.h */
61+
#cmakedefine CLANG_HAVE_DLFCN_H ${CLANG_HAVE_DLFCN_H}
62+
63+
/* Define if dladdr() is available on this platform. */
64+
#cmakedefine CLANG_HAVE_DLADDR ${CLANG_HAVE_DLADDR}
65+
6066
/* Linker version detected at compile time. */
6167
#cmakedefine HOST_LINK_VERSION "${HOST_LINK_VERSION}"
6268

clang/tools/libclang/CIndexer.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414
#include "CXString.h"
1515
#include "clang/Basic/LLVM.h"
1616
#include "clang/Basic/Version.h"
17+
#include "clang/Config/config.h"
1718
#include "clang/Driver/Driver.h"
1819
#include "llvm/ADT/STLExtras.h"
1920
#include "llvm/ADT/SmallString.h"
20-
#include "llvm/Config/llvm-config.h"
2121
#include "llvm/Support/FileSystem.h"
2222
#include "llvm/Support/MD5.h"
2323
#include "llvm/Support/Path.h"
@@ -127,7 +127,7 @@ const std::string &CIndexer::getClangResourcesPath() {
127127
getClangResourcesPathImplAIX(LibClangPath);
128128
#else
129129
bool PathFound = false;
130-
#if defined(HAVE_DLFCN_H) && defined(HAVE_DLADDR)
130+
#if defined(CLANG_HAVE_DLFCN_H) && defined(CLANG_HAVE_DLADDR)
131131
Dl_info info;
132132
// This silly cast below avoids a C++ warning.
133133
if (dladdr((void *)(uintptr_t)clang_createTranslationUnit, &info) != 0) {

llvm/include/llvm/Config/config.h.cmake

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,15 @@
5050
don't. */
5151
#cmakedefine01 HAVE_DECL_STRERROR_S
5252

53+
/* Define to 1 if you have the <dlfcn.h> header file. */
54+
#cmakedefine HAVE_DLFCN_H ${HAVE_DLFCN_H}
55+
5356
/* Define if dlopen() is available on this platform. */
5457
#cmakedefine HAVE_DLOPEN ${HAVE_DLOPEN}
5558

59+
/* Define if dladdr() is available on this platform. */
60+
#cmakedefine HAVE_DLADDR ${HAVE_DLADDR}
61+
5662
/* Define to 1 if we can register EH frames on this platform. */
5763
#cmakedefine HAVE_REGISTER_FRAME ${HAVE_REGISTER_FRAME}
5864

llvm/include/llvm/Config/llvm-config.h.cmake

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -198,10 +198,4 @@
198198
/* Define if plugins enabled */
199199
#cmakedefine LLVM_ENABLE_PLUGINS
200200

201-
/* Define to 1 if you have the <dlfcn.h> header file. */
202-
#cmakedefine HAVE_DLFCN_H ${HAVE_DLFCN_H}
203-
204-
/* Define if dladdr() is available on this platform. */
205-
#cmakedefine HAVE_DLADDR ${HAVE_DLADDR}
206-
207201
#endif

0 commit comments

Comments
 (0)