CxxWrap.jl icon indicating copy to clipboard operation
CxxWrap.jl copied to clipboard

hello world causes hard crash on Ubuntu 22.04

Open Clemapfel opened this issue 2 years ago • 9 comments
trafficstars

Hi, the following MWE project crashes on my and one of my users Ubuntu 22.04 machines:

CMakeLists.txt

cmake_minimum_required(VERSION 3.18)

project(cxxwrap_test LANGUAGES CXX)
set(LIBRARY_NAME cxxwrap_test)
find_package(JlCxx REQUIRED)

add_library(${LIBRARY_NAME} SHARED
    cxxwrap_test.hpp
    cxxwrap_test.cpp
)

target_link_libraries(${LIBRARY_NAME} PUBLIC JlCxx::cxxwrap_julia)
target_include_directories(${LIBRARY_NAME} PUBLIC "${Julia_INCLUDE_DIRS}")
target_compile_features(${LIBRARY_NAME} PUBLIC cxx_std_17)
set_target_properties(${LIBRARY_NAME} PROPERTIES LINKER_LANGUAGE CXX)

cxxwrap_test.hpp

#pragma once
#include <jlcxx/jlcxx.hpp>

struct Test {};
template<> struct jlcxx::IsMirroredType<Test> : std::false_type {};
JLCXX_MODULE define_julia_module(jlcxx::Module& module);

cxxwrap_test.cpp

#include "./cxxwrap_test.hpp"

JLCXX_MODULE define_julia_module(jlcxx::Module& module)
{
    auto test = module.add_type<Test>("Test", jl_any_type)
        .constructor<Test>()
    ;
}

Compilation

clem@ubuntu:~/Workspace/cxxwrap_test/build$ cmake ..
-- The CXX compiler identification is GNU 11.4.0
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found Julia executable: /home/clem/Applications/julia-1.9.3/bin/julia
-- Julia_VERSION_STRING: 1.9.3
-- Julia_INCLUDE_DIRS:   /home/clem/Applications/julia-1.9.3/include/julia
-- Julia_LIBRARY_DIR:    /home/clem/Applications/julia-1.9.3/lib
-- Julia_LIBRARY:        /home/clem/Applications/julia-1.9.3/lib/libjulia.so.1
-- JULIA_HOME:           /home/clem/Applications/julia-1.9.3/bin
-- Julia_LLVM_VERSION:   v14.0.6
-- Julia_WORD_SIZE:      64
-- Found Julia: /home/clem/Applications/julia-1.9.3/lib/libjulia.so.1 (found version "1.9.3") 
-- Configuring done
-- Generating done
-- Build files have been written to: /home/clem/Workspace/cxxwrap_test/build
clem@ubuntu:~/Workspace/cxxwrap_test/build$ make
[ 50%] Building CXX object CMakeFiles/cxxwrap_test.dir/cxxwrap_test.cpp.o
[100%] Linking CXX shared library libcxxwrap_test.so
[100%] Built target cxxwrap_test

Julia

module test
    using CxxWrap
    #function __init__() @initcxx end
    @wrapmodule("/home/clem/Workspace/cxxwrap_test/build/libcxxwrap_test.so")
end

(I commented out __init__ as the behavior is the same both with and without that line)

Causes the following stacktrace:

