[Bug libgomp/81336] New: OpenMP crash if -fno-underscoring is used in gfortran

bburgerm at googlemail dot com gcc-bugzilla@gcc.gnu.org
Thu Jul 6 08:31:00 GMT 2017


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81336

            Bug ID: 81336
           Summary: OpenMP crash if -fno-underscoring is used in gfortran
           Product: gcc
           Version: 6.3.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libgomp
          Assignee: unassigned at gcc dot gnu.org
          Reporter: bburgerm at googlemail dot com
                CC: jakub at gcc dot gnu.org
  Target Milestone: ---

Created attachment 41692
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=41692&action=edit
Test executable to show the bug

If I use OpenMP nested locks in Fortran code which is compiled with the
"-fno-underscoring" option invalid memory is accessed which leads to incorrect
results or crashes.

The attached program shows the problem at least on linux (32 and 64 bits). If
compiled with "-fopenmp -fno-underscoring" the second element of the array is
modified during omp_init_nest_lock. If "-fno-underscoring" is omitted the
result is OK. Same bug is visible with gfortran 4.9.2.

I have read the warning about usage of -fno-underscoring, but it talks about
possible incompatibilities with system libraries. At least libraries shipped
with gfortran should work correctly in this case.

I could track down the problem to the OpenMP library which has a different
interface for C and Fortran:
- C uses the symbol "omp_init_nest_lock" is used and expects as argument a
pointer to a 16 byte structure.
- Fortran uses with default options "omp_init_nest_lock_" which expects a
pointer to a 8 byte integer which is used as a pointer to the 16 byte
structure.
If -fno-underscoring is used Fortran uses incorrectly the C version with a
different interface.

As workaround I used explicit iso_c_binding interfaces as this is currently the
only method to tell gfortran the symbol name to use independent of program
options:

      use iso_c_binding, only : c_int64_t

      integer, parameter :: omp_nest_lock_kind = c_int64_t

      interface
         subroutine omp_init_nest_lock(nvar)
     +      bind(C,name='omp_init_nest_lock_')
         import omp_nest_lock_kind
         integer(omp_nest_lock_kind), intent(  out) :: nvar
         end subroutine omp_init_nest_lock
      end interface
      ... for omp_destroy_nest_lock, set and unset

A possible solution would be to use this interface in omp_lib.f90 (but
unfortunately not in omp_lib.h because of strict C interoperability checks of
gfortran)


More information about the Gcc-bugs mailing list