https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98046
Bug ID: 98046 Summary: lock in libpthread occurs with gcc-fortran and atlas-lapack Product: gcc Version: 10.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: fortran Assignee: unassigned at gcc dot gnu.org Reporter: anthony.debeus at gmail dot com Target Milestone: --- When running the following code under kernel 5.8.18-1-MANJARO (among others) and gcc-fortran 10.2.0 PROGRAM bugs USE badwrite x=AC(0) write(*,*) 'x: ',x ! this works write (*,*) '0: ',AC(0) !this does not STOP END MODULE badwrite CONTAINS function AC(m2) result(c) INTEGER,INTENT(IN) :: m2 write(*,*) m2 !killer statement with lapack or blas linked ONLY with atlas c = m2+3 end function AC END MODULE badwrite compiled with gfortran -c -llapack badwrite.f90 gfortran -llapack badwrite.f90 bugs.f90 should result in 0 x: 3.0000000 0: 0 3.00000000 However with the -llapack library (or the blas library, and possibly other external libraries) the result is 0 x: 3.000000 (program hangs here) Adding the -ggdb flag, running in gdb and interrupting with ^C results in Starting program: /home/me/build/bugs.lib90/a.out [Thread debugging using libthread_db enabled] Using host libthread_db library "/usr/lib/libthread_db.so.1". 0 x: 3.00000000 ^C Program received signal SIGINT, Interrupt. 0x00007ffff6baddb0 in __lll_lock_wait () from /usr/lib/libpthread.so.0 The two writes are deadlocked. Conditions: (1) Only happens with an external library linked in, so gfortran -c badwrite.f90 gfortran badwrite.f90 bugs.f90 runs normally without hanging (2) Removing the write statement in the function AC also removes the hang. (3) Separating the writes, as in the first statement with x=AC(0) then write(*,*) x, removes the deadlock/hang (4) When using the "regular" lapack and blas libraries, the problem does not occur. (5) The problem does not occur with pgfortran (aka nvfortran) 20.7-0 LLVM (6) Changing kernels to 5.7 or 5.9 series on the same machine does not solve the problem. This problem was originally reported on https://www.linuxquestions.org/questions/linux-general-1/lock-in-libpthread-occurs-only-on-one-arch-installation-only-with-gcc-fortran-4175685889/ before discovering that it was triggered by the combination of gcc+atlas lapack. Because of condition (5) this is reported as a gcc-fortran bug.