Intel® C++ Compiler
Community support and assistance for creating C++ code that runs on platforms based on Intel® processors.

Getting segmentation fault for no reason.

Jon_P_
Beginner
2,064 Views

I am running on RHE6.7 which comes with gcc 4.4.7. My source code that requires c++11 compatible compiler, so I have downloaded gcc 4.8.2. I am able to compile with gcc 4.8.2 and run.

The Intel compiler completes without any error but when I run the output... I get a segmentation fault. I also get a segmentation fault if I compile HelloWorld.cpp (only when specifying version of 4.8.2), see below:

$ /opt/rh/devtoolset-2/root/usr/bin/g++ HelloWorld.cpp
$ ./a.out
Hello World!

$ icpc HelloWorld.cpp
$ ./a.out
Hello World!

$ icpc -gcc-name=/opt/rh/devtoolset-2/root/usr/bin/gcc HelloWorld.cpp
$ ./a.out
Segmentation fault


Does anyone know what I is happening or what I am doing wrong? Your help will be much appreciated.

0 Kudos
14 Replies
Viet_H_Intel
Moderator
2,064 Views

Hi Jon,

Which compiler version are you using. I couldn't reproduce the error with 17.0.4

 

vahoang@orcsle100:/tmp$ which gcc
/cts/tools/gcc/gcc-4.8.1/bin/gcc
vahoang@orcsle100:/tmp$ icpc -gcc-name=/cts/tools/gcc/gcc-4.8.1/bin/gcc hellow.cpp && ./a.out
Hello, World!
vahoang@orcsle100:/tmp$ cat hellow.cpp
#include <iostream>
using namespace std;

int main()
{
    cout << "Hello, World!" << endl;
    return 0;
}
vahoang@orcsle100:/tmp$ cat /etc/redhat-release
Red Hat Enterprise Linux Workstation release 6.0 (Santiago)
vahoang@orcsle100:/tmp$ icc -V
Intel(R) C Intel(R) 64 Compiler for applications running on Intel(R) 64, Version 17.0.4.196 Build 20170411
Copyright (C) 1985-2017 Intel Corporation.  All rights reserved.

Regards,

Viet Hoang

0 Kudos
Yuan_C_Intel
Employee
2,064 Views

Hi, Jon

Please also check your glibc version:

$ ldd --version

If you are using a newer version gcc, you'd better not use too old glibc which are incompatible.

Thanks

Yolanda
 

0 Kudos
Jon_P_
Beginner
2,064 Views

- Hoang and Chen

$ icc -V
Intel(R) C Intel(R) 64 Compiler for applications running on Intel(R) 64, Version 17.0.4.196 Build 20170411
Copyright (C) 1985-2017 Intel Corporation.  All rights reserved.

$ ldd --version
ldd (GNU libc) 2.12

 

^ so it looks like my glibc is pretty old and should update it.

0 Kudos
Viet_H_Intel
Moderator
2,064 Views

Hi Jon,

Even I have the same glibc and ICC version but I still couldn't reproduce it at my end.

vahoang@orcsle100:/tmp$ ldd --version
ldd (GNU libc) 2.12

vahoang@orcsle100:/tmp$ icpc -gcc-name=/cts/tools/gcc/gcc-4.8.1/bin/gcc hellow.cpp && ./a.out
Hello, World!

Can you run it under debugger?

 

Regards,

Viet Hoang

 

0 Kudos
Jon_P_
Beginner
2,064 Views

Unfortunately, there is no change and no additional information with running with debugger.

0 Kudos
Viet_H_Intel
Moderator
2,064 Views

Did you compile with -g? Can you try:  strace -f -o /tmp/st.out ./a.out and look at the output to see if there are any errors?

Regards,

Viet Hoang

0 Kudos
Jon_P_
Beginner
2,064 Views

I did compile with -g

I have output from using icc without specifying new version of gcc (working) and output with specifying new version (broken). The last few lines are as follows.

...
10349 close(3)                          = 0
10349 mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x2aaaaba08000
10349 mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x2aaaaba09000
10349 arch_prctl(ARCH_SET_FS, 0x2aaaaba08b40) = 0
10349 mprotect(0x2aaaaba06000, 4096, PROT_READ) = 0
10349 mprotect(0x2aaaab7f9000, 16384, PROT_READ) = 0
10349 mprotect(0x2aaaab257000, 4096, PROT_READ) = 0
10349 mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x2aaaaba0b000
10349 mprotect(0x2aaaaafb6000, 28672, PROT_READ) = 0
10349 mprotect(0x2aaaaacca000, 8192, PROT_READ) = 0
10349 munmap(0x2aaaaaacd000, 104151)    = 0
10349 fstat(1, {st_mode=S_IFCHR|0620, st_rdev=makedev(136, 2), ...}) = 0
10349 mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x2aaaaaacd000
10349 write(1, "Hello World!\n", 13)    = 13
10349 exit_group(0)                     = ?
10349 +++ exited with 0 +++


...
6634  close(3)                          = 0
6634  mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x2aaaaba08000
6634  mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x2aaaaba09000
6634  arch_prctl(ARCH_SET_FS, 0x2aaaaba08b40) = 0
6634  mprotect(0x2aaaaba06000, 4096, PROT_READ) = 0
6634  mprotect(0x2aaaab7f9000, 16384, PROT_READ) = 0
6634  mprotect(0x2aaaab257000, 4096, PROT_READ) = 0
6634  mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x2aaaaba0b000
6634  mprotect(0x2aaaaafb6000, 28672, PROT_READ) = 0
6634  mprotect(0x2aaaaacca000, 8192, PROT_READ) = 0
6634  munmap(0x2aaaaaacd000, 104151)    = 0
6634  --- SIGSEGV {si_signo=SIGSEGV, si_code=SEGV_MAPERR, si_addr=0xffffffffffffffe8} ---
6634  +++ killed by SIGSEGV +++

0 Kudos
jimdempseyatthecove
Honored Contributor III
2,064 Views

While this is a C++ forum, your debug printouts look suspiciously like Fortran.

The failure is occurring on an fstat(1, ...

Which is a status on the console unit number (1).

Do you happen by chance have a FILE.1 or environment variable FORT1=xxx in the failing configuration?

Either would redirect unit 1 to somewhere else (or possibly to nowhere).

Jim Dempsey

0 Kudos
Jon_P_
Beginner
2,064 Views

Jim,

There is no FILE.1 or environmental variable FORT1 anywhere.

0 Kudos
Viet_H_Intel
Moderator
2,064 Views

I think the problem happened with mummap () called. And the SEGV may generate if  address addr not multiple by the page size.

Do you know what your page size is? 

$getconf PAGESIZE

 

So far, I couldn't reproduce it at our end to investigate further.

Is it  possible for you to download different version of GCC and see if still occurs?

 

Regards,

Viet Hoang

0 Kudos
Jon_P_
Beginner
2,064 Views

Hoang,

My page size:
$ getconf PAGESIZE
4096

I will work with the Admins on getting a different version of gcc to see if that will help.

Thanks!

0 Kudos
Viet_H_Intel
Moderator
2,064 Views

Can you generate an assembly file and provide it to us?

$icpc -gcc-name=/opt/rh/devtoolset-2/root/usr/bin/gcc  HelloWorld.cpp -S -O2

there should be a HelloWorld.s

Thanks,

Viet Hoang

 

 

0 Kudos
Jon_P_
Beginner
2,064 Views

I was able to get a different version of gcc version 6.1.0. I am able to compile and run with that.

$ icpc -gcc-name=/cm/local/apps/gcc/current/bin/gcc HelloWorld.cpp
$ ./a.out
Hello World!

$ /cm/local/apps/gcc/current/bin/gcc --version
gcc (GCC) 6.1.0

------------------------------------------------------------------------------------------
I also ran the command with with the 'broken' compiler setting.... 
$icpc -gcc-name=/opt/rh/devtoolset-2/root/usr/bin/gcc  HelloWorld.cpp -S -O2

The first time I ran it, ./a.out actually ran and printed "Hello World!", however, the second time it continued to give segmentation fault. The assembly file created during 'segmentation fault' and 'Hello World!' is identical.
 


 

 

0 Kudos
Viet_H_Intel
Moderator
2,064 Views

Hi Jon,

I looked at your assembly. It looked ok to me. Then I generated an executable from it. It ran successfully. (I ran it several times)

vahoang@orcsle100:/tmp$ icc HelloWorld.s (your assembly file)
vahoang@orcsle100:/tmp$ ./a.out
Hello World!
vahoang@orcsle100:/tmp$

If the compiler generated wrong code, then I should have seen the SegFault. So, I think something in your ENV caused the SegFault rather than the compiler. 

One more thing you can try is to take a.out to another system to see if it works.

Regards,

Viet Hoang

 

0 Kudos
Reply