Bug 1007528

Summary: devtoolset-1.1: __stack_chk_fail referenced despite of -fno-stack-protector
Product: Red Hat Developer Toolset Reporter: Marcin Wojdyr <wojdyr>
Component: gccAssignee: Jakub Jelinek <jakub>
Status: CLOSED NOTABUG QA Contact: Martin Cermak <mcermak>
Severity: low Docs Contact:
Priority: unspecified    
Version: DTS 1.1 RHEL 5CC: law, mcermak, mfranc, mnewsome, mpolacek
Target Milestone: ---   
Target Release: 2.4   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2013-09-12 18:00:41 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:

Description Marcin Wojdyr 2013-09-12 16:56:47 UTC
(Maybe that's not a bug, I have no idea).

I'm trying to produce binaries that would work also on RHEL4. One symbol gets in the way: __stack_chk_fail.
Adding -fno-stack-protector doesn't change anything.
This is devtoolset specific, the system compiler doesn't reference this symbol.
It happens only with -O[1-3] and with <iostream> included.


How reproducible:
always on i386 and x86 RHEL5 clones (sorry, I don't have access to RHEL5 atm)


Steps to Reproduce:

$ cat foo.cc

#include <iostream>
int main(int argc, char *argv[]) {
    for(int i=0; i < argc; i++)
        std::cout << " " << argv[i];
    return 0;
}

$ g++ -fno-stack-protector -O2 foo.cc
$ readelf -s a.out | grep chk
    15: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND __stack_chk_fail (5)
   105: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND __stack_chk_fail@@GLIBC_2

Do you know why this happens (and why only with -O)?

Comment 2 Jakub Jelinek 2013-09-12 18:00:41 UTC
This is indeend not a bug, libstdc++_nonshared.a (and other libraries) are intentionally built with -fstack-protector for security reasons.
Developer Toolset is not the product to use if you want to build on newer RHEL and deploy on older RHEL, after all the system libstdc++.so.6 on RHEL4 doesn't have many of the symbols you might need and DTS on RHEL5 depends on.
To build (limited amount of) programs on RHEL5 that can run on RHEL4 you need to use compat-gcc-34 and compat-glibc packages and gcc34 or g++34.

Comment 3 Marcin Wojdyr 2013-09-12 18:17:30 UTC
aha, I just didn't know that *_nonshared.a archives are linked, I thought that everything is in shared libraries. Thanks for explanation.