Note: This bug is displayed in read-only format because the product is no longer active in Red Hat Bugzilla.

Bug 1610457

Summary: gcc bug when static linking with boost and lto enabled
Product: Red Hat Developer Toolset Reporter: Paulo Andrade <pandrade>
Component: gccAssignee: Marek Polacek <mpolacek>
Status: CLOSED ERRATA QA Contact: Michael Petlan <mpetlan>
Severity: medium Docs Contact:
Priority: medium    
Version: DTS 7.1 RHEL 7CC: hartsjc, jakub, kanderso, law, mcermak, mnewsome, mpetlan, ohudlick
Target Milestone: alpha   
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: devtoolset-8-gcc-8.2.1-2.2.el7 Doc Type: No Doc Update
Doc Text:
undefined
Story Points: ---
Clone Of: Environment:
Last Closed: 2018-11-13 08:38:37 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:
Embargoed:

Description Paulo Andrade 2018-07-31 16:37:59 UTC
User is unable to use link time optimization with –std=c++17 and statically link boost with devtoolset-7-gcc.

User pointed to the commit https://gcc.gnu.org/viewcvs/gcc?view=revision&revision=258287 and the bug report https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81004

Using the libboost_program_options.a from the gcc bug report, below is result from tests:

$ scl enable devtoolset-7 bash
# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81004#c3
[reduced]$ g++ -w -Wl,--no-demangle -flto lines.ii options.ii -O1 -std=c++1z -o options ../unreduced/libboost_program_options.a
../unreduced/libboost_program_options.a(value_semantic.o): In function `_ZN5boost15program_options10validators17get_single_stringIcEERKNSt7__cxx1112basic_stringIT_St11char_traitsIS5_ESaIS5_EEERKSt6vectorIS9_SaIS9_EEb':
value_semantic.cpp:(.text._ZN5boost15program_options10validators17get_single_stringIcEERKNSt7__cxx1112basic_stringIT_St11char_traitsIS5_ESaIS5_EEERKSt6vectorIS9_SaIS9_EEb[_ZN5boost15program_options10validators17get_single_stringIcEERKNSt7__cxx1112basic_stringIT_St11char_traitsIS5_ESaIS5_EEERKSt6vectorIS9_SaIS9_EEb]+0x90): undefined reference to `_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEED1Ev'
../unreduced/libboost_program_options.a(value_semantic.o): In function `_GLOBAL__sub_I__ZNK5boost15program_options29value_semantic_codecvt_helperIcE5parseERNS_3anyERKSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaISB_EEb':
value_semantic.cpp:(.text.startup+0x1e): undefined reference to `_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEED1Ev'
collect2: error: ld returned 1 exit status

# for the sake of testing, no errors if using Red Hat provided dynamic library
[reduced]$ g++ -w -Wl,--no-demangle -flto lines.ii options.ii -O1 -std=c++1z -o options -lboost_program_options

# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81004#c4
[unreduced]$ g++ -w -flto -Wl,--no-demangle l.ii o.ii -O1 -std=c++1z ./libboost_program_options.a
./libboost_program_options.a(value_semantic.o): In function `_GLOBAL__sub_I__ZNK5boost15program_options29value_semantic_codecvt_helperIcE5parseERNS_3anyERKSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaISB_EEb':
value_semantic.cpp:(.text.startup+0x1e): undefined reference to `_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEED1Ev'
collect2: error: ld returned 1 exit status