[13520] signal (11.128): Segmentation fault
in expression starting at REPL[1]:4
_ZNKSt9type_info6beforeERKS_ at /home/clem/Workspace/cxxwrap_test/build/libcxxwrap_test.so (unknown line)
_ZNKSt10type_indexltERKS_ at /home/clem/Workspace/cxxwrap_test/build/libcxxwrap_test.so (unknown line)
_ZStltISt10type_indexmEbRKSt4pairIT_T0_ES6_ at /home/clem/Workspace/cxxwrap_test/build/libcxxwrap_test.so (unknown line)
_ZNKSt4lessISt4pairISt10type_indexmEEclERKS2_S5_ at /home/clem/Workspace/cxxwrap_test/build/libcxxwrap_test.so (unknown line)
_ZNSt8_Rb_treeISt4pairISt10type_indexmES0_IKS2_N5jlcxx14CachedDatatypeEESt10_Select1stIS6_ESt4lessIS2_ESaIS6_EE24_M_get_insert_unique_posERS3_ at /home/clem/Workspace/cxxwrap_test/build/libcxxwrap_test.so (unknown line)
_ZNSt8_Rb_treeISt4pairISt10type_indexmES0_IKS2_N5jlcxx14CachedDatatypeEESt10_Select1stIS6_ESt4lessIS2_ESaIS6_EE17_M_emplace_uniqueIJS0_IS2_S5_EEEES0_ISt17_Rb_tree_iteratorIS6_EbEDpOT_ at /home/clem/Workspace/cxxwrap_test/build/libcxxwrap_test.so (unknown line)
_ZNSt3mapISt4pairISt10type_indexmEN5jlcxx14CachedDatatypeESt4lessIS2_ESaIS0_IKS2_S4_EEE6insertIS0_IS2_S4_EEENSt9enable_ifIXsrSt16is_constructibleIS8_JT_EE5valueES0_ISt17_Rb_tree_iteratorIS8_EbEE4typeEOSF_ at /home/clem/Workspace/cxxwrap_test/build/libcxxwrap_test.so (unknown line)
_ZN5jlcxx14JuliaTypeCacheI4TestE14set_julia_typeEP14_jl_datatype_tb at /home/clem/Workspace/cxxwrap_test/build/libcxxwrap_test.so (unknown line)
_ZN5jlcxx14set_julia_typeI4TestEEvP14_jl_datatype_tb at /home/clem/Workspace/cxxwrap_test/build/libcxxwrap_test.so (unknown line)
_ZN5jlcxx6Module17add_type_internalI4TestNS_13ParameterListIJEEE14_jl_datatype_tEENS_11TypeWrapperIT_EERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEPT1_ at /home/clem/Workspace/cxxwrap_test/build/libcxxwrap_test.so (unknown line)
_ZN5jlcxx6Module8add_typeI4TestNS_13ParameterListIJEEE14_jl_datatype_tEENS_11TypeWrapperIT_EERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEPT1_ at /home/clem/Workspace/cxxwrap_test/build/libcxxwrap_test.so (unknown line)
define_julia_module at /home/clem/Workspace/cxxwrap_test/build/libcxxwrap_test.so (unknown line)
register_julia_module at /home/clem/.julia/artifacts/88a033de19250acca6784647964d43d7121a06aa/lib/libcxxwrap_julia.so (unknown line)
register_julia_module at /home/clem/.julia/packages/CxxWrap/aXNBY/src/CxxWrap.jl:393 [inlined]
readmodule at /home/clem/.julia/packages/CxxWrap/aXNBY/src/CxxWrap.jl:742
wrapmodule at /home/clem/.julia/packages/CxxWrap/aXNBY/src/CxxWrap.jl:747
_jl_invoke at /cache/build/default-amdci5-5/julialang/julia-release-1-dot-9/src/gf.c:2758 [inlined]
ijl_apply_generic at /cache/build/default-amdci5-5/julialang/julia-release-1-dot-9/src/gf.c:2940
jl_apply at /cache/build/default-amdci5-5/julialang/julia-release-1-dot-9/src/julia.h:1880 [inlined]
do_call at /cache/build/default-amdci5-5/julialang/julia-release-1-dot-9/src/interpreter.c:126
eval_value at /cache/build/default-amdci5-5/julialang/julia-release-1-dot-9/src/interpreter.c:226
eval_stmt_value at /cache/build/default-amdci5-5/julialang/julia-release-1-dot-9/src/interpreter.c:177 [inlined]
eval_body at /cache/build/default-amdci5-5/julialang/julia-release-1-dot-9/src/interpreter.c:624
jl_interpret_toplevel_thunk at /cache/build/default-amdci5-5/julialang/julia-release-1-dot-9/src/interpreter.c:762
jl_toplevel_eval_flex at /cache/build/default-amdci5-5/julialang/julia-release-1-dot-9/src/toplevel.c:912
jl_eval_module_expr at /cache/build/default-amdci5-5/julialang/julia-release-1-dot-9/src/toplevel.c:203 [inlined]
jl_toplevel_eval_flex at /cache/build/default-amdci5-5/julialang/julia-release-1-dot-9/src/toplevel.c:715
jl_toplevel_eval_flex at /cache/build/default-amdci5-5/julialang/julia-release-1-dot-9/src/toplevel.c:856
ijl_toplevel_eval_in at /cache/build/default-amdci5-5/julialang/julia-release-1-dot-9/src/toplevel.c:971
eval at ./boot.jl:370 [inlined]
eval_user_input at /cache/build/default-amdci5-5/julialang/julia-release-1-dot-9/usr/share/julia/stdlib/v1.9/REPL/src/REPL.jl:153
repl_backend_loop at /cache/build/default-amdci5-5/julialang/julia-release-1-dot-9/usr/share/julia/stdlib/v1.9/REPL/src/REPL.jl:249
#start_repl_backend#46 at /cache/build/default-amdci5-5/julialang/julia-release-1-dot-9/usr/share/julia/stdlib/v1.9/REPL/src/REPL.jl:234
start_repl_backend at /cache/build/default-amdci5-5/julialang/julia-release-1-dot-9/usr/share/julia/stdlib/v1.9/REPL/src/REPL.jl:231
_jl_invoke at /cache/build/default-amdci5-5/julialang/julia-release-1-dot-9/src/gf.c:2758 [inlined]
ijl_apply_generic at /cache/build/default-amdci5-5/julialang/julia-release-1-dot-9/src/gf.c:2940
#run_repl#59 at /cache/build/default-amdci5-5/julialang/julia-release-1-dot-9/usr/share/julia/stdlib/v1.9/REPL/src/REPL.jl:379
run_repl at /cache/build/default-amdci5-5/julialang/julia-release-1-dot-9/usr/share/julia/stdlib/v1.9/REPL/src/REPL.jl:365
jfptr_run_repl_60908 at /home/clem/Applications/julia-1.9.3/lib/julia/sys.so (unknown line)
_jl_invoke at /cache/build/default-amdci5-5/julialang/julia-release-1-dot-9/src/gf.c:2758 [inlined]
ijl_apply_generic at /cache/build/default-amdci5-5/julialang/julia-release-1-dot-9/src/gf.c:2940
#1017 at ./client.jl:421
jfptr_YY.1017_36106 at /home/clem/Applications/julia-1.9.3/lib/julia/sys.so (unknown line)
_jl_invoke at /cache/build/default-amdci5-5/julialang/julia-release-1-dot-9/src/gf.c:2758 [inlined]
ijl_apply_generic at /cache/build/default-amdci5-5/julialang/julia-release-1-dot-9/src/gf.c:2940
jl_apply at /cache/build/default-amdci5-5/julialang/julia-release-1-dot-9/src/julia.h:1880 [inlined]
jl_f__call_latest at /cache/build/default-amdci5-5/julialang/julia-release-1-dot-9/src/builtins.c:774
#invokelatest#2 at ./essentials.jl:819 [inlined]
invokelatest at ./essentials.jl:816 [inlined]
run_main_repl at ./client.jl:405
exec_options at ./client.jl:322
_start at ./client.jl:522
jfptr__start_40034 at /home/clem/Applications/julia-1.9.3/lib/julia/sys.so (unknown line)
_jl_invoke at /cache/build/default-amdci5-5/julialang/julia-release-1-dot-9/src/gf.c:2758 [inlined]
ijl_apply_generic at /cache/build/default-amdci5-5/julialang/julia-release-1-dot-9/src/gf.c:2940
jl_apply at /cache/build/default-amdci5-5/julialang/julia-release-1-dot-9/src/julia.h:1880 [inlined]
true_main at /cache/build/default-amdci5-5/julialang/julia-release-1-dot-9/src/jlapi.c:573
jl_repl_entrypoint at /cache/build/default-amdci5-5/julialang/julia-release-1-dot-9/src/jlapi.c:717
main at julia (unknown line)
unknown function (ip: 0x7fd057229d8f)
__libc_start_main at /lib/x86_64-linux-gnu/libc.so.6 (unknown line)
unknown function (ip: 0x4010b8)
Allocations: 2998 (Pool: 2985; Big: 13); GC: 0
Segmentation fault (core dumped)

