Segmentation Fault with GCC and Gcov on Instrumented C++ Program

I'm to instrument GCC and Gcov to collect execution sequence information. While my approach works well for c programs on x86 and x86_64, I'm encountering a segmentation fault when attempting to instrument a C++ program on x86_64.
C++
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
vector<int> numbers = {1, 2, 3, 4, 5};

sort(numbers.begin(), numbers.end(), greater<int>());

for (int num : numbers) {
cout << num << " ";
}
cout << endl;

return 0;
}
C++
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
vector<int> numbers = {1, 2, 3, 4, 5};

sort(numbers.begin(), numbers.end(), greater<int>());

for (int num : numbers) {
cout << num << " ";
}
cout << endl;

return 0;
}
When I compile this program with GCC and Gcov on a 64-bit Intel processor x86_64 and attempt to run it, I encounter a segmentation fault. I'm using GCC version 3.4.5 on CentOS 6.4. My instrumentation code is being inserted correctly and there are no other obvious issues in the code. Does anyone have experience with similar issues or suggestions for troubleshooting?
2 Replies
Dtynin
Dtynin2mo ago
Hi @Marvee Amasi have you tried updating to a more recent version of GCC? the The GCC version you're using may not fully support modern C++ features, especially when combined with instrumentation tools like Gcov.
Marvee Amasi
Marvee Amasi2mo ago
CentOS 6.4 has a fixed GCC version. Just worried that upgrading the entire system to a newer version could potentially introduce compatibility issues with other software components or disrupt the workflow, maybe I would try out another hardware with a different OS so I can try the latest version of GCC but thanks @Dtynin
Want results from more Discord servers?
Add your server