How to resolve gcc compiler optimization-induced segmentation fault on centos dual compiler set up
NickName:Kemin Zhou Ask DateTime:2020-02-25T03:50:11

How to resolve gcc compiler optimization-induced segmentation fault on centos dual compiler set up

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). The OS giving trouble:

uname -a
Linux hostname 3.10.0-957.27.2.el7.x86_64 #1 SMP Mon Jul 29 17:46:05 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux 

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 at

std::ostream& operator(ostream&, const string&);

but from one of several random places in my code. I 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 to be faster.

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?

I have followed suggestion (provide in the comment section below) turning on full warning and updated all dependent libraries with warning message too (include boost). It looks this solved the problem. I learn a big lesson: any code we write has to pass pedantic Wall. Someone should write an answer to help other programmers.

Copyright Notice:Content Author:「Kemin Zhou」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/60382948/how-to-resolve-gcc-compiler-optimization-induced-segmentation-fault-on-centos-du

More about “How to resolve gcc compiler optimization-induced segmentation fault on centos dual compiler set up” related questions

How to resolve gcc compiler optimization-induced segmentation fault on centos dual compiler set up

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 sm...

Show Detail

GCC internal compiler error: Segmentation fault

I try to include a file, I've defined in cmake. -DUNINSTD_INC=$ENV{TARGET_FS}/usr/include/unistd.h I checked this define and UNINSTD_INC is the correct filepath. The code-snipped, which causes the

Show Detail

How to resolve issue with gcc internal compiler error: Segmentation fault

I have written a "hello world" C code: #include<stdio.h> int main() { printf("hello world"); return 0; } When running the below command: gcc main.c -o main

Show Detail

Swift compiler segmentation fault using `ReferenceWritableKeyPath `

Using a ReferenceWritaleKeyPath to read a property is causing a compiler segmentation fault. I am setting up a helper to simplify binding two variables. With help from OOPer I got the basic bindin...

Show Detail

Segmentation fault GCC

I'm modifying gcc, specifically adding a new clause to OpenMP. after compiling my test program it gives me this error: "test.c: In function 'main': test.c:10:1: internal compiler error: Segmentat...

Show Detail

pointer segmentation fault with gcc

void main() { int *p=20; printf("%d\n",*p); } This code is compiling successfully but giving segmentation fault, I am using gcc compiler.

Show Detail

OS X Swift Compiler Error - Segmentation Fault

I am making some variable declarations in a NSViewController custom class. The declarations are: var filterSettings: Dictionary<String, String> = ["Location": "All", "Status": "All", "PP

Show Detail

gfortran compiler gives segmentation fault

I was having trouble running fortran code, so I tried an example code in here: https://gcc.gnu.org/onlinedocs/gcc-8.4.0/gfortran/ICHAR.html program read_val integer value character(len=10) str...

Show Detail

internal compiler error: Segmentation fault in gcc . when sending variadic template to struct

I'm trying to compile following code : #include <iostream> template<template <typename...> class Container,class... Args> struct Container {}; template<class T1,class

Show Detail

gcc compiler does not show segfault error

I am using mingw compiler on my windows 10 laptop. The following c code should display a segmentation fault error. But instead, it just does not show anything (empty output). #include <stdio.h&g...

Show Detail