<p dir="auto">I have a consistent segfault in <code class="notranslate">Nettle.jl</code> on <code class="notranslate">master</code>.  This happens on all three platforms.</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="in expression starting at /Users/travis/.julia/v0.7/Nettle/test/hash_tests.jl:4
jl_typemap_level_assoc_exact at /Users/osx/buildbot/slave/package_osx64/build/src/typemap.c:813
jl_typemap_assoc_exact at /Users/osx/buildbot/slave/package_osx64/build/src/./julia_internal.h:876 [inlined]
jl_lookup_generic_ at /Users/osx/buildbot/slave/package_osx64/build/src/gf.c:2112
jl_apply_generic at /Users/osx/buildbot/slave/package_osx64/build/src/gf.c:2164
Type at /Users/travis/.julia/v0.7/Nettle/src/hash.jl:23
digest at /Users/travis/.julia/v0.7/Nettle/src/hash.jl:44
jl_fptr_trampoline at /Users/osx/buildbot/slave/package_osx64/build/src/gf.c:1838
top-level scope at ./&lt;missing&gt;:40
jl_fptr_trampoline at /Users/osx/buildbot/slave/package_osx64/build/src/gf.c:1838
jl_toplevel_eval_flex at /Users/osx/buildbot/slave/package_osx64/build/src/toplevel.c:811
jl_parse_eval_all at /Users/osx/buildbot/slave/package_osx64/build/src/ast.c:847
jl_load at /Users/osx/buildbot/slave/package_osx64/build/src/toplevel.c:854 [inlined]
jl_load_ at /Users/osx/buildbot/slave/package_osx64/build/src/toplevel.c:861
include at ./boot.jl:306 [inlined]
include_relative at ./loading.jl:1067
include at ./sysimg.jl:29
include at ./sysimg.jl:68
jl_fptr_trampoline at /Users/osx/buildbot/slave/package_osx64/build/src/gf.c:1838
do_call at /Users/osx/buildbot/slave/package_osx64/build/src/interpreter.c:324
eval_body at /Users/osx/buildbot/slave/package_osx64/build/src/interpreter.c:661
jl_interpret_toplevel_thunk_callback at /Users/osx/buildbot/slave/package_osx64/build/src/interpreter.c:759
unknown function (ip: 0xfffffffffffffffe)
unknown function (ip: 0x11578354f)
unknown function (ip: 0xffffffffffffffff)
jl_interpret_toplevel_thunk at /Users/osx/buildbot/slave/package_osx64/build/src/interpreter.c:768
jl_toplevel_eval_flex at /Users/osx/buildbot/slave/package_osx64/build/src/toplevel.c:816
jl_parse_eval_all at /Users/osx/buildbot/slave/package_osx64/build/src/ast.c:847
jl_load at /Users/osx/buildbot/slave/package_osx64/build/src/toplevel.c:854 [inlined]
jl_load_ at /Users/osx/buildbot/slave/package_osx64/build/src/toplevel.c:861
include at ./boot.jl:306 [inlined]
include_relative at ./loading.jl:1067
include at ./sysimg.jl:29
exec_options at ./client.jl:327
_start at ./client.jl:455
true_main at /Users/travis/julia/bin/julia (unknown line)"><pre class="notranslate"><code class="notranslate">in expression starting at /Users/travis/.julia/v0.7/Nettle/test/hash_tests.jl:4
jl_typemap_level_assoc_exact at /Users/osx/buildbot/slave/package_osx64/build/src/typemap.c:813
jl_typemap_assoc_exact at /Users/osx/buildbot/slave/package_osx64/build/src/./julia_internal.h:876 [inlined]
jl_lookup_generic_ at /Users/osx/buildbot/slave/package_osx64/build/src/gf.c:2112
jl_apply_generic at /Users/osx/buildbot/slave/package_osx64/build/src/gf.c:2164
Type at /Users/travis/.julia/v0.7/Nettle/src/hash.jl:23
digest at /Users/travis/.julia/v0.7/Nettle/src/hash.jl:44
jl_fptr_trampoline at /Users/osx/buildbot/slave/package_osx64/build/src/gf.c:1838
top-level scope at ./&lt;missing&gt;:40
jl_fptr_trampoline at /Users/osx/buildbot/slave/package_osx64/build/src/gf.c:1838
jl_toplevel_eval_flex at /Users/osx/buildbot/slave/package_osx64/build/src/toplevel.c:811
jl_parse_eval_all at /Users/osx/buildbot/slave/package_osx64/build/src/ast.c:847
jl_load at /Users/osx/buildbot/slave/package_osx64/build/src/toplevel.c:854 [inlined]
jl_load_ at /Users/osx/buildbot/slave/package_osx64/build/src/toplevel.c:861
include at ./boot.jl:306 [inlined]
include_relative at ./loading.jl:1067
include at ./sysimg.jl:29
include at ./sysimg.jl:68
jl_fptr_trampoline at /Users/osx/buildbot/slave/package_osx64/build/src/gf.c:1838
do_call at /Users/osx/buildbot/slave/package_osx64/build/src/interpreter.c:324
eval_body at /Users/osx/buildbot/slave/package_osx64/build/src/interpreter.c:661
jl_interpret_toplevel_thunk_callback at /Users/osx/buildbot/slave/package_osx64/build/src/interpreter.c:759
unknown function (ip: 0xfffffffffffffffe)
unknown function (ip: 0x11578354f)
unknown function (ip: 0xffffffffffffffff)
jl_interpret_toplevel_thunk at /Users/osx/buildbot/slave/package_osx64/build/src/interpreter.c:768
jl_toplevel_eval_flex at /Users/osx/buildbot/slave/package_osx64/build/src/toplevel.c:816
jl_parse_eval_all at /Users/osx/buildbot/slave/package_osx64/build/src/ast.c:847
jl_load at /Users/osx/buildbot/slave/package_osx64/build/src/toplevel.c:854 [inlined]
jl_load_ at /Users/osx/buildbot/slave/package_osx64/build/src/toplevel.c:861
include at ./boot.jl:306 [inlined]
include_relative at ./loading.jl:1067
include at ./sysimg.jl:29
exec_options at ./client.jl:327
_start at ./client.jl:455
true_main at /Users/travis/julia/bin/julia (unknown line)
</code></pre></div>
<p dir="auto">The lowest "user code" stack frame seems to be <a href="https://github.com/staticfloat/Nettle.jl/blob/d4bac3dde14eaf05f0223f4c9c36e8a29035cad2/src/hash.jl#L23"><code class="notranslate">hash.jl:23</code></a>, which is:</p>
<div class="highlight highlight-source-julia notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="ccall(hash_type.init, Void, (Ptr{Void},), state)"><pre class="notranslate"><span class="pl-c1">ccall</span>(hash_type<span class="pl-k">.</span>init, Void, (Ptr{Void},), state)</pre></div>
<p dir="auto">In the following example I get a segfault at the <code class="notranslate">ccall</code>, but only if this line is inside the <code class="notranslate">Container</code> constructor. If this call is done in an own function there is no segfault.</p>
<p dir="auto">[I used <code class="notranslate">malloc</code> in <code class="notranslate">libc</code> only as an example. This segfault happens for other C-functions, too.]</p>
<p dir="auto">Minimal example:</p>
<div class="highlight highlight-source-julia notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="lib = Libdl.dlopen(&quot;libc&quot;)

