Application segfaults at -Ofast optimization level
A Fortran program runs correctly when the binary is built with armflang at
-O3 level, but encounters a runtime crash or segfault with
-Ofast optimization level.
The runtime segfault only occurs when
-Ofast is used to compile the code. The segfault disappears when you add the
-fno-stack-arrays option at the compilation with armflang.
The -fstack-arrays option is enabled by default at -Ofast
-fstack-arrays option is enabled, either on its own or enabled with
-Ofast by default, the compiler will allocate arrays for all sizes using the local stack for local and temporary arrays. This helps to improve performance, because it avoids slower heap operations with
free(). However, applications that use large arrays might reach the Linux stack-size limit at runtime and produce program segfaults. On typical Linux systems, a default stack-size limit is set, such as 8192 kilo bytes. You can adjust this default stack-size limit to a suitable value.
-Ofast -fno-stack-arraysinstead. This disables automatic arrays on the local stack, and keeps all other
- Alternatively, call
ulimit -s unlimitedbefore running the program to set the stack so that it is larger than the default size.
If you continue to experience problems, contact Arm support.