OS Info

clem@ubuntu:~/Workspace/mousetrap_julia_binding/build$ lsb_release -a
No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 22.04.3 LTS
Release:	22.04
Codename:	jammy

I have been unable to reproduce this on fedora or newer ubuntu versions. I played with the cxxwrap_cpp definition and it seems only add_type causes the crash, other functions like set_const work fine. It happens for both mirror and non-mirrored types.


Just to make sure I did a fresh install on the current master of libcxxwrap and the issue persisted. Installation output:

clem@ubuntu:~/Desktop$ git clone https://github.com/JuliaInterop/libcxxwrap-julia
Cloning into 'libcxxwrap-julia'...
remote: Enumerating objects: 1778, done.
remote: Counting objects: 100% (327/327), done.
remote: Compressing objects: 100% (148/148), done.
remote: Total 1778 (delta 170), reused 246 (delta 140), pack-reused 1451
Receiving objects: 100% (1778/1778), 383.09 KiB | 3.68 MiB/s, done.
Resolving deltas: 100% (1117/1117), done.
clem@ubuntu:~/Desktop$ cd libcxxwrap-julia/
clem@ubuntu:~/Desktop/libcxxwrap-julia$ mkdir build; cd build
clem@ubuntu:~/Desktop/libcxxwrap-julia/build$ cmake ..
-- The C compiler identification is GNU 11.4.0
-- The CXX compiler identification is GNU 11.4.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found Julia executable: /home/clem/Applications/julia-1.9.3/bin/julia
-- Julia_VERSION_STRING: 1.9.3
-- Julia_INCLUDE_DIRS:   /home/clem/Applications/julia-1.9.3/include/julia
-- Julia_LIBRARY_DIR:    /home/clem/Applications/julia-1.9.3/lib
-- Julia_LIBRARY:        /home/clem/Applications/julia-1.9.3/lib/libjulia.so.1
-- JULIA_HOME:           /home/clem/Applications/julia-1.9.3/bin
-- Julia_LLVM_VERSION:   v14.0.6
-- Julia_WORD_SIZE:      64
-- Found Julia: /home/clem/Applications/julia-1.9.3/lib/libjulia.so.1 (found version "1.9.3") 
-- JlCxx version: v0.10.0
-- Performing Test COMPILER_HAS_HIDDEN_VISIBILITY
-- Performing Test COMPILER_HAS_HIDDEN_VISIBILITY - Success
-- Performing Test COMPILER_HAS_HIDDEN_INLINE_VISIBILITY
-- Performing Test COMPILER_HAS_HIDDEN_INLINE_VISIBILITY - Success
-- Performing Test COMPILER_HAS_DEPRECATED_ATTR
-- Performing Test COMPILER_HAS_DEPRECATED_ATTR - Success
-- Configuring done
-- Generating done
-- Build files have been written to: /home/clem/Desktop/libcxxwrap-julia/build
clem@ubuntu:~/Desktop$ sudo make install -j 4
(...)

