0

I am currently doing a project using cling to compile a file. However, I have a segmentation fault when building the project.
LLVM seems to be the cause.

I've tried including Cling and LLVM using Cmake. For Cling, it seems to work, but LLVM segfaults on app startup. I've included LLVM as said on the documentation but had no luck :/
I saw this post on github saying to replace the ${llvm_libs} by LLVM
Then, it finally compiled but segfaults on app startup.

Here is valgrind's output:

==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)

And here is the minimal Cmake for Cling & LLVM inclusion we use:

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)

it seems to fail before the main function is reached. We are not even including any header file for cling or LLVM at this point but it fails nevertheless. Is this a known bug of LLVM or am I missing something?

Stephane Rolland
  • 38,876
  • 35
  • 121
  • 169
Narice
  • 311
  • 3
  • 6

0 Answers0