understanding segmentation faults



Is "segmentation fault" an error message that is issued by the operating
system rather than by the compiler run-time? If so, then I guess it's
not a problem that the compiler vendors can easily solve. I find the
error message to be particularly unhelpful in diagnosing a problem.

Case in point: I have a program written in Fortran 90 that runs just
fine on a Windows machine after being compiled with CVF 6.6c, though
it's been a while since the program was built, so I don't recall if it
was necessary to use the editbin utility to increase the stack size.
The same program would sometimes work but sometimes fail on a Linux
machine after being compiled with ifort version 10.1.008; when it
failed, the error message was the mysterious "segmentation fault". I
tracked down the offending statement to be a simple WRITE statement
with a single argument in the list, namely a subarray (or is the
technical terminology an "array section"?). Whenver the array was
about 4 MB in size, the program worked as expected, but whenever the
array was about 16 MB in size, the segmentation fault occurred. After
playing around with some command line options on the compiler, I was
able to get the program to work by using the -heap-arrays option with
the argument set to 20000 kB. I'm guessing that the compiler tried to
create a temporary to hold the array section and that there wasn't
enough memory in that pool to do so, thus causing the segmentation fault.
But I could have diagnosed the problem a lot faster if the error message
had been something like "stack overflow" like it is with CVF.

So my goal here is to try and get a better understanding of what can
cause the "segmentation fault" error message, anything that might have
helped me to reduce the debugging time. Is it a rather generic error
message that can be caused by so many different things that it would be
difficult to provide a tutorial? Or would a more experienced ifort user
have been able to diagnose the problem right away?

.



Relevant Pages

  • Re: Why the compiler gives warning ?
    ... > "Except when it is the operand of the sizeof operator or the unary & ... > initial element of the array object and is not an lvalue." ... ignored' is an error message; it looks more like a warning. ... from the compiler. ...
    (comp.lang.c)
  • Re: problem with linked list
    ... main returns int in C. ... You cannot directly assign to an array in C like this (and this is what your ... compiler is telling you). ... > I am using the Borland c compiler an here is the error message: ...
    (comp.lang.c)
  • Re: Bad code or bad compiler?
    ... segmentation fault at the indicated instruction. ... the array pointer is allocated by a function in the array index. ... Is this bad C code, "unwise" C code, or a compiler bug? ... int nextindex ...
    (comp.lang.c)
  • trouble with initializing array of complex type
    ... it gives me this error message: ... With PGI Fortran 90 compiler, it also gives an error at this step. ... real type array, compiles without any error or warning message. ...
    (comp.lang.fortran)
  • Re: Bad code or bad compiler?
    ... segmentation fault at the indicated instruction. ... the array pointer is allocated by a function in the array index. ... Is this bad C code, "unwise" C code, or a compiler bug? ... int nextindex ...
    (comp.lang.c)