Exception access violation (only Julia 1.8 on Windows)

I am using the Fortran 77 library SLICOT in my current project PeriodicSystems via the binary wrapper SLICOT_jll automatically generated with the BinaryBuilder. 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):


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
 [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):

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
LDWORK = KMAX + max( 2*NMAX, 8*KMAX )
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:

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},
    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)

    return info[], iwarn[]

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

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

Although not a segfault, this might provide a direction:

Are these tools available also for Windows?

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 for the failures):

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.

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.

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.