0

我目前正在做一个项目,使用 cling 来编译文件。但是,我在构建项目时遇到了分段错误。
LLVM 似乎是原因。

我尝试过使用 Cmake 包含 Cling 和 LLVM。对于 Cling,它似乎可以工作,但 LLVM 在应用程序启动时会出现段错误。我已经按照文档中的说明包含了 LLVM,但没有运气:/我在 github 上
看到这篇文章
说要用 LLVM 替换 ${llvm_libs} 然后,它终于编译了,但在应用程序启动时出现了段错误。

这是 valgrind 的输出:

==4497== Conditional jump or move depends on uninitialised value(s)
==4497==    at 0x483872C: malloc (vg_replace_malloc.c:299)
==4497==    by 0x659DB25: llvm::SmallVectorBase::grow_pod(void*, unsigned long, unsigned long) (in /opt/cling/lib/libcling.so.5.0.0)
==4497==    by 0x842D39F: ??? (in /usr/lib/libLLVM-8.so)
==4497==    by 0x40106A9: call_init.part.0 (in /usr/lib/ld-2.29.so)
==4497==    by 0x40107A9: _dl_init (in /usr/lib/ld-2.29.so)
==4497==    by 0x4002039: ??? (in /usr/lib/ld-2.29.so)
==4497== 
==4497== Argument 'size' of function malloc has a fishy (possibly negative) value: -274844350770
==4497==    at 0x483877F: malloc (vg_replace_malloc.c:299)
==4497==    by 0x659DB25: llvm::SmallVectorBase::grow_pod(void*, unsigned long, unsigned long) (in /opt/cling/lib/libcling.so.5.0.0)
==4497==    by 0x842D39F: ??? (in /usr/lib/libLLVM-8.so)
==4497==    by 0x40106A9: call_init.part.0 (in /usr/lib/ld-2.29.so)
==4497==    by 0x40107A9: _dl_init (in /usr/lib/ld-2.29.so)
==4497==    by 0x4002039: ??? (in /usr/lib/ld-2.29.so)
==4497== 
==4497== Invalid write of size 8
==4497==    at 0x483F92B: memmove (vg_replace_strmem.c:1270)
==4497==    by 0x659DB36: llvm::SmallVectorBase::grow_pod(void*, unsigned long, unsigned long) (in /opt/cling/lib/libcling.so.5.0.0)
==4497==    by 0x842D39F: ??? (in /usr/lib/libLLVM-8.so)
==4497==    by 0x40106A9: call_init.part.0 (in /usr/lib/ld-2.29.so)
==4497==    by 0x40107A9: _dl_init (in /usr/lib/ld-2.29.so)
==4497==    by 0x4002039: ??? (in /usr/lib/ld-2.29.so)
==4497==  Address 0x0 is not stack'd, malloc'd or (recently) free'd
==4497== 
==4497== 
==4497== Process terminating with default action of signal 11 (SIGSEGV): dumping core
==4497==  Access not within mapped region at address 0x0
==4497==    at 0x483F92B: memmove (vg_replace_strmem.c:1270)
==4497==    by 0x659DB36: llvm::SmallVectorBase::grow_pod(void*, unsigned long, unsigned long) (in /opt/cling/lib/libcling.so.5.0.0)
==4497==    by 0x842D39F: ??? (in /usr/lib/libLLVM-8.so)
==4497==    by 0x40106A9: call_init.part.0 (in /usr/lib/ld-2.29.so)
==4497==    by 0x40107A9: _dl_init (in /usr/lib/ld-2.29.so)
==4497==    by 0x4002039: ??? (in /usr/lib/ld-2.29.so)

这是我们使用的用于 Cling 和 LLVM 包含的最小 Cmake:

set(OPT "-Wall -Werror -std=c++17 -g -DLLVMDIR='\"/usr/include/llvm/\"'")

find_package(Cling REQUIRED)
find_package(LLVM REQUIRED CONFIG)
message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}")
message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}")
message("LLVM_INCLUDE_DIRS=${LLVM_INCLUDE_DIRS}")
message("LLVM_DEFINITIONS=${LLVM_DEFINITIONS}")

target_include_directories(${OUTPUT} ${CLING_INCLUDE_DIRS})

include_directories(${LLVM_INCLUDE_DIRS})
add_definitions(${LLVM_DEFINITIONS})

# Find the libraries that correspond to the LLVM components
# that we wish to use
llvm_map_components_to_libnames(llvm_libs support core irreader)

target_link_libraries(${OUTPUT} ${CLING_LIBRARIES} LLVM stdc++fs)

在达到主要功能之前似乎失败了。在这一点上,我们甚至没有包含任何用于 cling 或 LLVM 的头文件,但它仍然失败了。这是 LLVM 的已知错误还是我遗漏了什么?

4

0 回答 0