Thank you

Clemapfel avatar Sep 01 '23 17:09 Clemapfel

I am very much interested in getting this fixed. @barche Any idea how to debug this issue further?

ufechner7 avatar Sep 02 '23 11:09 ufechner7

@Clemapfel I am not able to reproduce the issue. I fail to compile the cpp program. I am having the output:

ufechner@ufryzen:~/repos/CxxWrap/build$ cmake ..
CMake Error at CMakeLists.txt:5 (find_package):
  By not providing "FindJlCxx.cmake" in CMAKE_MODULE_PATH this project has
  asked CMake to find a package configuration file provided by "JlCxx", but
  CMake did not find one.

  Could not find a package configuration file provided by "JlCxx" with any of
  the following names:

    JlCxxConfig.cmake
    jlcxx-config.cmake

  Add the installation prefix of "JlCxx" to CMAKE_PREFIX_PATH or set
  "JlCxx_DIR" to a directory containing one of the above files.  If "JlCxx"
  provides a separate development package or SDK, be sure it has been
  installed.


-- Configuring incomplete, errors occurred!
See also "/home/ufechner/repos/CxxWrap/build/CMakeFiles/CMakeOutput.log".

Any idea?

ufechner7 avatar Sep 02 '23 18:09 ufechner7

Ok, I could compile the code by using the following build script:

cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_PREFIX_PATH=/home/ufechner/.julia/artifacts/88a033de19250acca6784647964d43d7121a06aa ..
cmake --build . --config Release

I obtained the prefix path from the command:

ufechner@ufryzen:~/repos/CxxWrap$ julia --project
               _
   _       _ _(_)_     |  Documentation: https://docs.julialang.org
  (_)     | (_) (_)    |
   _ _   _| |_  __ _   |  Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 1.9.3 (2023-08-24)
 _/ |\__'_|_|_|\__'_|  |  Official https://julialang.org/ release
