Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

segfault when printing string component

Michael_G_1
Beginner
823 Views
The following "minimal example" causes a segfault if compiled with ifort 17.0.4 20170411 on 64-bit Linux (Ubuntu 16.04) goerz@mlhpc2:~> uname -a Linux mlhpc2 4.4.0-36-generic #55-Ubuntu SMP Thu Aug 11 18:01:55 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux This is on a machine with 80 cores, the CPU information on the highest core is processor : 79 vendor_id : GenuineIntel cpu family : 6 model : 47 model name : Intel(R) Xeon(R) CPU E7- 4870 @ 2.40GHz stepping : 2 microcode : 0x37 cpu MHz : 1064.000 cache size : 30720 KB physical id : 7 siblings : 10 core id : 9 cpu cores : 10 apicid : 242 initial apicid : 242 fpu : yes fpu_exception : yes cpuid level : 11 wp : yes flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 cx16 xtpr pdcm pcid dca sse4_1 sse4_2 popcnt aes lahf_lm epb tpr_shadow vnmi flexpriority ept vpid dtherm ida arat bugs : clflush_monitor bogomips : 4788.04 clflush size : 64 cache_alignment : 64 address sizes : 44 bits physical, 48 bits virtual The program (see also attachment) reads as follows: program test implicit none integer, parameter :: sparsity_model_l = 10 integer, parameter :: op_subspace_l = 5 !integer, parameter :: op_subspace_l = 10 ! This works type op_matrix_t character(len=sparsity_model_l) :: sparsity_model character(len=op_subspace_l) :: subspace end type op_matrix_t type(op_matrix_t) :: obs call debug_op_matrix_t(obs) ! works (but not needed) obs%sparsity_model = '' ! commenting out either one ... obs%subspace = '' ! ... of these lines makes it work call debug_op_matrix_t(obs) ! crashes when printing subspace contains subroutine debug_op_matrix_t(var) type(op_matrix_t), intent(in) :: var write(*,'("obs = {")') write(*,'(A,A,A)') ' sparsity_model', ' = ', "'"//trim(var%sparsity_model)//"'" write(*,'(A,A,A)') ' subspace ', ' = ', "'"//trim(var%subspace)//"'" write(*,'("}")') end subroutine debug_op_matrix_t end program test The program was compiled with `ifort test.f90` and run as `./a.out`. In order to try to get slightly more information, I also compiled with `ifort -O0 -g -warn all -check all -debug all -traceback test.f90`, without any change in behavior. An example output is in the attachment, out1.txt The crash occurs after initializing the `subspace` component with the empty string, and then printing out the data structure. The problem disappears when setting `op_subspace_l` to 10 instead of 5. It also works with other compilers, or other versions of ifort (I tried ifort 11). Is this a compiler bug? Occasionally, the crash message changes. One message that was particularly concise was goerz@mlhpc2:~> ./a.out obs = { subspace = '' } obs = { a.out: malloc.c:2394: sysmalloc: Assertion `(old_top == initial_top (av) && old_size == 0) || ((unsigned long) (old_size) >= MINSIZE && prev_inuse (old_top) && ((unsigned long) old_end & (pagesize - 1)) == 0)' failed. Aborted (core dumped)
0 Kudos
7 Replies
FortranFan
Honored Contributor II
823 Views

Looks like a compiler bug in Intel Fortran to me

Intel now would prefer you to submit an incident at their Online Service Center (OSC):

https://supporttickets.intel.com/?lang=en-US

You may want to consider the following as a workaround until the issue is fixed in the compiler:

program test

   implicit none

   integer, parameter :: sparsity_model_l = 10
   integer, parameter :: op_subspace_l = 5

   type op_matrix_t
      character(len=sparsity_model_l) :: sparsity_model = "" ! Initialize
      character(len=op_subspace_l) :: subspace = ""          ! Initialize
   end type op_matrix_t

   type(op_matrix_t) :: obs

   call debug_op_matrix_t(obs)
   obs%sparsity_model = 'foo'
   obs%subspace = 'bar'
   call debug_op_matrix_t(obs)