# for the sake of testing, with the Red Hat provided dynamic library
unreduced]$ g++ -w -flto -Wl,--no-demangle l.ii o.ii -O1 -std=c++1z -lboost_program_options
/tmp/ccVfdhyi.ltrans0.ltrans.o: In function `_ZN5boost15program_options16validation_errorC2ENS1_6kind_tERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESA_i':
<artificial>:(.text+0x214f): undefined reference to `_ZN5boost15program_options16validation_error12get_templateB5cxx11ENS1_6kind_tE'
<artificial>:(.text+0x2163): undefined reference to `_ZN5boost15program_options22error_with_option_nameC2ERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES9_S9_i'
/tmp/ccVfdhyi.ltrans0.ltrans.o: In function `_ZNK5boost15program_options11typed_valueIN5utils5LinesEcE4nameB5cxx11Ev':
<artificial>:(.text+0x2fb6): undefined reference to `_ZN5boost15program_options3argB5cxx11E'
/tmp/ccVfdhyi.ltrans0.ltrans.o: In function `_ZNK5boost15program_options11typed_valueIicE4nameB5cxx11Ev':
<artificial>:(.text+0x358c): undefined reference to `_ZN5boost15program_options3argB5cxx11E'
/tmp/ccVfdhyi.ltrans0.ltrans.o: In function `_ZNK5boost15program_options11typed_valueIN5utils5LinesEcE6xparseERNS_3anyERKSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaISD_EE':
<artificial>:(.text+0x571d): undefined reference to `_ZN5boost15program_options8validateERNS_3anyERKSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaIS9_EEPS9_i'
<artificial>:(.text+0x5d63): undefined reference to `_ZN5boost15program_options20invalid_option_valueC1ERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE'
/tmp/ccVfdhyi.ltrans0.ltrans.o: In function `_ZN5boost15program_options8validateIicEEvRNS_3anyERKSt6vectorINSt7__cxx1112basic_stringIT0_St11char_traitsIS7_ESaIS7_EEESaISB_EEPT_l':
<artificial>:(.text+0x6c21): undefined reference to `_ZN5boost15program_options20invalid_option_valueC1ERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE'
/tmp/ccVfdhyi.ltrans0.ltrans.o: In function `main':
<artificial>:(.text+0x6df6): undefined reference to `_ZN5boost15program_options19options_descriptionC1ERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEjj'
/tmp/ccVfdhyi.ltrans0.ltrans.o:(.rodata+0xaa0): undefined reference to `_ZNK5boost15program_options22error_with_option_name23substitute_placeholdersERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE'
/tmp/ccVfdhyi.ltrans0.ltrans.o:(.rodata+0xaf8): undefined reference to `_ZNK5boost15program_options22error_with_option_name23substitute_placeholdersERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE'
/tmp/ccVfdhyi.ltrans0.ltrans.o:(.rodata+0xb70): undefined reference to `_ZNK5boost15program_options22error_with_option_name23substitute_placeholdersERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE'
/tmp/ccVfdhyi.ltrans0.ltrans.o:(.rodata+0xc30): undefined reference to `_ZNK5boost15program_options29value_semantic_codecvt_helperIcE5parseERNS_3anyERKSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaISB_EEb'
/tmp/ccVfdhyi.ltrans0.ltrans.o:(.rodata+0xcd0): undefined reference to `_ZNK5boost15program_options29value_semantic_codecvt_helperIcE5parseERNS_3anyERKSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaISB_EEb'
/tmp/ccVfdhyi.ltrans0.ltrans.o:(.rodata+0x11b8): undefined reference to `_ZNK5boost15program_options22error_with_option_name23substitute_placeholdersERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE'
/tmp/ccVfdhyi.ltrans0.ltrans.o:(.rodata+0x1210): undefined reference to `_ZNK5boost15program_options22error_with_option_name23substitute_placeholdersERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE'
/tmp/ccVfdhyi.ltrans0.ltrans.o:(.rodata+0x1288): undefined reference to `_ZNK5boost15program_options22error_with_option_name23substitute_placeholdersERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE'
collect2: error: ld returned 1 exit status

# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81004#c5
[reduced]$ g++ -O2 -c value_semantic.ii
[reduced]$ g++ -w -Wl,--no-demangle lines.ii options.ii -O2 -std=c++1z -flto value_semantic.o 2>&1 | grep _ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEED1Ev
value_semantic.ii:(.text.startup+0x20): undefined reference to `_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEED1Ev'


--------------------------------------------------------------------------------
Now, with a devtoolset-7-gcc built with the pointed patch:

# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81004#c3
[reduced]$ g++ -w -Wl,--no-demangle -flto lines.ii options.ii -O1 -std=c++1z -o options ../unreduced/libboost_program_options.a
# for the sake of testing, also works with dynamic libboost
[reduced]$ g++ -w -Wl,--no-demangle -flto lines.ii options.ii -O1 -std=c++1z -o options -lboost_program_options

# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81004#c4
[unreduced]$ g++ -w -flto -Wl,--no-demangle l.ii o.ii -O1 -std=c++1z ./libboost_program_options.a
lto1: internal compiler error: in register_resolution, at lto/lto.c:841
Please submit a full bug report,
with preprocessed source if appropriate.
See <http://bugzilla.redhat.com/bugzilla> for instructions.
lto-wrapper: fatal error: g++ returned 1 exit status
compilation terminated.
/opt/rh/devtoolset-7/root/usr/libexec/gcc/x86_64-redhat-linux/7/ld: error: lto-wrapper failed
collect2: error: ld returned 1 exit status
# for the sake of testing, using Red Hat provided dynamic library
[unreduced]$ g++ -w -flto -Wl,--no-demangle l.ii o.ii -O1 -std=c++1z -lboost_program_options
lto1: internal compiler error: in register_resolution, at lto/lto.c:841
Please submit a full bug report,
with preprocessed source if appropriate.
See <http://bugzilla.redhat.com/bugzilla> for instructions.
lto-wrapper: fatal error: g++ returned 1 exit status
compilation terminated.
/opt/rh/devtoolset-7/root/usr/libexec/gcc/x86_64-redhat-linux/7/ld: error: lto-wrapper failed
collect2: error: ld returned 1 exit status

# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81004#c5
[reduced]$ g++ -O2 -c value_semantic.ii
[reduced]$ g++ -w -Wl,--no-demangle lines.ii options.ii -O2 -std=c++1z -flto value_semantic.o 2>&1 | grep _ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEED1Ev

--------------------------------------------------------------------------------

Need further investigation, as the test in https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81004#c4
triggers an ICE, so, would need more patches.

Comment 2 Marek Polacek 2018-08-06 19:44:40 UTC
We don't recommend using LTO if it doesn't work for you.  That said, (part of) this problem has been fixed upstream and for GCC 8, so the fix will be included in DTS 8.0.

Comment 3 James Hartsock 2018-08-06 19:48:03 UTC
This mean fix for devtoolset-7-gcc is not viable?

Comment 4 Marek Polacek 2018-08-06 19:50:15 UTC
I'm afraid not.

Comment 14 Michael Petlan 2018-11-08 18:01:53 UTC
VERIFIED for devtoolset-8-gcc-8.2.1-3.

Comment 16 errata-xmlrpc 2018-11-13 08:38:37 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHBA-2018:3562