mutable struct Container
  ptr           :: Ptr{Cvoid}
  method_ptr    :: Ptr{Cvoid}
end

function call_with_func(container::Container)
  container.ptr = ccall(container.method_ptr, Ptr{Cvoid}, (Csize_t,), 1024 )
  return nothing
end

function Container()
  container = Container(C_NULL, Libdl.dlsym(lib, :malloc))
  # this works
  #    call_with_func(container) 
  # but the same code here (without own function) produces a segfault
  container.ptr = ccall(container.method_ptr, Ptr{Cvoid}, (Csize_t,), 1024 )
  return container
end

c = Container()
println(&quot;got pointer: &quot;, c.ptr)"><pre class="notranslate">lib <span class="pl-k">=</span> Libdl<span class="pl-k">.</span><span class="pl-c1">dlopen</span>(<span class="pl-s"><span class="pl-pds">"</span>libc<span class="pl-pds">"</span></span>)

<span class="pl-k">mutable struct</span> Container
  ptr           <span class="pl-k">::</span> <span class="pl-c1">Ptr{Cvoid}</span>
  method_ptr    <span class="pl-k">::</span> <span class="pl-c1">Ptr{Cvoid}</span>
<span class="pl-k">end</span>

<span class="pl-k">function</span> <span class="pl-en">call_with_func</span>(container<span class="pl-k">::</span><span class="pl-c1">Container</span>)
  container<span class="pl-k">.</span>ptr <span class="pl-k">=</span> <span class="pl-c1">ccall</span>(container<span class="pl-k">.</span>method_ptr, Ptr{Cvoid}, (Csize_t,), <span class="pl-c1">1024</span> )
  <span class="pl-k">return</span> <span class="pl-c1">nothing</span>
