runtime segmentation fault for formatted write statement

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

runtime segmentation fault for formatted write statement

Christopher S. Talley
I have a legacy FORTRAN code that compiles on Compaq Visual FORTRAN 6.6, Intel FORTRAN, and g95. I am trying to get this code to build with gfortran-8.3.0 and I keep getting the following runtime error:

Program received signal SIGSEGV: Segmentation fault - invalid memory reference.

Backtrace for this error:
#0  0xf7f82fff in ???
#1  0x805d238 in format_hash
        at ../../../../gcc-8.3.0/libgfortran/io/format.c:128
#2  0x805d238 in find_parsed_format
        at ../../../../gcc-8.3.0/libgfortran/io/format.c:163
#3  0x804e4c8 in data_transfer_init
        at ../../../../gcc-8.3.0/libgfortran/io/transfer.c:2842
#4  0x8048b38 in MAIN__
        at debug/example.for:6
#5  0x8048b8a in main
        at debug/example.for:34
Segmentation fault (core dumped)

I’ve created the following example that reproduces the problem when compiled as follows:
> gfortran example.for -std=gnu -cpp -m32 -fdefault-real-8 -O0 -g3 -malign-double -ftracer -fcaller-saves --static -o example

=============================
C  example.for

       PROGRAM MAIN

C     SUPPLY HEADER INFORMATION
        WRITE(*,10)

C********************************************************************
10    FORMAT(12X,'*************************************************',/,
     &   12X,'             X X X X X (XXXXXXX XXX)              ',/,
     &   12X,'     XXXXXXXXXXX XXXXX XXXXXX XXXXXXXXXX XXXXXXX  ',/,
     &   12X,'                XXXXXXXXX XXXX                      ',/,
C    
#ifdef __G95__
     &   12X,'            Built with G95 Compiler               ',/,
#endif
#ifdef __GFORTRAN__
     &   12X,'            Built with GFORTRAN Compiler          ',/,
#endif
#ifdef __INTEL_COMPILER
     &   12X,'           Built with Intel Compiler              ',/,
#endif
#ifdef __VF_VER
     &   12X,'         Built with CVF 6.6 Compiler              ',/,
#endif    
     &   12X,'                                                  ',/,
     &   12X,'   XXXXXXXXX XX XXXX/XXXXXXXX XXXXX XXXXXX XXXXXX ',/,
     &   12X,'   XXXXXXXXX (X) XX XXXXXXXX XXXXX XXXXXX XXXXXX  ',/,
     &   12X,'                                                  ',/,
     &   12X,' X XXXXXXXXXXX XXXXXXXX XXXXXXX XX XXXXXXXXX XXXX ',/,
     &   12X,' XXXXX, XXXXXXXXX, XXXXXXXXXXXX XXX XXXXXXXXXXXXXX',/,
     &   12X,' XX X XXXX XXXXXXX.                               ',/,
     &   12X,'*************************************************',//)
       END PROGRAM
=============================

Thanks,

Chris

Reply | Threaded
Open this post in threaded view
|

Re: runtime segmentation fault for formatted write statement

Steve Kargl
On Tue, Apr 09, 2019 at 04:30:23PM +0000, Christopher S. Talley wrote:
>
> I’ve created the following example that reproduces the problem
> when compiled as follows:
> gfortran example.for -std=gnu -cpp -m32 -fdefault-real-8 -O0 -g3 \
> -malign-double -ftracer -fcaller-saves --static -o example
>

What happens if you remove all of the questionable options
that you're using, and simply add -Wall -fcheck=all?

--
Steve
Reply | Threaded
Open this post in threaded view
|

Re: runtime segmentation fault for formatted write statement

Bernhard Reutner-Fischer
On Tue, 9 Apr 2019 18:39:47 -0700
Steve Kargl <[hidden email]> wrote:

> On Tue, Apr 09, 2019 at 04:30:23PM +0000, Christopher S. Talley wrote:
> >
> > I’ve created the following example that reproduces the problem
> > when compiled as follows:
> > gfortran example.for -std=gnu -cpp -m32 -fdefault-real-8 -O0 -g3 \
> > -malign-double -ftracer -fcaller-saves --static -o example
> >  
>
> What happens if you remove all of the questionable options
> that you're using, and simply add -Wall -fcheck=all?
>

Your libgfortran is most likely not built with -malign-double so you
should rather not use that in objects calling into libgfortran.
Reply | Threaded
Open this post in threaded view
|

Re: runtime segmentation fault for formatted write statement

Bernhard Reutner-Fischer
On 10 April 2019 11:02:16 CEST, Bernhard Reutner-Fischer <[hidden email]> wrote:

>On Tue, 9 Apr 2019 18:39:47 -0700
>Steve Kargl <[hidden email]> wrote:
>
>> On Tue, Apr 09, 2019 at 04:30:23PM +0000, Christopher S. Talley
>wrote:
>> >
>> > I’ve created the following example that reproduces the problem
>> > when compiled as follows:
>> > gfortran example.for -std=gnu -cpp -m32 -fdefault-real-8 -O0 -g3 \
>> > -malign-double -ftracer -fcaller-saves --static -o example
>> >  
>>
>> What happens if you remove all of the questionable options
>> that you're using, and simply add -Wall -fcheck=all?
>>
>
>Your libgfortran is most likely not built with -malign-double so you
>should rather not use that in objects calling into libgfortran.

Some previous discussion WRT malign-double and IO, fwiw:
http://gcc.gnu.org/ml/fortran/2007-02/msg00026.html
Reply | Threaded
Open this post in threaded view
|

Re: runtime segmentation fault for formatted write statement

Christopher S. Talley
In reply to this post by Bernhard Reutner-Fischer
I removed the -malign-double and that fixed the problem, although I now have another problem for a separate thread.

Thanks!
Chris


> On Apr 10, 2019, at 4:02 AM, Bernhard Reutner-Fischer <[hidden email]> wrote:
>
> On Tue, 9 Apr 2019 18:39:47 -0700
> Steve Kargl <[hidden email]> wrote:
>
>> On Tue, Apr 09, 2019 at 04:30:23PM +0000, Christopher S. Talley wrote:
>>>
>>> I’ve created the following example that reproduces the problem
>>> when compiled as follows:
>>> gfortran example.for -std=gnu -cpp -m32 -fdefault-real-8 -O0 -g3 \
>>> -malign-double -ftracer -fcaller-saves --static -o example
>>>
>>
>> What happens if you remove all of the questionable options
>> that you're using, and simply add -Wall -fcheck=all?
>>
>
> Your libgfortran is most likely not built with -malign-double so you
> should rather not use that in objects calling into libgfortran.