Issue 1:
Symptoms

On julia 0.6.1 it appears libgit2 builds incorrectly on older Debian system.

After modifying/deps/libgit2.mk to set -DBUILD_CLAR=ON (so the libgit2 tests will be built) and building julia, running the libgit2 tests segfaults part way through. This happens on Debian 6, but not Debian 7.

Also on Debian 6, launching julia gives the message:

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)

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 #18693. Also, setting the environmental variables described in that issue did not help.

Building libgit2 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 libgit2.

Steps to reproduce

Using a virtual machine (preferably with multiple cores, to speed up step 4)

Install Debian 6 (installation medium here). During installation, decline to use a network mirror (Debian 6 packages are no longer available on the regular mirrors)

Download the scripts here to your home directory

Run install_pkgs.sh as root. This will update apt to find the archive mirror and install as many dependencies from there as possible.

Run install_src.sh 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 ~/local. Make sure to source ~/.bashrc after this script completes.

Now you can attempt to launch julia (in $HOME/julia) to verify it does not work. You can then go into ~/julia/deps/scratch/libgit2-COMMIT_HASH) and run libgit2_clar to see it segfault.

There is also a script install_ssl.sh to install OpenSSL 1.0.2m to ~/crypto and updates .bashrc. It is not run as part of step 4 but may be useful for debugging.

Backtrace

Running libgit2_clar under gdb gives this backtrace:

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

Also, ldd confirms libgit2.so linked to mbedtls built by julia and not the system OpenSSL.

Issue 2:
It appears that broken symlinks within the SSL_CERT_DIR can cause Julia to raise an exception during startup:

$ 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("error initializing LibGit2 module"))
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)

Note that the paths in the exception above appear to be from the official build server as I encountered this in a Debian environment.

versioninfo:

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)