Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

undefined behaviour due to BLAS prototypes missing "hidden" variables required by Fortran #31

Open
conradsnicta opened this issue Jun 13, 2019 · 0 comments

Comments

@conradsnicta
Copy link

The prototypes for Fortran BLAS and LAPACK functions appear to be incomplete in SuperLU. This can lead to undefined behaviour with recent releases of gcc/gfortran 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 so-called "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 SuperLU, the current prototype for dgemm in
https://github.com/xiaoyeli/superlu/blob/master/SRC/slu_ddefs.h
is defined as:
extern int dgemm_(const char*, const char*, const int*, const int*, const int*, const double*, const double*, const int*, const double*, const int*, const double*, double*, const int*);

But it probably should be:
extern int dgemm_(const char*, const char*, const int*, const int*, const int*, const double*, const double*, const int*, const double*, const int*, const double*, double*, const int*, fort_len, fort_len);

where fort_len is typically a 32 bit unsigned int on 32 bit platforms, and 64 bit unsigned int on 64 bit platforms (eg. size_t). This does not apply to gcc versions <= 7, where it is always int.

Until recently, avoiding the use of these fort_len arguments appeared to work, but new versions of gcc/gfortran are more strict, leading to stack overwrites (and hence crashes) when these arguments are not used.

The same bug affects a lot of other software in C and C++ that uses BLAS / LAPACK:

eschnett pushed a commit to eschnett/superlu that referenced this issue Oct 13, 2022
compile fix on OSX/clang - i.e without OpenMP
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant