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

SIGSEGV at end of program, after successful execution

gregfi04
Beginner
587 Views
Hi,

I'm porting a relatively simple (~400 line), albeit old, code from HP-UX to Linux/ifort. It executes successfully, reproducing the same results as the HP-UX code, but it segfaults at the very end (END PROGRAM) of the code. Using the debugger, here are the last three lines it goes through:

998 READ (5,100,END=999) TITLE
...
...
...
999 CONTINUE
END PROGRAM

Any ideas on what may be causing this?

Greg
0 Kudos
4 Replies
Steven_L_Intel1
Employee
587 Views
Stack corruption due to coding error would be my guess. Using the debugger, switch to instruction mode and nexti (I think?) through the code at the end of the program - does it get the segfault on the return to the OS?

Try compiling with "-check bounds -gen-interface -warn interface" and see what you get.
0 Kudos
gregfi04
Beginner
587 Views
Steve,

Compiling with "-check bounds -gen-interface -warn interface" doesn't yield any new error messages or different runtime behavior. Here's the output of the debugger when I "si" through the end (the "(idb)"'s have been removed for brevity):

80 998 READ (5,100,END=999) TITLE
(idb) next
386 999 CONTINUE
(idb) si
387 END PROGRAM
0x0804d6c2 387 END PROGRAM
0x0804d6c3 387 END PROGRAM
0x08049fc1 in main ()
0x0804f1b0 in for_rtl_finish_ ()
0x0804f1b1 in for_rtl_finish_ ()
0x0804f1b3 in for_rtl_finish_ ()
0x0806a764 in for__message_catalog_close ()
0x0806a765 in for__message_catalog_close ()
0x0806a767 in for__message_catalog_close ()
0x0806a768 in for__message_catalog_close ()
0x0806a76d in for__message_catalog_close ()
0x0806a76f in for__message_catalog_close ()
0x0806a79b in for__message_catalog_close ()
0x0806a79d in for__message_catalog_close ()
0x0806a79e in for__message_catalog_close ()
0x0804f1b8 in for_rtl_finish_ ()
0x0806c270 in for__exit_handler ()
0x0806c271 in for__exit_handler ()
0x0806c273 in for__exit_handler ()
0x0806c276 in for__exit_handler ()
0x0806c27b in for__exit_handler ()
0x0806c280 in for__exit_handler ()
0x0806c2a1 in for__exit_handler ()
0x0806c2a6 in for__exit_handler ()
0x0806c2c7 in for__exit_handler ()
0x0806c2cc in for__exit_handler ()
0x0806c2ed in for__exit_handler ()
0x0806c2f2 in for__exit_handler ()
0x0806c313 in for__exit_handler ()
0x0806c318 in for__exit_handler ()
0x0806c333 in for__exit_handler ()
0x0806c338 in for__exit_handler ()
0x0806c342 in for__exit_handler ()
0x0806c344 in for__exit_handler ()
0x0806c346 in for__exit_handler ()
0x0806c347 in for__exit_handler ()
0x0805ab28 in for__free_vm ()
0x0805ab29 in for__free_vm ()
0x0805ab2b in for__free_vm ()
0x0805ab2e in for__free_vm ()
0x08049e38 in _init ()
0x008562b0 in free ()
0x008562b1 in free ()
0x008562b3 in free ()
0x008562b6 in free ()
0x008562b9 in free ()
0x00808c31 in __i686.get_pc_thunk.bx ()
0x00808c34 in __i686.get_pc_thunk.bx ()
0x008562be in free ()
0x008562c4 in free ()
0x008562c7 in free ()
0x008562cd in free ()
0x008562d0 in free ()
0x008562d3 in free ()
0x008562d5 in free ()
0x008562d7 in free ()
0x008562f2 in free ()
0x008562f4 in free ()
0x008562f6 in free ()
0x008562f9 in free ()
Program received signal SIGSEGV
0x008562f9 in free ()



0 Kudos
Steven_L_Intel1
Employee
587 Views
Ok - it seems to be dying when some dynamically allocated memory is freed - it has finished your code by that time, so the statements at the end of your program are not relevant.

This sort of thing can be tricky to diagnose. What I often do is start commenting out parts of the main program, from the end back, and see if the error goes away. If it does, then I look closer at what I just disabled and perhaps do some more selective disabling to find the culprit. There are so many possibilities, it's hard to suggest anything specific, though if you have arrays dimensioned (*) or (1) then bounds checking is disabled.
0 Kudos
gregfi04
Beginner
587 Views
Fixed it.

The dimensioning on an integer array wasn't large enough. I'm kind of amazed it worked in the first place.

Greg
0 Kudos
Reply