segmentation fault, gfortran.

407 views
Skip to first unread message

diego

unread,
Apr 7, 2008, 6:39:51 AM4/7/08
to GNU Fortran
Hi all,

I'm the developer of a fluid dynamics code in Fortran 90.
The code has a long history and has been successfully employed for
years. Compiled with both PGI and intel fortran it apparently works
flawlessly.
Since I now switched to Eclipse/Photran for development, I found it
good to switch to the GNU compiler and debugger.
I am now experiencing some problems with the gfortran generated
executable.

If I compile with -O0 -g flags I get segmentation fault, and precisely
on a line of a function which does a simple "max" operation. To make
it simple, the function is called by a loop, and the SIGSEGV occurs
after a lot of loop iterations.
If I compile with -O3 -g the code stops in the same place, but it
gives me the backtrace I'm attaching down here.

any clues? I could go on using different compilers but that would be a
bit annoying for ease of development..

many thanks in advance

diego

_____________________-



*** glibc detected *** /home/diego/Work/Development/DNSNatu/Debug/
DNSNatu: free(): invalid pointer: 0xb6bf0000 ***
======= Backtrace: =========
/lib/libc.so.6[0xb76574b6]
/lib/libc.so.6(cfree+0x89)[0xb7659179]
/usr/lib/libgfortran.so.2(_gfortran_internal_free+0x21)[0xb77642a1]
/home/diego/Work/Development/DNSNatu/Debug/DNSNatu[0x8051217]
/home/diego/Work/Development/DNSNatu/Debug/DNSNatu[0x8068799]
/home/diego/Work/Development/DNSNatu/Debug/DNSNatu[0x80700ce]
/home/diego/Work/Development/DNSNatu/Debug/DNSNatu[0x804980b]
/home/diego/Work/Development/DNSNatu/Debug/DNSNatu[0x80824b7]
/lib/libc.so.6(__libc_start_main+0xe0)[0xb7606fe0]
/home/diego/Work/Development/DNSNatu/Debug/DNSNatu[0x8049021]
======= Memory map: ========
08048000-08084000 r-xp 00000000 08:11 13795367 /home/diego/Work/
Development/DNSNatu/Debug/DNSNatu
08084000-08085000 r--p 0003b000 08:11 13795367 /home/diego/Work/
Development/DNSNatu/Debug/DNSNatu
08085000-08086000 rw-p 0003c000 08:11 13795367 /home/diego/Work/
Development/DNSNatu/Debug/DNSNatu
08086000-080f6000 rw-p 08086000 00:00 0 [heap]
aab00000-aab21000 rw-p aab00000 00:00 0
aab21000-aac00000 ---p aab21000 00:00 0
aacdf000-b75f1000 rw-p aacdf000 00:00 0
b75f1000-b771e000 r-xp 00000000 08:01 4309004 /lib/libc-2.6.1.so
b771e000-b771f000 r--p 0012c000 08:01 4309004 /lib/libc-2.6.1.so
b771f000-b7721000 rw-p 0012d000 08:01 4309004 /lib/libc-2.6.1.so
b7721000-b7724000 rw-p b7721000 00:00 0
b7724000-b772e000 r-xp 00000000 08:01 4309087 /lib/libgcc_s.so.1
b772e000-b7730000 rw-p 00009000 08:01 4309087 /lib/libgcc_s.so.1
b7730000-b7753000 r-xp 00000000 08:01 4309012 /lib/libm-2.6.1.so
b7753000-b7755000 rw-p 00022000 08:01 4309012 /lib/libm-2.6.1.so
b7755000-b77ea000 r-xp 00000000 08:01 2752626 /usr/lib/
libgfortran.so.2.0.0
b77ea000-b77ec000 rw-p 00095000 08:01 2752626 /usr/lib/
libgfortran.so.2.0.0
b77ec000-b788f000 r-xp 00000000 08:01 2752630 /usr/lib/libblas.so.
3.1.1
b788f000-b7891000 rw-p 000a2000 08:01 2752630 /usr/lib/libblas.so.
3.1.1
b7891000-b7e71000 r-xp 00000000 08:01 2752646 /usr/lib/liblapack.so.
3.1.1
b7e71000-b7e75000 rw-p 005e0000 08:01 2752646 /usr/lib/liblapack.so.
3.1.1
b7e75000-b7f83000 rw-p b7e75000 00:00 0
b7f9d000-b7fb7000 r-xp 00000000 08:01 4310667 /lib/ld-2.6.1.so
b7fb7000-b7fb9000 rw-p 0001a000 08:01 4310667 /lib/ld-2.6.1.so
bfec8000-bfede000 rw-p bfec8000 00:00 0 [stack]
ffffe000-fffff000 r-xp 00000000 00:00 0 [vdso]

