I'm using GCC 4.7.2 from devtoolset package on CentOS 5 (CentOS 5 because we need compatibility with old Linuxes, and GCC 4.7 because it optimizes better than 4.4).
There is one symbols that prevents my binaries from running on RHEL4: __stack_chk_fail@GLIBC_2.4
. It is included only in some C++ programs and the -fno-stack-protector
flag doesn't help.
Here is minimal program that reproduces the problem (but the same using stdio.h
works):
#include <iostream>
int main(int argc, char *argv[]) {
for(int i=0; i < argc; i++)
std::cout << " " << argv[i];
return 0;
}
When compiled with optimization (-O
/-O2
) it references __stack_chk_fail
.
$ g++ -fno-stack-protector -O2 foo.cc
$ readelf -s a.out | grep chk
15: 0000000000000000 0 FUNC GLOBAL DEFAULT UND __stack_chk_fail@GLIBC_2.4 (5)
105: 0000000000000000 0 FUNC GLOBAL DEFAULT UND __stack_chk_fail@@GLIBC_2
Any idea why this symbol gets here and how to get rid of it?
Just in case, full readelf
output and gcc -v
is here.
Edit: This problem may be specific to Red Hat Developer Toolset 1.1. With default CentOS compiler __stack_chk_fail
is not referenced.