I have a large C++ software project build with gcc. After adding some new code into the repository, one of the binary started to get Segmentation Fault on larger test data (no segfault on a few smaller test inputs). I have tested on several different hardwares with two different systems. Ubuntu 18 and Centos6. GCC compiler tested are 6.3, 7.4 and 9.2. Binary build on Ubuntu always good and on Centos is always bad (segfault).
My Unbuntu has single compiler, but the Cenos usually has a old gcc 4.8, and on top of that we build 6.3, 7.4, or 9.2. My C++ code was build with various versions gcc and on different harwares, all got segfault and used the -O2 or -O3 option. When using -O0 option the binary has no problem but a few times slower. I am trying to generate production code which needs faster programs (time is a lots of money).
I know one solution is to find out which line of code is causing this segmentation fault, which I will try next. My question is that is there any option while making the gcc compiler that may help to resolve this segfault issue?