<span class="pl-k">end</span>

<span class="pl-k">function</span> <span class="pl-en">Container</span>()
  container <span class="pl-k">=</span> <span class="pl-c1">Container</span>(<span class="pl-c1">C_NULL</span>, Libdl<span class="pl-k">.</span><span class="pl-c1">dlsym</span>(lib, <span class="pl-c1">:malloc</span>))
  <span class="pl-c"><span class="pl-c">#</span> this works</span>
  <span class="pl-c"><span class="pl-c">#</span>    call_with_func(container) </span>
  <span class="pl-c"><span class="pl-c">#</span> but the same code here (without own function) produces a segfault</span>
  container<span class="pl-k">.</span>ptr <span class="pl-k">=</span> <span class="pl-c1">ccall</span>(container<span class="pl-k">.</span>method_ptr, Ptr{Cvoid}, (Csize_t,), <span class="pl-c1">1024</span> )
  <span class="pl-k">return</span> container
<span class="pl-k">end</span>

c <span class="pl-k">=</span> <span class="pl-c1">Container</span>()
<span class="pl-c1">println</span>(<span class="pl-s"><span class="pl-pds">"</span>got pointer: <span class="pl-pds">"</span></span>, c<span class="pl-k">.</span>ptr)</pre></div>
<p dir="auto">Julia-Version:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="Julia Version 0.7.0-DEV.3183
Commit 4b74a74 (2017-12-25 07:17 UTC)
Platform Info:
  OS: Linux (x86_64-redhat-linux)
  CPU: Intel(R) Core(TM) i7-4700MQ CPU @ 2.40GHz
  WORD_SIZE: 64
  BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY Haswell)
  LAPACK: libopenblas64_
  LIBM: libopenlibm
  LLVM: libLLVM-3.9.1 (ORCJIT, haswell)"><pre class="notranslate"><code class="notranslate">Julia Version 0.7.0-DEV.3183
Commit 4b74a74 (2017-12-25 07:17 UTC)
Platform Info:
  OS: Linux (x86_64-redhat-linux)
  CPU: Intel(R) Core(TM) i7-4700MQ CPU @ 2.40GHz
  WORD_SIZE: 64
  BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY Haswell)
  LAPACK: libopenblas64_
  LIBM: libopenlibm
  LLVM: libLLVM-3.9.1 (ORCJIT, haswell)
