Skip to main content Skip to navigation

It can be frustrating for an engineer that their CAE application is giving a segfault with a particular model, which often points to a bug in the application that needs to be addressed, or some model behavior that creates an issue within the CAE application that causes the segfault. This post is to help clients better understand what a segfault is.

A segfault error is a common programming bug where the application is trying to access memory that it didn’t actually allocate, or had already freed. This class of bug is so common, you can even buy t-shirts online that have the dreaded “segfault” printed on them, they are the bane of programmers everywhere.

A simple example below “segfault.c” is some C code just allocates a NULL pointer to memory , and then tries to access it

#include <stdio.h>
int main( int argc, char* argv[] )
{
  const char *s = NULL;
  printf( "%c\n", s[0] );
}

Compile this code, and execute it:

$ gcc -g segfault.c
$ ulimit -c unlimited ; ./a.out
signal 11 (Segmentation fault), address is (nil) from 0x40084a
[bt]: (1) ./a.out() [0x40084a]
[bt]: (2) ./a.out() [0x40084a]
[bt]: (3) ./a.out() [0x400862]
[bt]: (4) ./a.out() [0x400877]
[bt]: (5) ./a.out() [0x40088c]
[bt]: (6) ./a.out() [0x4008a1]
[bt]: (7) ./a.out() [0x400931]
[bt]: (8) /usr/lib64/libc.so.6(__libc_start_main+0xf5) [0x2afb01fb8495]
[bt]: (9) ./a.out() [0x400659]

And you see the program generates the dreaded “segfault”.

To debug the segfault, the program will often print a “core” file out, which can be used with a debugger to point to the exact line of code that created the issue. The CAE vendor may want these core files to debug the issue, and may need you to run with a debug build version of the software:

$ gdb a.out  -c ./core.20273 
Reading symbols from /home/user/a.out...done.
[New LWP 20273]
Core was generated by `./a.out'.
Program terminated with signal 11, Segmentation fault.
#0  0x0000000000400548 in main (argc=1, argv=0x7ffffb093d68) at segfault.c:6
6	  printf( "%c\n", s[0] );
(gdb) bt
#0  0x0000000000400548 in main (argc=1, argv=0x7ffffb093d68) at segfault.c:6

(gdb) 

There is often not anything the CAE engineer or TotalCAE can do to make a segfault go away without the CAE application vendor who wrote the code providing a fix after checking that there is no memory faults on the system. The TotalCAE support team will attempt to run your model on a newest release of the application to see if the issue/bug was fixed in a later release, or try different core counts if this is boundary condition issue.