You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The prototypes for Fortran LAPACK functions appear to be incomplete in Dlib. This can lead to undefined behaviour with recent releases of gcc due to more aggressive compiler optimisations.
According to gfortran passing conventions (followed by other fortran compilers as well), every char* argument also has an associated "hidden" argument which specifies the number of characters. The type of the "hidden" argument may vary across compilers and/or compiler versions. The position of each "hidden" argument is also compiler dependent, though seems to be typically tacked onto the end of the function definition. https://gcc.gnu.org/onlinedocs/gfortran/Argument-passing-conventions.html
where blas_len is typically a 32 bit unsigned int on 32 bit platforms, and 64 bit unsigned int on 64 bit platforms. (This does not apply to gcc versions <= 7, where it is always int).
Avoiding the use of the blas_len arguments appeared to work, but recently gcc has started to optimise more heavily, leading to stack overwrites when these arguments are not used.
The same bug affects Armadillo, R, and a lot of other software in C and C++ that uses LAPACK:
A while back I've also had a few reports of strange crashes involving code compiled by non-gcc compilers. I couldn't reproduce them on my setup, but I now strongly suspect that the "hidden" args were the culprit.
The prototypes for Fortran LAPACK functions appear to be incomplete in Dlib. This can lead to undefined behaviour with recent releases of gcc due to more aggressive compiler optimisations.
According to gfortran passing conventions (followed by other fortran compilers as well), every
char*
argument also has an associated "hidden" argument which specifies the number of characters. The type of the "hidden" argument may vary across compilers and/or compiler versions. The position of each "hidden" argument is also compiler dependent, though seems to be typically tacked onto the end of the function definition.https://gcc.gnu.org/onlinedocs/gfortran/Argument-passing-conventions.html
As an example in Dlib, the current prototype for
dsyev
inhttps://github.com/davisking/dlib/blob/master/dlib/matrix/lapack/syev.h
is defined as:
void DLIB_FORTRAN_ID(dsyev) (const char *jobz, const char *uplo, const integer *n, double *a, const integer *lda, double *w, double *work, const integer *lwork, integer *info);
But it probably should be:
void DLIB_FORTRAN_ID(dsyev) (const char *jobz, const char *uplo, const integer *n, double *a, const integer *lda, double *w, double *work, const integer *lwork, integer *info, blas_len jobz_len, blas_len uplo_len);
where
blas_len
is typically a 32 bit unsigned int on 32 bit platforms, and 64 bit unsigned int on 64 bit platforms. (This does not apply to gcc versions <= 7, where it is alwaysint
).Avoiding the use of the blas_len arguments appeared to work, but recently gcc has started to optimise more heavily, leading to stack overwrites when these arguments are not used.
The same bug affects Armadillo, R, and a lot of other software in C and C++ that uses LAPACK:
CC: @dodomorandi
The text was updated successfully, but these errors were encountered: