# Exception access violation (only Julia 1.8 on Windows)

**URL:** <https://discourse.julialang.org/t/exception-access-violation-only-julia-1-8-on-windows/87781>\
**Category:** General Usage\
**Tags:** ccall\
**Created:** [September 25, 2022, 3:11pm UTC](https://discourse.julialang.org/t/exception-access-violation-only-julia-1-8-on-windows/87781 "2022-09-25T15:11:05Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![andreasvarga](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/andreasvarga/32/11634_2.png) [@andreasvarga](https://discourse.julialang.org/u/andreasvarga)\
**Post date:** [September 25, 2022, 3:11pm UTC](https://discourse.julialang.org/t/exception-access-violation-only-julia-1-8-on-windows/87781/1 "2022-09-25T15:11:05Z")

</div>

I am using the Fortran 77 library [SLICOT](https://github.com/SLICOT/SLICOT-Reference/) in my current project [PeriodicSystems](https://github.com/andreasvarga/PeriodicSystems.jl) via the binary wrapper [SLICOT\_jll](https://github.com/JuliaBinaryWrappers/SLICOT_jll.jl) automatically generated with the [BinaryBuilder](https://github.com/JuliaPackaging/BinaryBuilder.jl). Recently, versions of `SLICOT_jll` have been generated for Julia 1.7, 1.8 and 1.9 for a bunch of compilers and operating systems. I started testing the generated libraries with Julia 1.7 and 1.8 runing both on Windows and Linux.

The following error occurs during testing under Windows with Julia 1.8, leading to crashing Julia (see [CI.log](https://github.com/andreasvarga/PeriodicSystems.jl/actions/runs/3088971504/jobs/4996050657)):

```julia
Test_psfutils

Please submit a bug report with steps to reproduce this fault, and any error messages that follow (in their entirety). Thanks.
Exception: EXCEPTION_ACCESS_VIOLATION at 0x0 -- unknown function (ip: 0000000000000000)
in expression starting at D:\a\PeriodicSystems.jl\PeriodicSystems.jl\test\test_pschur.jl:15
unknown function (ip: 0000000000000000)
Allocations: 107208134 (Pool: 107190352; Big: 17782); GC: 43
ERROR: LoadError: Package PeriodicSystems errored during testing
Stacktrace:
 [1] pkgerror(msg::String)
   @ Pkg.Types C:\hostedtoolcache\windows\julia\1.8.1\x64\share\julia\stdlib\v1.8\Pkg\src\Types.jl:67
 [2] test(ctx::Pkg.Types.Context, pkgs::Vector{Pkg.Types.PackageSpec}; coverage::Bool, julia_args::Cmd, test_args::Cmd, test_fn::Nothing, force_latest_compatible_version::Bool, allow_earlier_backwards_compatible_versions::Bool, allow_reresolve::Bool)
   @ Pkg.Operations C:\hostedtoolcache\windows\julia\1.8.1\x64\share\julia\stdlib\v1.8\Pkg\src\Operations.jl:1813
 [3] test(ctx::Pkg.Types.Context, pkgs::Vector{Pkg.Types.PackageSpec}; coverage::Bool, test_fn::Nothing, julia_args::Vector{String}, test_args::Cmd, force_latest_compatible_version::Bool, allow_earlier_backwards_compatible_versions::Bool, allow_reresolve::Bool, kwargs::Base.Pairs{Symbol, IOContext{Base.PipeEndpoint}, Tuple{Symbol}, NamedTuple{(:io,), Tuple{IOContext{Base.PipeEndpoint}}}})
   @ Pkg.API C:\hostedtoolcache\windows\julia\1.8.1\x64\share\julia\stdlib\v1.8\Pkg\src\API.jl:431
 [4] test(pkgs::Vector{Pkg.Types.PackageSpec}; io::IOContext{Base.PipeEndpoint}, kwargs::Base.Pairs{Symbol, Any, Tuple{Symbol, Symbol, Symbol}, NamedTuple{(:coverage, :julia_args, :force_latest_compatible_version), Tuple{Bool, Vector{String}, Bool}}})
   @ Pkg.API C:\hostedtoolcache\windows\julia\1.8.1\x64\share\julia\stdlib\v1.8\Pkg\src\API.jl:156
 [5] test(; name::Nothing, uuid::Nothing, version::Nothing, url::Nothing, rev::Nothing, path::Nothing, mode::Pkg.Types.PackageMode, subdir::Nothing, kwargs::Base.Pairs{Symbol, Any, Tuple{Symbol, Symbol, Symbol}, NamedTuple{(:coverage, :julia_args, :force_latest_compatible_version), Tuple{Bool, Vector{String}, Bool}}})
   @ Pkg.API C:\hostedtoolcache\windows\julia\1.8.1\x64\share\julia\stdlib\v1.8\Pkg\src\API.jl:171
 [6] top-level scope
   @ D:\a\_actions\julia-actions\julia-runtest\v1\test_harness.jl:15
 [7] include(fname::String)
   @ Base.MainInclude .\client.jl:476
 [8] top-level scope
   @ none:1
in expression starting at D:\a\_actions\julia-actions\julia-runtest\v1\test_harness.jl:7

```

This error can be reproduced using the following code (which will probably crash Julia 1.8 on Windows):

```julia
using PeriodicSystems
using LinearAlgebra
using LinearAlgebra: BlasInt

# MB03BD example
A1 = Matrix{Float64}(I,3,3); A2 = [1.0 2.0 0.0; 4.0 -1.0 3.0; 0.0 3.0 1.0]; A3 = Matrix{Float64}(I,3,3); 
E1 = [2.0 0.0 1.0; 0.0 -2.0 -1.0; 0.0 0.0 3.0]; E2 = Matrix{Float64}(I,3,3); 
E3 = [1.0 0.0 1.0; 0.0 4.0 -1.0; 0.0 0.0 -2.0];
ihess = 2

# using the SLICOT wrapper mb03bd!
A = reshape([E1 A2 E3],3,3,3);
KMAX = 3
NMAX = 3
LDA1 = NMAX
LDA2 = NMAX
LDQ1 = NMAX
LDQ2 = NMAX
LDWORK = KMAX + max( 2*NMAX, 8*KMAX )
LIWORK = 2*KMAX + NMAX
QIND = Array{BlasInt,1}(undef, KMAX)
S = [-1,1,-1]; 
Q = Array{Float64,3}(undef, LDQ1, LDQ2, KMAX)
ALPHAR = Array{Float64,1}(undef, NMAX)
ALPHAI = Array{Float64,1}(undef, NMAX)
BETA = Array{Float64,1}(undef, NMAX)
SCAL = Array{BlasInt,1}(undef, NMAX)
IWORK = Array{BlasInt,1}(undef, LIWORK)
DWORK = Array{Float64,1}(undef, LDWORK)

mb03bd!('T','C','I',QIND,3,3,ihess,1,3,S,A,Q,ALPHAR, ALPHAI, BETA, SCAL, LIWORK, LDWORK)

```

Because the above sequence correctly works under Linux with Julia 1.8, my guess is that this error probably originates from a (somehow) corrupted SLICOT\_jll binary library.

The wrapper `mb03bd!` used above is:

```julia
function mb03bd!(job::AbstractChar, defl::AbstractChar,
    compq::AbstractChar, qind::AbstractVector{BlasInt}, k::Integer,
    n::Integer, h::Integer, ilo::Integer, ihi::Integer,
    s::AbstractVector{BlasInt}, a::Array{Float64,3},
    q::Array{Float64,3},
    alphar::AbstractVector{Float64}, alphai::AbstractVector{Float64},
    beta::AbstractVector{Float64}, scal::AbstractVector{BlasInt},
    liwork::Integer, ldwork::Integer)

    lda1 = max(1,stride(a,2))
    lda2 = max(1,stride(a,3)÷lda1)
    ldq1 = max(1,stride(q,2))
    ldq2 = max(1,stride(q,3)÷ldq1)
    info = Ref{BlasInt}()
    iwarn = Ref{BlasInt}()
    iwork = Vector{BlasInt}(undef, liwork)
    dwork = Vector{Float64}(undef, ldwork)

    ccall((:mb03bd_, libslicot), Cvoid, (Ref{UInt8}, Ref{UInt8},
            Ref{UInt8}, Ptr{BlasInt}, Ref{BlasInt}, Ref{BlasInt},
            Ref{BlasInt}, Ref{BlasInt}, Ref{BlasInt}, Ptr{BlasInt},
            Ptr{Float64}, Ref{BlasInt}, Ref{BlasInt}, Ptr{Float64},
            Ref{BlasInt}, Ref{BlasInt}, Ptr{Float64}, Ptr{Float64},
            Ptr{Float64}, Ptr{BlasInt}, Ptr{BlasInt}, Ref{BlasInt},
            Ptr{Float64}, Ref{BlasInt}, Ptr{BlasInt}, Ptr{BlasInt},
            Clong, Clong, Clong), job, defl, compq, qind, k, n, h,
            ilo, ihi, s, a, lda1, lda2, q, ldq1, ldq2, alphar,
            alphai, beta, scal, iwork, liwork, dwork, ldwork, iwarn,
            info, 1, 1, 1)
    chkargsok(info[])

    return info[], iwarn[]
end

```

Unfortunately, I can not debug this crash on my computer, because after crash, the Julia windows closes. However I assume, that the error message is the same as in the [CI.log](https://github.com/andreasvarga/PeriodicSystems.jl/actions/runs/3088971504/jobs/4996050657)).

O would appreciate any idea or advise on how to debug this error. Many thanks in advance.

---

<div class="post-metadata">

**Author:** ![jd-foster](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jd-foster/32/35824_2.png) [@jd-foster](https://discourse.julialang.org/u/jd-foster)\
**Post date:** [September 27, 2022, 6:43am UTC](https://discourse.julialang.org/t/exception-access-violation-only-julia-1-8-on-windows/87781/2 "2022-09-27T06:43:55Z")

</div>

Although not a segfault, this might provide a direction:  
[https://docs.julialang.org/en/v1/devdocs/backtraces/#Segfaults-when-running-a-script](https://docs.julialang.org/en/v1/devdocs/backtraces/#Segfaults-when-running-a-script)

---

<div class="post-metadata">

**Author:** ![andreasvarga](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/andreasvarga/32/11634_2.png) [@andreasvarga](https://discourse.julialang.org/u/andreasvarga)\
**Post date:** [September 27, 2022, 11:12am UTC](https://discourse.julialang.org/t/exception-access-violation-only-julia-1-8-on-windows/87781/3 "2022-09-27T11:12:09Z")

</div>

Are these tools available also for Windows?

---

<div class="post-metadata">

**Author:** ![andreasvarga](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/andreasvarga/32/11634_2.png) [@andreasvarga](https://discourse.julialang.org/u/andreasvarga)\
**Post date:** [September 29, 2022, 12:57pm UTC](https://discourse.julialang.org/t/exception-access-violation-only-julia-1-8-on-windows/87781/4 "2022-09-29T12:57:24Z")

</div>

I generated a MWE to test the generated SLICOT\_jll on various architectures and Julia versions. Here are the results (see the full [CI.log](https://github.com/andreasvarga/PeriodicSystems.jl/actions/runs/3151066166/jobs/5124566608) for the failures):

 ![MWE_SLICOT](https://global.discourse-cdn.com/julialang/original/3X/2/7/2781ad3a0b6768cc203af6d8ffb2dce688d6fe10.jpeg)

The only conclusion I can draw from this is that the binary libraries generated for Windows for Julia 1.8 and 1.9 are faulty, while the library for Julia 1.7 is correct. My understanding is that since the compilation options are set automatocally, it should something be wrong with these settings. Before opening an issue, I would appreciate to have your opinion on how to proceed further.

---

<div class="post-metadata">

**Author:** ![Ralph\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ralph_smith/32/10344_2.png) [@Ralph\_Smith](https://discourse.julialang.org/u/Ralph_Smith)\
**Post date:** [September 29, 2022, 2:10pm UTC](https://discourse.julialang.org/t/exception-access-violation-only-julia-1-8-on-windows/87781/5 "2022-09-29T14:10:05Z")

</div>

It would be best to work on a Windows system with the MinGW development environment appropriate to the actual artifact used by Julia 1.8 there (perhaps @giordano can tell us where to find all the details). There one could run `gdb` to diagnose the problem and try alternative build flags. (A calling program in Fortran should suffice and be easier to debug than Julia.) I don’t have a convenient Windows system so I hope someone else can help.

---

<div class="post-metadata">

**Author:** ![andreasvarga](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/andreasvarga/32/11634_2.png) [@andreasvarga](https://discourse.julialang.org/u/andreasvarga)\
**Post date:** [September 29, 2022, 4:29pm UTC](https://discourse.julialang.org/t/exception-access-violation-only-julia-1-8-on-windows/87781/6 "2022-09-29T16:29:31Z")

</div>

I am wondering if SLICOT is the only library which faces these problems. As far as I know, for example, Arpack should also have Fortran components.