contains

   subroutine debug_op_matrix_t(var)

      type(op_matrix_t), intent(in) :: var

      write(*,'("obs = {")')

      if ( len_trim(var%sparsity_model) > 0 ) then
         write(*,'(*(g0))') ' sparsity_model', ' = ', "'"//trim(var%sparsity_model)//"'"
      else
         write(*,'(*(g0))') ' sparsity_model', ' = ', "''"
      end if

      if ( len_trim(var%sparsity_model) > 0 ) then
         write(*,'(*(g0))') ' subspace ', ' = ', "'"//trim(var%subspace)//"'"
      else
         write(*,'(*(g0))') ' subspace ', ' = ', "''"
      end if

      write(*,'("}")')

   end subroutine debug_op_matrix_t

end program test

Upon execution,

obs = {
 sparsity_model = ''
 subspace  = ''
}
obs = {
 sparsity_model = 'foo'
 subspace  = 'bar'
}

 

0 Kudos
Johannes_Rieke
New Contributor III
823 Views

Hi, I can confirm the segfault for Windows (PSXE2017 update 4, 32/64, release and debug), too. Interestingly the bug only occurs for

  integer, parameter :: sparsity_model_l = 10
  integer, parameter :: op_subspace_l = 5

Other combinations like 11/5 or 12/6 works fine. @Michael You should play lottery ;-)

Is there a logical explanation, why 10/5 fails? Would the disassembly give a hint?

0 Kudos
Martyn_C_Intel
Employee
823 Views

I was initially unable to reproduce this, either on a system running RHEL 7.3 (with glibc 2.17, gcc 4.8) or a system with Ubuntu 14.04.  However, I was subsequently able to reproduce it on older systems running openSUSE 11.4 and RHEL 6.0, with glibc 2.11 and 2.12, gcc 4.5 and 4.4  respectively,  all with the same binary. The GNU libraries are linked dynamically, whereas the Intel libraries are linked statically, so this is suggestive that this is a consequence of the glibc version. 

Which glibc and gcc versions are you using, and are you able to test on another system with more recent ones?

0 Kudos
Michael_G_1
Beginner
823 Views

I think my glibc and gcc are fairly recent:

goerz@mlhpc2:~> ldd --version
ldd (Ubuntu GLIBC 2.23-0ubuntu9) 2.23
Copyright (C) 2016 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Written by Roland McGrath and Ulrich Drepper.
goerz@mlhpc2:~> gcc --version
gcc (Ubuntu 5.4.0-6ubuntu1~16.04.4) 5.4.0 20160609
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

I don't think I have access to any system with newer versions than that at the moment.

0 Kudos
Johannes_Rieke
New Contributor III
823 Views

@Martyn, if this issue is depending on the glibc version, why will this segfault be visible on Windows OS? In #3 I showed that it occurs on Windows also.
 

0 Kudos
Johannes_Rieke
New Contributor III
823 Views

If it may help: On Mint 17.3 (Ubuntu 14 based, glibc 2.19, gcc 4.84) with PSXE2017 update 4 the segfault occurs, with PSXE2016 no segfault occurs. I assume, like FortranFan before, that this is a bug in PSXE2017. That the segfault occurs on Windows OS too confirms me in that point.

obs = {
 sparsity_model = ''
 subspace  = ''
}
obs = {
 sparsity_model = ''
forrtl: severe (174): SIGSEGV, segmentation fault occurred
Image              PC                Routine            Line        Source             
a.out              00000000004031F4  Unknown               Unknown  Unknown
libpthread-2.19.s  00007FF27130F330  Unknown               Unknown  Unknown
a.out              000000000048883B  Unknown               Unknown  Unknown
a.out              000000000042D961  Unknown               Unknown  Unknown
a.out              000000000040D4E5  Unknown               Unknown  Unknown
a.out              0000000000402F60  Unknown               Unknown  Unknown
a.out              000000000040299E  Unknown               Unknown  Unknown
libc-2.19.so       00007FF270F57F45  __libc_start_main     Unknown  Unknown
a.out              00000000004028A9  Unknown               Unknown  Unknown
*** Error in `./a.out': free(): invalid pointer: 0x00000000009d9010 ***
Aborted

 

0 Kudos
Devorah_H_Intel
Moderator
823 Views

Please submit bug reports at Online Service Center.

Thank you,

0 Kudos
Reply