|__/                   |

julia> using CxxWrap

julia> CxxWrap.prefix_path()
"/home/ufechner/.julia/artifacts/88a033de19250acca6784647964d43d7121a06aa"

after creating a Julia project that contains only CxxWrap:

(CxxWrap) pkg> st
Status `~/repos/CxxWrap/Project.toml`
  [1f15a43c] CxxWrap v0.13.4

I am using:

cmake version 3.22.1
gcc (Ubuntu 12.3.0-1ubuntu1~22.04) 12.3.0

Output of the build script:

ufechner@ufryzen:~/repos/CxxWrap/build$ ./build.sh 
-- The CXX compiler identification is GNU 12.3.0
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found Julia executable: /home/ufechner/.local/bin/julia
-- Julia_VERSION_STRING: 1.9.3
-- Julia_INCLUDE_DIRS:   /home/ufechner/packages/julias/julia-1.9/include/julia
-- Julia_LIBRARY_DIR:    /home/ufechner/packages/julias/julia-1.9/lib
-- Julia_LIBRARY:        /home/ufechner/packages/julias/julia-1.9/lib/libjulia.so.1
-- JULIA_HOME:           /home/ufechner/packages/julias/julia-1.9/bin
-- Julia_LLVM_VERSION:   v14.0.6
-- Julia_WORD_SIZE:      64
-- Found Julia: /home/ufechner/packages/julias/julia-1.9/lib/libjulia.so.1 (found version "1.9.3") 
-- Configuring done
-- Generating done
-- Build files have been written to: /home/ufechner/repos/CxxWrap/build
[ 50%] Building CXX object CMakeFiles/cxxwrap_test.dir/cxxwrap_test.cpp.o
[100%] Linking CXX shared library libcxxwrap_test.so
[100%] Built target cxxwrap_test

Julia script test.jl

ufechner@ufryzen:~/repos/CxxWrap$ cat test.jl
module test
    using CxxWrap
    #function __init__() @initcxx end
    @wrapmodule("/home/ufechner/repos/CxxWrap/build/libcxxwrap_test.so")
end

Running the julia script works fine:

julia> include("test.jl")
Main.test

In other words, I cannot reproduce the issue.

ufechner7 avatar Sep 02 '23 19:09 ufechner7

@Clemapfel Can you please share the output of:

cmake --version
gcc --version

and the output of

using Pkg
Pkg.status()

We need to find out why it fails for you and works for me...

ufechner7 avatar Sep 02 '23 19:09 ufechner7

This might be related: https://github.com/JuliaInterop/libcxxwrap-julia/pull/132

ufechner7 avatar Sep 03 '23 07:09 ufechner7

I recommend trying this again with the just-released libcxxwrap-julia 0.11 and CxxWrap 0.14.

barche avatar Sep 03 '23 21:09 barche

Reinstalling CxxWrap.jl and libcxxwrap.so from their respective github main branch fixed the issue for me.

I'll keep this open until CxxWrap.jl and libcxxwrap_julia_jll are upgraded and I can confirm this works for the installed-from-registry versions, but the just-released update does seem to work! Thank you.

Clemapfel avatar Sep 05 '23 15:09 Clemapfel

Unless I am missing something, I have both (from the manifest):

[[deps.libcxxwrap_julia_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl"]
git-tree-sha1 = "15292484f628f2daaf77f7919f5df3d1719c86ca"
uuid = "3eaa8342-bff7-56a5-9981-c04077f7cee7"
version = "0.11.0+0"

and

[[deps.CxxWrap]]
deps = ["Libdl", "MacroTools", "libcxxwrap_julia_jll"]
git-tree-sha1 = "67ebbc028b385658142d3c0644e07992616653d9"
uuid = "1f15a43c-97ca-5a2a-ae31-89f07a497df4"
version = "0.14.0"

and am seeing this issue.

andrew-at-rotor avatar Sep 05 '23 18:09 andrew-at-rotor

Note that you can't mix binaries from the Julia artifacts registry with code you compile yourself, maybe that is the issue? On Arch Linux I even have to compile Julia itself, along with libcxxwrap-julia and then the wrappers to make sure everything links correctly.

barche avatar Sep 05 '23 19:09 barche