Bug with ISO_C_BINDING on Mac OS?
Janus Weil
janus@gcc.gnu.org
Sat Jun 1 10:46:00 GMT 2013
Hi all,
attached are two small test cases (Fortran & C), which try to open a
bz2 file for reading (they require a, possibly empty, file 'test.bz2'
in the same dir). The Fortran version uses ISO_C_BINDING interfaces
for the calls to 'fopen' and 'BZ2_bzReadOpen', and both work as
expected on Linux (x86_64):
$ gcc-4.9 testBz2.c -lbz2
$ ./a.out
#1
#2
#3
$ gfortran-4.9 testBz2.f90 -lbz2
$ ./a.out
#1
#2
#3
(Also with other compilers btw. The Fortran code has been reduced from
a larger code which successfully reads bz2 files in this way.)
On Mac OS (x86_64-apple-darwin11.4.2), the C version still works,
while the Fortran version produces a segfault in the call to
BZ2_bzReadOpen:
$ ./a.out
#1
#2
Program received signal SIGSEGV: Segmentation fault - invalid memory reference.
Valgrind shows:
#1
#2
==1773== Invalid read of size 2
==1773== at 0x100354455: ferror (in /usr/lib/system/libsystem_c.dylib)
==1773== by 0x100026774: BZ2_bzReadOpen (in /usr/lib/libbz2.1.0.dylib)
==1773== by 0x100000DD7: MAIN__ (testBz2.f90:38)
==1773== by 0x100000E7A: main (testBz2.f90:42)
==1773== Address 0x3fdef0 is not stack'd, malloc'd or (recently) free'd
==1773==
==1773==
==1773== Process terminating with default action of signal 11 (SIGSEGV)
==1773== General Protection Fault
==1773== at 0x1002D46CD:
misaligned_stack_error_entering_dyld_stub_binder (in
/usr/lib/system/libdyld.dylib)
==1773== by 0x100148027: ??? (in
/usr/local/lib/gcc/x86_64-apple-darwin11.4.2/4.9.0/libgfortran.3.dylib)
==1773== by 0x100026774: BZ2_bzReadOpen (in /usr/lib/libbz2.1.0.dylib)
==1773== by 0x100000DD7: MAIN__ (testBz2.f90:38)
==1773== by 0x100000E7A: main (testBz2.f90:42)
Can anyone give me a hint what is going on, or how I can debug it? Is
this a gfortran bug with ISO_C_BINDING on Mac OS or some other
problem? Are my ISO_C_BINDING interfaces correct (as mentioned, they
work fine on Linux)? Can anyone reproduce the segfault on Mac OS?
Cheers,
Janus
-------------- next part --------------
A non-text attachment was scrubbed...
Name: testBz2.c
Type: text/x-csrc
Size: 365 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/fortran/attachments/20130601/c6c1f948/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: testBz2.f90
Type: application/octet-stream
Size: 1005 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/fortran/attachments/20130601/c6c1f948/attachment.obj>
More information about the Fortran
mailing list