</code></pre></div>
<p dir="auto">Segfault information:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="signal (11): Segmentation fault
in expression starting at /TEST/Desktop/mytest.jl:22
jl_typemap_level_assoc_exact at /TEST/julia/julia_trunk/src/typemap.c:810
jl_typemap_assoc_exact at /TEST/julia/julia_trunk/src/julia_internal.h:940 [inlined]
jl_lookup_generic_ at /TEST/julia/julia_trunk/src/gf.c:2026 [inlined]
jl_apply_generic at /TEST/julia/julia_trunk/src/gf.c:2078
Type at /TEST/Desktop/mytest.jl:18
jl_call_fptr_internal at /TEST/julia/julia_trunk/src/julia_internal.h:380 [inlined]
jl_call_method_internal at /TEST/julia/julia_trunk/src/julia_internal.h:399 [inlined]
jl_apply_generic at /TEST/julia/julia_trunk/src/gf.c:2081
do_call at /TEST/julia/julia_trunk/src/interpreter.c:323
eval_value at /TEST/julia/julia_trunk/src/interpreter.c:395
eval_body at /TEST/julia/julia_trunk/src/interpreter.c:509
jl_interpret_toplevel_thunk_callback at /TEST/julia/julia_trunk/src/interpreter.c:720
unknown function (ip: 0xfffffffffffffffe)
unknown function (ip: 0x7f9d6502ff8f)
unknown function (ip: 0xffffffffffffffff)
jl_interpret_toplevel_thunk at /TEST/julia/julia_trunk/src/interpreter.c:729
jl_toplevel_eval_flex at /TEST/julia/julia_trunk/src/toplevel.c:721
jl_parse_eval_all at /TEST/julia/julia_trunk/src/ast.c:803
jl_load at /TEST/julia/julia_trunk/src/toplevel.c:759
include at ./boot.jl:295 [inlined]
include_relative at ./loading.jl:503
jl_call_fptr_internal at /TEST/julia/julia_trunk/src/julia_internal.h:380 [inlined]
jl_call_method_internal at /TEST/julia/julia_trunk/src/julia_internal.h:399 [inlined]
jl_apply_generic at /TEST/julia/julia_trunk/src/gf.c:2081
include at ./sysimg.jl:26
jl_call_fptr_internal at /TEST/julia/julia_trunk/src/julia_internal.h:380 [inlined]
jl_call_method_internal at /TEST/julia/julia_trunk/src/julia_internal.h:399 [inlined]
jl_apply_generic at /TEST/julia/julia_trunk/src/gf.c:2081
process_options at ./client.jl:330
_start at ./client.jl:381
jl_call_fptr_internal at /TEST/julia/julia_trunk/src/julia_internal.h:380 [inlined]
jl_call_method_internal at /TEST/julia/julia_trunk/src/julia_internal.h:399 [inlined]
jl_apply_generic at /TEST/julia/julia_trunk/src/gf.c:2081
jl_apply at /TEST/julia/julia_trunk/ui/../src/julia.h:1474 [inlined]
true_main at /TEST/julia/julia_trunk/ui/repl.c:107
main at /TEST/julia/julia_trunk/ui/repl.c:237
__libc_start_main at /lib64/libc.so.6 (unknown line)
_start at ./julia (unknown line)
Allocations: 289698 (Pool: 289541; Big: 157); GC: 0"><pre class="notranslate"><code class="notranslate">signal (11): Segmentation fault
in expression starting at /TEST/Desktop/mytest.jl:22
jl_typemap_level_assoc_exact at /TEST/julia/julia_trunk/src/typemap.c:810
jl_typemap_assoc_exact at /TEST/julia/julia_trunk/src/julia_internal.h:940 [inlined]
jl_lookup_generic_ at /TEST/julia/julia_trunk/src/gf.c:2026 [inlined]
jl_apply_generic at /TEST/julia/julia_trunk/src/gf.c:2078
Type at /TEST/Desktop/mytest.jl:18
jl_call_fptr_internal at /TEST/julia/julia_trunk/src/julia_internal.h:380 [inlined]
jl_call_method_internal at /TEST/julia/julia_trunk/src/julia_internal.h:399 [inlined]
jl_apply_generic at /TEST/julia/julia_trunk/src/gf.c:2081
do_call at /TEST/julia/julia_trunk/src/interpreter.c:323
eval_value at /TEST/julia/julia_trunk/src/interpreter.c:395
eval_body at /TEST/julia/julia_trunk/src/interpreter.c:509
jl_interpret_toplevel_thunk_callback at /TEST/julia/julia_trunk/src/interpreter.c:720
unknown function (ip: 0xfffffffffffffffe)
unknown function (ip: 0x7f9d6502ff8f)
unknown function (ip: 0xffffffffffffffff)
jl_interpret_toplevel_thunk at /TEST/julia/julia_trunk/src/interpreter.c:729
jl_toplevel_eval_flex at /TEST/julia/julia_trunk/src/toplevel.c:721
jl_parse_eval_all at /TEST/julia/julia_trunk/src/ast.c:803
jl_load at /TEST/julia/julia_trunk/src/toplevel.c:759
include at ./boot.jl:295 [inlined]
include_relative at ./loading.jl:503
jl_call_fptr_internal at /TEST/julia/julia_trunk/src/julia_internal.h:380 [inlined]
jl_call_method_internal at /TEST/julia/julia_trunk/src/julia_internal.h:399 [inlined]
jl_apply_generic at /TEST/julia/julia_trunk/src/gf.c:2081
include at ./sysimg.jl:26
jl_call_fptr_internal at /TEST/julia/julia_trunk/src/julia_internal.h:380 [inlined]
jl_call_method_internal at /TEST/julia/julia_trunk/src/julia_internal.h:399 [inlined]
jl_apply_generic at /TEST/julia/julia_trunk/src/gf.c:2081
process_options at ./client.jl:330
_start at ./client.jl:381
jl_call_fptr_internal at /TEST/julia/julia_trunk/src/julia_internal.h:380 [inlined]
jl_call_method_internal at /TEST/julia/julia_trunk/src/julia_internal.h:399 [inlined]
jl_apply_generic at /TEST/julia/julia_trunk/src/gf.c:2081
jl_apply at /TEST/julia/julia_trunk/ui/../src/julia.h:1474 [inlined]
true_main at /TEST/julia/julia_trunk/ui/repl.c:107
main at /TEST/julia/julia_trunk/ui/repl.c:237
__libc_start_main at /lib64/libc.so.6 (unknown line)
_start at ./julia (unknown line)
Allocations: 289698 (Pool: 289541; Big: 157); GC: 0
</code></pre></div>