https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66756
Bug ID: 66756 Summary: libgfortran: ThreadSanitizer: lock-order-inversion Product: gcc Version: 5.1.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: libfortran Assignee: unassigned at gcc dot gnu.org Reporter: Joost.VandeVondele at mat dot ethz.ch Target Milestone: --- After building libgfortran with -fsanitize=thread (see below) any Fortran program that opens a file fails with: > cat test.f90 OPEN(10,FILE="foo.bar") CLOSE(10) END > gfortran -fsanitize=thread -g test.f90 > ./a.out WARNING: ThreadSanitizer: lock-order-inversion (potential deadlock) (pid=28274) Cycle in lock order graph: M20 (0x7f4472668d80) => M21 (0x7d580000f3d0) => M20 Mutex M21 acquired here while holding mutex M20 in main thread: #0 pthread_mutex_lock /data/vjoost/toolchain-sanitize/build/gcc-5.1.0/libsanitizer/sanitizer_common/sanitizer_common_interceptors.inc:2988 (libtsan.so.0+0x0000000349a6) #1 __gthread_mutex_lock ../libgcc/gthr-default.h:748 (libgfortran.so.3+0x000000160c4b) #2 insert_unit /data/vjoost/toolchain-sanitize/build/gcc-5.1.0/libgfortran/io/unit.c:220 (libgfortran.so.3+0x000000160c4b) #3 get_external_unit /data/vjoost/toolchain-sanitize/build/gcc-5.1.0/libgfortran/io/unit.c:330 (libgfortran.so.3+0x000000160dc5) #4 _gfortrani_find_or_create_unit /data/vjoost/toolchain-sanitize/build/gcc-5.1.0/libgfortran/io/unit.c:394 (libgfortran.so.3+0x000000160ff8) #5 _gfortran_st_open /data/vjoost/toolchain-sanitize/build/gcc-5.1.0/libgfortran/io/open.c:829 (libgfortran.so.3+0x000000154f47) #6 MAIN__ /data/vjoost/gnu/bugs/test.f90:1 (a.out+0x000000400a67) #7 main /data/vjoost/gnu/bugs/test.f90:4 (a.out+0x000000400b30) Hint: use TSAN_OPTIONS=second_deadlock_stack=1 to get more informative warning message Mutex M20 acquired here while holding mutex M21 in main thread: #0 pthread_mutex_lock /data/vjoost/toolchain-sanitize/build/gcc-5.1.0/libsanitizer/sanitizer_common/sanitizer_common_interceptors.inc:2988 (libtsan.so.0+0x0000000349a6) #1 __gthread_mutex_lock ../libgcc/gthr-default.h:748 (libgfortran.so.3+0x0000001644e6) #2 _gfortrani_find_file /data/vjoost/toolchain-sanitize/build/gcc-5.1.0/libgfortran/io/unix.c:1613 (libgfortran.so.3+0x0000001644e6) #3 _gfortrani_new_unit /data/vjoost/toolchain-sanitize/build/gcc-5.1.0/libgfortran/io/open.c:486 (libgfortran.so.3+0x00000015427f) #4 already_open /data/vjoost/toolchain-sanitize/build/gcc-5.1.0/libgfortran/io/open.c:672 (libgfortran.so.3+0x00000015502e) #5 _gfortran_st_open /data/vjoost/toolchain-sanitize/build/gcc-5.1.0/libgfortran/io/open.c:837 (libgfortran.so.3+0x00000015502e) #6 MAIN__ /data/vjoost/gnu/bugs/test.f90:1 (a.out+0x000000400a67) #7 main /data/vjoost/gnu/bugs/test.f90:4 (a.out+0x000000400b30) SUMMARY: ThreadSanitizer: lock-order-inversion (potential deadlock) ../libgcc/gthr-default.h:748 __gthread_mutex_lock To build the sanitized libgfortran one first builds gcc, followed by the equivalent of: cd /data/vjoost/toolchain-sanitize/build/gcc-5.1.0/obj/x86_64-unknown-linux-gnu/libgfortran make clean make CFLAGS="-std=gnu99 -g -O2 -fsanitize=thread " FCFLAGS="-g -O2 -fsanitize=thread" CXXFLAGS="-std=gnu99 -g -O2 -fsanitize=thread " LDFLAGS="-B`pwd`/../libsanitizer/tsan/.libs/ -Wl,-rpath,`pwd`/../libsanitizer/tsan/.libs/ -fsanitize=thread" make install