FX

unread,
Apr 7, 2008, 6:49:49 AM4/7/08
to gnu-f...@googlegroups.com
Hi Diego,

What version of gfortran are you using? What platform (CPU & OS) are
you running on? (Both questions are answered by the output of
"gfortran -v".)

> If I compile with -O0 -g flags I get segmentation fault, and precisely
> on a line of a function which does a simple "max" operation. To make
> it simple, the function is called by a loop, and the SIGSEGV occurs
> after a lot of loop iterations.

Sounds like an out-of-bounds array access to me (but of course,
without seeing code, it's just guessing). Have you tried to compile
with -O0 -g -fbounds-check and see if it gives you a runtime error
message? (which would include a location for the out-of-bounds access)

> /usr/lib/libgfortran.so.2(_gfortran_internal_free+0x21)[0xb77642a1]
> /home/diego/Work/Development/DNSNatu/Debug/DNSNatu[0x8051217]
> /home/diego/Work/Development/DNSNatu/Debug/DNSNatu[0x8068799]
> /home/diego/Work/Development/DNSNatu/Debug/DNSNatu[0x80700ce]
> /home/diego/Work/Development/DNSNatu/Debug/DNSNatu[0x804980b]
> /home/diego/Work/Development/DNSNatu/Debug/DNSNatu[0x80824b7]

These frames are the one that would be interesting: why isn't there
any source line information? Are you sure you compiled everything with
-g?

FX

--
FX Coudert
http://www.homepages.ucl.ac.uk/~uccafco/

diego

unread,
Apr 7, 2008, 7:16:58 AM4/7/08
to GNU Fortran
Hi FX and thanks by now for the quick reply

>
> What version of gfortran are you using? What platform (CPU & OS) are
> you running on? (Both questions are answered by the output of
> "gfortran -v".)

sorry, I forgot it in the previous..here it is
Using built-in specs.
Target: i586-suse-linux
Configured with: ../configure --enable-threads=posix --prefix=/usr --
with-local-prefix=/usr/local --infodir=/usr/share/info --mandir=/usr/
share/man --libdir=/usr/lib --libexecdir=/usr/lib --enable-
languages=c,c++,objc,fortran,obj-c++,java,ada --enable-
checking=release --with-gxx-include-dir=/usr/include/c++/4.2.1 --
enable-ssp --disable-libssp --disable-libgcj --with-slibdir=/lib --
with-system-zlib --enable-shared --enable-__cxa_atexit --enable-
libstdcxx-allocator=new --disable-libstdcxx-pch --program-suffix=-4.2
--enable-version-specific-runtime-libs --without-system-libunwind --
with-cpu=generic --host=i586-suse-linux
Thread model: posix
gcc version 4.2.1 (SUSE Linux)

the OS is openSUSE 10.3
the gfortran package is that distributed with the os itself (maybe
outdated)

> > If I compile with -O0 -g flags I get segmentation fault, and precisely
> > on a line of a function which does a simple "max" operation. To make
> > it simple, the function is called by a loop, and the SIGSEGV occurs
> > after a lot of loop iterations.

>
> Sounds like an out-of-bounds array access to me (but of course,
> without seeing code, it's just guessing). Have you tried to compile
> with -O0 -g -fbounds-check and see if it gives you a runtime error
> message? (which would include a location for the out-of-bounds access)

I thought about it indeed ... but it would be strange, 'cause the same
source compiled with pgf90 or ifort run and works well
anyhow, I added the bounds check and it shows up the same. To be
precise, this is the backtrace with -O0 I get by eclipse

No symbol "new" in current context.
Stopped due to shared library event
Stopped due to shared library event
Cannot access memory at address 0x4


> > /usr/lib/libgfortran.so.2(_gfortran_internal_free+0x21)[0xb77642a1]
> > /home/diego/Work/Development/DNSNatu/Debug/DNSNatu[0x8051217]
> > /home/diego/Work/Development/DNSNatu/Debug/DNSNatu[0x8068799]
> > /home/diego/Work/Development/DNSNatu/Debug/DNSNatu[0x80700ce]
> > /home/diego/Work/Development/DNSNatu/Debug/DNSNatu[0x804980b]
> > /home/diego/Work/Development/DNSNatu/Debug/DNSNatu[0x80824b7]
>
> These frames are the one that would be interesting: why isn't there
> any source line information? Are you sure you compiled everything with
> -g?

yes I did, but i also added -O3 to that run.

FX

unread,
Apr 7, 2008, 7:23:10 AM4/7/08
to gnu-f...@googlegroups.com
> anyhow, I added the bounds check and it shows up the same.

Could you download a more recent version of gfortran to see if it was
one of the bugs fixed for the 4.3.0 release? I suggest downloading
binaries from http://gcc.gnu.org/wiki/GFortranBinaries (you don't need
to be administrator on your computer to install them and use them).

Tobias Burnus

unread,
Apr 7, 2008, 8:25:59 AM4/7/08
to gnu-f...@googlegroups.com
FX wrote:
>> anyhow, I added the bounds check and it shows up the same.
>>
> Could you download a more recent version of gfortran to see if it was
> one of the bugs fixed for the 4.3.0 release? I suggest downloading
> binaries from http://gcc.gnu.org/wiki/GFortranBinaries (you don't need
> to be administrator on your computer to install them and use them).
>
Alternatively, there are gfortran 4.3 builds for openSUSE 10.3 at:
http://download.opensuse.org/repositories/home:/rguenther/openSUSE_10.3/

