gcc-11 C++ Regression on Cygwin

Xi Ruoyao xry111@mengyan1223.wang
Sun May 2 05:49:53 GMT 2021


On Sun, 2021-05-02 at 00:02 +0000, James McKelvey wrote:
> My code works fine on Cygwin using C++ 10.2.0. But it fails when I
> build with the latest gcc-11 snapshot,gcc-11-20210426, with undefined
> references at link time. It fails under -O3 and -O0, with
> differenterrors. It failed under earlier snapshots as well.
> 
> My problem is that I do not know how to report the bug without
> providing most or all of the project. Or maybe thebug has been
> reported already? Let me know. I've been away from C++ for several
> years. Here are the errors for one program:
> /usr/local/bin/g++ -std=c++0x  -O3 -DNDEBUG     -DUSE_INTL=1 -
> DUSE_MUTEX=1  -D_FORTIFY_SOURCE=1 -pedantic-errors -Werror -ansi -fno-
> common -Wall -Wold-style-cast -Wsign-promo -Wpointer-arith -Wundef -
> Wwrite-strings -Winvalid-pch -Woverloaded-virtual -Wcast-qual -Wextra
> -Wredundant-decls -Wshadow -Wcast-align=strict -Wcomment -fstrict-
> aliasing -Winit-self -Wmissing-include-dirs -Wswitch-default -Wswitch-
> enum -Wlogical-op -Wconversion -Wsign-conversion -Wmissing-
> declarations -Wdeprecated -ftree-switch-conversion -Wuninitialized -
> Wparentheses -Wimplicit-fallthrough=5 -Wformat-nonliteral -Wformat-
> truncation=2 -Wformat-signedness -Wdouble-promotion -Wformat=2 -
> Wformat-overflow=2 -Wformat-security -Wnull-dereference -Wmain -
> Wmultistatement-macros -Wsequence-point -Wswitch-default -Wswitch-enum
> -Wunused-value -Wstrict-overflow=2 -Warith-conversion -Wfloat-
> conversion -Wduplicated-cond -Wunsafe-loop-optimizations -Wreturn-type
> -Wunused-parameter -Wmaybe-uninitialized -Wstrict-aliasing -Wsuggest-
> attribute=noreturn -Wsuggest-attribute=format -Wsuggest-
> attribute=malloc -Wmissing-format-attribute -Wmissing-noreturn -
> Walloc-zero -Walloca -Wtrampolines -Wcast-function-type -Wlogical-op -
> Wpacked -Wredundant-decls -Wunused -Winline -MMD      -fimplicit-
> templates  -Wl,-warn-common -L.. -o header_edit.exe header_edit.o -
> lPatternDriver -lintl -lpthread
> /usr/bin/ld: header_edit.o:header_edit.cc:(.text.startup+0x2e2):
> undefined reference to `

I think mixing "-std=c++0x" and "-ansi" does not make sense: -ansi means
C++98.  And in GNU C++ standard library, std::basic_string's ABI is
different in C++98 and C++11 (or above).  So it might cause the
following problems.

To link your code, header_edit.o and PatternDriver.a must be compiled
with a consistent string ABI, i. e. both compiled with -std=c++98, or
both compiled with -std=c++0x or above.

> _ZN13PatternDriver12BreakPatternC1ERKNSt7__cxx1112basic_stringIcSt11ch
> ar_traitsIcESaIcEEERKNS_26ConflateIntegerScalarValueESB_RKNS_12Templat
> eEnumIL_ZNS_16complement_namesB5cxx11EEL_ZNS_14COMPLEMENTENUMEEEE
> 
> '
> /usr/bin/ld: header_edit.o:header_edit.cc:(.text.startup+0x3a1):
> undefined reference to `
> 
> _ZN13PatternDriver12BreakPatternC1ERKNSt7__cxx1112basic_stringIcSt11ch
> ar_traitsIcESaIcEEERKNS_26ConflateIntegerScalarValueESB_RKNS_12Templat
> eEnumIL_ZNS_16complement_namesB5cxx11EEL_ZNS_14COMPLEMENTENUMEEEE
> 
> '
> /usr/bin/ld: header_edit.o:header_edit.cc:(.text.startup+0x3d2):
> undefined reference to `E
> 
> '
> /usr/bin/ld: header_edit.o:header_edit.cc:(.text.startup+0x3f8):
> undefined reference to `leE'
> /usr/bin/ld: header_edit.o:header_edit.cc:(.text.startup+0x431):
> undefined reference to `gnE'
> /usr/bin/ld: header_edit.o:header_edit.cc:(.text.startup+0x449):
> undefined reference to `S3_'

E, leE, gnE, S3_ are not a C++ mangled name.  Does your code contain
them, or the compiler (mis)generated them?

To report it as a bug you'll need to reduce it to a small, self-
contained single translation unit.  You can use objdump to show it
misses some symbols or contains some buggy symbols.

If possible you can post your code (github or somewhere), so others can
help you to do the reduction.
-- 
Xi Ruoyao <xry111@mengyan1223.wang>
School of Aerospace Science and Technology, Xidian University



More information about the Gcc-help mailing list