https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68594
Bug ID: 68594
Summary: [regression] libfortran WRITE() ERR option causing
segfault when used twice
Product: gcc
Version: 4.8.4
Status: UNCONFIRMED
Severity: major
Priority: P3
Component: libfortran
Assignee: unassigned at gcc dot gnu.org
Reporter: luca.dallolio at gmail dot com
Target Milestone: ---
Created attachment 36861
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=36861&action=edit
double WRITE with ERR option causing segfault in Trusty
A simple fortran program causes a segmentation fault under Ubuntu 14.04 Trusty
but works fine in Ubuntu 12.04 Precise.
The problem can be reproduced by using the ERR option of the WRITE command
twice :
PROGRAM WRITESEGF2
WRITE (*,'(I8)',ERR=40) 3.14
40 CONTINUE
WRITE (*,'(I8)',ERR=80) 3.14
80 CONTINUE
END
Here the compilation options :
gfortran -O0 -g -fcheck=all -o writesegfault2 writesegfault2.f
This is the output in Trusty :
(trusty64)$ ./writesegfault2
Program received signal SIGSEGV: Segmentation fault - invalid memory reference.
Backtrace for this error:
#0 0x7F1B871EA777
#1 0x7F1B871EAD7E
#2 0x7F1B86E42D3F
#3 0x7F1B86EA41B4
#4 0x7F1B872A1D1E
#5 0x7F1B872AC43C
#6 0x7F1B872AE558
#7 0x40088E in writesegf2 at writesegfault2.f:4
Segmentation fault (core dumped)
GDB says :
(trusty64)$ gdb ./writesegfault2
Program received signal SIGSEGV, Segmentation fault.
__memcpy_sse2_unaligned () at
../sysdeps/x86_64/multiarch/memcpy-sse2-unaligned.S:153
153 ../sysdeps/x86_64/multiarch/memcpy-sse2-unaligned.S: No such file or
directory.
In Precise there is simply no output, as expected :
(precise64)$ ./writesegfault2
(precise64)$
A single WRITE with ERR label seems to work fine, even in Trusty :
PROGRAM WRITEOK
WRITE (*,'(I8)',ERR=40) 3.14
40 CONTINUE
WRITE (*,'(I8)') 3
WRITE (*,'(E8.3)') 3.14
END
(trusty64)$ ./writeok
3
.314E+01
Here is another variant causing the problem :
PROGRAM WRITESEGF
WRITE (*,'(I8)',ERR=40) 3.14
40 CONTINUE
WRITE (*,'(I8)') 3.14
END
Another segmentation fault seems to be caused by a WRITE with ERR label,
folowed by a simple conversion (should be an error instead) :
(trusty64)$ ./writesegfault
Program received signal SIGSEGV: Segmentation fault - invalid memory reference.
Backtrace for this error:
#0 0x7FF7F2BCB777
#1 0x7FF7F2BCBD7E
#2 0x7FF7F2823D3F
#3 0x7FF7F28851B4
#4 0x7FF7F2C82D1E
#5 0x7FF7F2C8D43C
#6 0x7FF7F2C8F558
#7 0x40088E in MAIN__ at writesegfault.f:4
Segmentation fault (core dumped)
Without using labels, it should be an error:
PROGRAM WRITEERR
WRITE (*,'(I8)') 3.14
END
When running this, in both Trusty and Precise :
(trusty64)$ ./writeerror
At line 2 of file writeerror.f (unit = 6, file = 'stdout')
Fortran runtime error: Expected INTEGER for item 1 in formatted transfer, got
REAL
(I8)
^
All this was reproduced using different versions of gfortran : 4.6.3 in Precise
and 4.8.4 in Trusty.
Nothing changes by switching gfortran (backporting 4.8 in Precise and
installing 4.6 in Trusty), changing architecture (32 and 64 bit), moving
binaries.
The issue stays the same, so it should be a libgfortran or glibc issue...