They are slightly older than the builds at
http://gcc.gnu.org/wiki/GFortranBinaries, but not much.

Tobias

diego

unread,
Apr 7, 2008, 12:10:35 PM4/7/08
to GNU Fortran
I updated the gfortran to v4.3 and all the gcc-related things
contained in the repository.
Now the program stops even earlier with this runtime error:

At line 298 of file ../src/clWorld2D.F90 (unit = 6, file = 'stdout')
Fortran runtime error: Unit number in I/O statement too large

did the allowed numers for I/O units change in v4.3?

thank you

diego

On 7 Apr, 14:25, Tobias Burnus <bur...@net-b.de> wrote:
> FX wrote:
> >> anyhow, I added the bounds check and it shows up the same.
>
> > Could you download a more recent version of gfortran to see if it was
> > one of the bugs fixed for the 4.3.0 release? I suggest downloading
> > binaries fromhttp://gcc.gnu.org/wiki/GFortranBinaries(you don't need
> > to be administrator on your computer to install them and use them).
>
> Alternatively, there are gfortran 4.3 builds for openSUSE 10.3 at:http://download.opensuse.org/repositories/home:/rguenther/openSUSE_10.3/
>
> They are slightly older than the builds athttp://gcc.gnu.org/wiki/GFortranBinaries, but not much.
>
> Tobias

Tobias Burnus

unread,
Apr 7, 2008, 12:39:32 PM4/7/08
to gnu-f...@googlegroups.com
diego wrote:
> I updated the gfortran to v4.3 and all the gcc-related things
> contained in the repository.
> Now the program stops even earlier with this runtime error:
>
> At line 298 of file ../src/clWorld2D.F90 (unit = 6, file = 'stdout')
> Fortran runtime error: Unit number in I/O statement too large
>
> did the allowed numers for I/O units change in v4.3?
>
Two questions:
a) You do not use things like -malign-double or -mnoalign-double or
similar, do you?
b) You compiled everything with that version of the compiler or do you
have some old libraries lying around which were compiled with a
different version?

According to Jerry, "This could be caused by an alignment problem with
the ioparm def". The question is only why it happens.

In principle, 4.3.0 (release) should support the same units as older
versions though the ABI might be not 100% the same (which is the case
for old 4.3.0 developer releases).

Tobias

diego

unread,
Apr 8, 2008, 4:08:33 AM4/8/08
to GNU Fortran
>
> Two questions:
> a) You do not use things like -malign-double or -mnoalign-double or
> similar, do you?

No I don't.

> b) You compiled everything with that version of the compiler or do you
> have some old libraries lying around which were compiled with a
> different version?

All the sources written by myself are compiled with this version, but,
yes, I suppose that the rest is compiled with the older version.

> In principle, 4.3.0 (release) should support the same units as older
> versions though the ABI might be not 100% the same (which is the case
> for old 4.3.0 developer releases).

by now, many thanks for your patience.

diego

unread,
Apr 8, 2008, 8:34:13 AM4/8/08
to GNU Fortran
this is what I get from the linker stage

/usr/lib/gcc/i586-suse-linux/4.3/../../../../i586-suse-linux/bin/ld:
warning: libgfortran.so.2, needed by /usr/lib/gcc/i586-suse-linux/
4.3/../../../liblapack.so, may conflict with libgfortran.so.3
Reply all
Reply to author
Forward
0 new messages