Skip to content

Fortran ABI issues with character arguments #650

@jabl

Description

@jabl

Hello,

this is a heads-up about an issue that appears to affect Julia based on a quick perusal of the source code (https://github.com/JuliaLang/julia/blob/master/stdlib/LinearAlgebra/src/blas.jl and https://github.com/JuliaLang/julia/blob/master/stdlib/LinearAlgebra/src/lapack.jl , maybe other files in the repo too).

When calling Fortran procedures that have character arguments, the character lengths have to be passed from the caller to the callee. Typically Fortran ABI's place these hidden (hidden in the sense that the Fortran programmer doesn't need to care about it, the compiler takes care of it behind the scenes) at the end of the argument list. Now, unfortunately it seems common to omit these hidden character length arguments when calling BLAS or LAPACK procedures with single-length characters.

While this has worked (apparently adequately?) for several decades, in light of increasingly sophisticated compiler optimizations, for instance interprocedural or link-time optimizations, such sins are unfortunately coming back to haunt us.

The upstream GFortran bug report: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90329

CBLAS/LAPACKE bug report, which has become a sort of gathering-place for links to various incantations of this bug on github: Reference-LAPACK/lapack#339

There's even a LWN article: https://lwn.net/Articles/791393/

And one of the R developers who first discovered that this ABI mismatch could cause a (very subtle) problem wrote a nice overview: https://developer.r-project.org/Blog/public/2019/05/15/gfortran-issues-with-lapack/

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions