<h1 dir="auto">Symptoms</h1>
<p dir="auto">On julia 0.6.1 it appears <code class="notranslate">libgit2</code> builds incorrectly on older Debian system.</p>
<p dir="auto">After modifying<code class="notranslate">/deps/libgit2.mk</code> to set <code class="notranslate">-DBUILD_CLAR=ON</code> (so the <code class="notranslate">libgit2</code> tests will be built) and building julia, running the <code class="notranslate">libgit2</code> tests segfaults part way through. This happens on Debian 6, but not Debian 7.</p>
<p dir="auto">Also on Debian 6, launching julia gives the message:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="fatal: error thrown and no exception handler available.
Base.InitError(mod=:LibGit2, error=ErrorException(&quot;error initializing LibGit2 module&quot;))
rec_backtrace at /home/dev/julia/src/stackwalk.c:84
record_backtrace at /home/dev/julia/src/task.c:245
jl_throw at /home/dev/julia/src/task.c:564
__init__ at ./libgit2/libgit2.jl:920
unknown function (ip: 0x7f9469e06ad8)
jl_call_fptr_internal at /home/dev/julia/src/julia_internal.h:339 [inlined]
jl_call_method_internal at /home/dev/julia/src/julia_internal.h:358 [inlined]
jl_apply_generic at /home/dev/julia/src/gf.c:1926
jl_apply at /home/dev/julia/src/julia.h:1424 [inlined]
jl_module_run_initializer at /home/dev/julia/src/toplevel.c:87
_julia_init at /home/dev/julia/src/init.c:733
julia_init at /home/dev/julia/src/task.c:297
main at /home/dev/julia/ui/repl.c:259
__libc_start_main at /lib/libc.so.6 (unknown line)
unknown function (ip: 0x401698)"><pre class="notranslate"><code class="notranslate">fatal: error thrown and no exception handler available.
Base.InitError(mod=:LibGit2, error=ErrorException("error initializing LibGit2 module"))
rec_backtrace at /home/dev/julia/src/stackwalk.c:84
record_backtrace at /home/dev/julia/src/task.c:245
jl_throw at /home/dev/julia/src/task.c:564
__init__ at ./libgit2/libgit2.jl:920
unknown function (ip: 0x7f9469e06ad8)
jl_call_fptr_internal at /home/dev/julia/src/julia_internal.h:339 [inlined]
jl_call_method_internal at /home/dev/julia/src/julia_internal.h:358 [inlined]
jl_apply_generic at /home/dev/julia/src/gf.c:1926
jl_apply at /home/dev/julia/src/julia.h:1424 [inlined]
jl_module_run_initializer at /home/dev/julia/src/toplevel.c:87
_julia_init at /home/dev/julia/src/init.c:733
julia_init at /home/dev/julia/src/task.c:297
main at /home/dev/julia/ui/repl.c:259
__libc_start_main at /lib/libc.so.6 (unknown line)
unknown function (ip: 0x401698)
</code></pre></div>
<p dir="auto">but on Debian 7 julia launches normally.  Because the tests segfault and the SSL certificates are installed in the same place in both cases, I think this is different than <a href="https://github.com/JuliaLang/julia/issues/18693" data-hovercard-type="issue" data-hovercard-url="/JuliaLang/julia/issues/18693/hovercard">#18693</a>.  Also, setting the environmental variables described in that issue did not help.</p>
<p dir="auto">Building <code class="notranslate">libgit2</code> separately from julia and linking it to OpenSSL 1.0.2m (the system OpenSSL is too old) works (on Debian 6).  It appears the problem is specific to how julia is building <code class="notranslate">libgit2</code>.</p>
<h1 dir="auto">Steps to reproduce</h1>
<p dir="auto">Using a virtual machine (preferably with multiple cores, to speed up step 4)</p>
<ol dir="auto">
<li>
<p dir="auto">Install Debian 6 (installation medium <a href="https://caesar.ftp.acc.umu.se/cdimage/archive/6.0.10/amd64/iso-cd/debian-6.0.10-amd64-CD-1.iso" rel="nofollow">here</a>).  During installation, decline to use a network mirror (Debian 6 packages are no longer available on the regular mirrors)</p>
</li>
<li>
<p dir="auto">Download the scripts <a href="https://gist.github.com/JaredCrean2/594185472f24502ed0182dfb2431de6b">here</a> to your home directory</p>
</li>
<li>
<p dir="auto">Run <code class="notranslate">install_pkgs.sh</code> as root.  This will update <code class="notranslate">apt</code> to find the archive mirror and install as many dependencies from there as possible.</p>
</li>
<li>
<p dir="auto">Run <code class="notranslate">install_src.sh</code> as a regular user.  This will build all remaining dependencies from source and then build julia itself.  This takes a while because GCC, CMake, Binutils, and Python 2.7 have to be built.  They will be installed to <code class="notranslate">~/local</code>.  Make sure to <code class="notranslate">source ~/.bashrc</code> after this script completes.</p>
</li>
<li>
<p dir="auto">Now you can attempt to launch julia (in <code class="notranslate">$HOME/julia</code>) to verify it does not work.  You can then go into <code class="notranslate">~/julia/deps/scratch/libgit2-COMMIT_HASH</code>) and run <code class="notranslate">libgit2_clar</code> to see it segfault.</p>
</li>
</ol>
<p dir="auto">There is also a script <code class="notranslate">install_ssl.sh</code> to install OpenSSL 1.0.2m to <code class="notranslate">~/crypto</code> and updates <code class="notranslate">.bashrc</code>.  It is not run as part of step 4 but may be useful for debugging.</p>
<h1 dir="auto">Backtrace</h1>
<p dir="auto">Running <code class="notranslate">libgit2_clar</code> under gdb gives this backtrace:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="Program received signal SIGSEGV, Segmentation fault.
0x00000000004919fc in git_mwindow_get_pack ()
(gdb) backtrace
#0  0x00000000004919fc in git_mwindow_get_pack ()
#1  0x000000000043709e in packfile_load(char, bool) ()
#2  0x0000000000478624 in git_path_direach ()
#3  0x0000000000436f0f in pack_backend__refresh ()
#4  0x0000000000437bd4 in git_odb_backend_pack ()
#5  0x000000000041c98c in add_default_backends ()
#6  0x000000000041d65f in git_odb_open ()
#7  0x00000000004322ab in git_repository_odb__weakptr ()
#8  0x000000000046a1e2 in git_object_lookup_prefix ()
#9  0x000000000041280e in git_attr_file__load ()
#10 0x0000000000424994 in git_attr_cache__get ()
#11 0x000000000041fcc6 in collect_attr_files ()
#12 0x000000000041ff90 in git_attr_get ()
#13 0x00000000005f40da in test_attr_flags__index_vs_workdir ()
#14 0x00000000004cd583 in clar_run_test.isra.6 ()
#15 0x00000000004cda41 in clar_test_run ()
#16 0x000000000040f46a in main ()"><pre class="notranslate"><code class="notranslate">Program received signal SIGSEGV, Segmentation fault.
0x00000000004919fc in git_mwindow_get_pack ()
(gdb) backtrace
#0  0x00000000004919fc in git_mwindow_get_pack ()
#1  0x000000000043709e in packfile_load(char, bool) ()
#2  0x0000000000478624 in git_path_direach ()
#3  0x0000000000436f0f in pack_backend__refresh ()
#4  0x0000000000437bd4 in git_odb_backend_pack ()
#5  0x000000000041c98c in add_default_backends ()
#6  0x000000000041d65f in git_odb_open ()
#7  0x00000000004322ab in git_repository_odb__weakptr ()
#8  0x000000000046a1e2 in git_object_lookup_prefix ()
#9  0x000000000041280e in git_attr_file__load ()
#10 0x0000000000424994 in git_attr_cache__get ()
#11 0x000000000041fcc6 in collect_attr_files ()
#12 0x000000000041ff90 in git_attr_get ()
#13 0x00000000005f40da in test_attr_flags__index_vs_workdir ()
#14 0x00000000004cd583 in clar_run_test.isra.6 ()
#15 0x00000000004cda41 in clar_test_run ()
#16 0x000000000040f46a in main ()
</code></pre></div>
<p dir="auto">Also, <code class="notranslate">ldd</code> confirms <code class="notranslate">libgit2.so</code> linked to <code class="notranslate">mbedtls</code> built by julia and not the system OpenSSL.</p>
<p dir="auto">It appears that broken symlinks within the SSL_CERT_DIR can cause Julia to raise an exception during startup:</p>
<div class="highlight highlight-source-shell notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="$ mkdir /tmp/certs
$ cd /tmp/certs
$ ln -s bar foo
$ ln -s /doesnotexist bar
$ SSL_CERT_DIR=/tmp/certs julia  # Julia 0.6
fatal: error thrown and no exception handler available.
Base.InitError(mod=:LibGit2, error=ErrorException(&quot;error initializing LibGit2 module&quot;))
rec_backtrace at /home/centos/buildbot/slave/package_tarball64/build/src/stackwalk.c:84
record_backtrace at /home/centos/buildbot/slave/package_tarball64/build/src/task.c:239
jl_throw at /home/centos/buildbot/slave/package_tarball64/build/src/task.c:565
__init__ at ./libgit2/libgit2.jl:669
unknown function (ip: 0x7f0b84fc7a88)
jl_call_method_internal at /home/centos/buildbot/slave/package_tarball64/build/src/julia_internal.h:248 [inlined]
jl_apply_generic at /home/centos/buildbot/slave/package_tarball64/build/src/gf.c:2217
jl_apply at /home/centos/buildbot/slave/package_tarball64/build/src/julia.h:1411 [inlined]
jl_module_run_initializer at /home/centos/buildbot/slave/package_tarball64/build/src/toplevel.c:85
_julia_init at /home/centos/buildbot/slave/package_tarball64/build/src/init.c:704
julia_init at /home/centos/buildbot/slave/package_tarball64/build/src/task.c:292
unknown function (ip: 0x401656)
__libc_start_main at /lib/x86_64-linux-gnu/libc.so.6 (unknown line)
unknown function (ip: 0x40170c)"><pre class="notranslate">$ mkdir /tmp/certs
$ <span class="pl-c1">cd</span> /tmp/certs
$ ln -s bar foo
$ ln -s /doesnotexist bar
$ SSL_CERT_DIR=/tmp/certs julia  <span class="pl-c"><span class="pl-c">#</span> Julia 0.6</span>
fatal: error thrown and no exception handler available.
Base.InitError(mod=:LibGit2, error=ErrorException(<span class="pl-s"><span class="pl-pds">"</span>error initializing LibGit2 module<span class="pl-pds">"</span></span>))
rec_backtrace at /home/centos/buildbot/slave/package_tarball64/build/src/stackwalk.c:84
record_backtrace at /home/centos/buildbot/slave/package_tarball64/build/src/task.c:239
jl_throw at /home/centos/buildbot/slave/package_tarball64/build/src/task.c:565
__init__ at ./libgit2/libgit2.jl:669
unknown <span class="pl-k">function</span> <span class="pl-en">(ip:</span> 0x7f0b84fc7a88)
jl_call_method_internal at /home/centos/buildbot/slave/package_tarball64/build/src/julia_internal.h:248 [inlined]
jl_apply_generic at /home/centos/buildbot/slave/package_tarball64/build/src/gf.c:2217
jl_apply at /home/centos/buildbot/slave/package_tarball64/build/src/julia.h:1411 [inlined]
jl_module_run_initializer at /home/centos/buildbot/slave/package_tarball64/build/src/toplevel.c:85
_julia_init at /home/centos/buildbot/slave/package_tarball64/build/src/init.c:704
julia_init at /home/centos/buildbot/slave/package_tarball64/build/src/task.c:292
unknown <span class="pl-k">function</span> <span class="pl-en">(ip:</span> 0x401656)
__libc_start_main at /lib/x86_64-linux-gnu/libc.so.6 (unknown line)
unknown <span class="pl-k">function</span> <span class="pl-en">(ip:</span> 0x40170c)</pre></div>
<p dir="auto">Note that the paths in the exception above appear to be from the official build server as I encountered this in a Debian environment.</p>
<p dir="auto">versioninfo:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="Julia Version 0.6.0-dev.2499
Commit cdca71b (2017-02-01 15:33 UTC)
Platform Info:
  OS: Linux (x86_64-pc-linux-gnu)
  CPU: Intel(R) Xeon(R) CPU E5-2670 v2 @ 2.50GHz
  WORD_SIZE: 64
  BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY Sandybridge)
  LAPACK: libopenblas64_
  LIBM: libopenlibm
  LLVM: libLLVM-3.9.1 (ORCJIT, ivybridge)"><pre class="notranslate"><code class="notranslate">Julia Version 0.6.0-dev.2499
Commit cdca71b (2017-02-01 15:33 UTC)
Platform Info:
  OS: Linux (x86_64-pc-linux-gnu)
  CPU: Intel(R) Xeon(R) CPU E5-2670 v2 @ 2.50GHz
  WORD_SIZE: 64
  BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY Sandybridge)
  LAPACK: libopenblas64_
  LIBM: libopenlibm
  LLVM: libLLVM-3.9.1 (ORCJIT, ivybridge)
</code></pre></div>