OPENDAP / libdap4

A new version of libdap that contains both DAP2 and DAP4 support
GNU Lesser General Public License v2.1
13 stars 14 forks source link

Build fails with LTO #244

Open eli-schwartz opened 9 months ago

eli-schwartz commented 9 months ago

I tried building with these flags: -flto=4 -Werror=odr -Werror=lto-type-mismatch -Werror=strict-aliasing

The -Werror=* here is important since these indicate cases where the compiler can try to optimize by assuming UB cannot exist.

I got this error:

/bin/sh ./libtool  --tag=CXX   --mode=link x86_64-pc-linux-gnu-g++ --std=c++14 -Wall -W -Wcast-align -Wno-deprecated-register -Wno-inconsistent-missing-override  -g -O2 -DNDEBUG  -march=native -fstack-protector-all -O2 -pipe -fdiagnostics-color=always -frecord-gcc-switches -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=3 -fstack-clash-protection -flto=4 -Werror=odr -Werror=lto-type-mismatch -Werror=strict-aliasing  -Wformat -Werror=format-security -std=c++14 -version-info 29:0:2 -Wl,-O1 -Wl,--as-needed -flto=4 -Werror=odr -Werror=lto-type-mismatch -Werror=strict-aliasing -Wl,--defsym=__gentoo_check_ldflags__=0 -o libdap.la -rpath /usr/lib64 libdap_la-AttrTable.lo libdap_la-DAS.lo libdap_la-DDS.lo libdap_la-DataDDS.lo libdap_la-DDXParserSAX2.lo libdap_la-BaseType.lo libdap_la-Byte.lo libdap_la-Int32.lo libdap_la-Float64.lo libdap_la-Str.lo libdap_la-Url.lo libdap_la-Vector.lo libdap_la-Array.lo libdap_la-Structure.lo libdap_la-Sequence.lo libdap_la-Grid.lo libdap_la-UInt32.lo libdap_la-Int16.lo libdap_la-UInt16.lo libdap_la-Float32.lo libdap_la-Constructor.lo libdap_la-BaseTypeFactory.lo libdap_la-SignalHandler.lo libdap_la-Error.lo libdap_la-InternalErr.lo libdap_la-util.lo libdap_la-xdrutil_ppc.lo libdap_la-parser-util.lo libdap_la-escaping.lo libdap_la-Clause.lo libdap_la-RValue.lo libdap_la-ConstraintEvaluator.lo libdap_la-DapIndent.lo libdap_la-XDRUtils.lo libdap_la-XDRFileMarshaller.lo libdap_la-XDRStreamMarshaller.lo libdap_la-XDRFileUnMarshaller.lo libdap_la-XDRStreamUnMarshaller.lo libdap_la-mime_util.lo libdap_la-Keywords2.lo libdap_la-XMLWriter.lo libdap_la-ServerFunctionsList.lo libdap_la-ServerFunction.lo libdap_la-DapXmlNamespaces.lo libdap_la-MarshallerThread.lo GNU/libdap_la-GetOpt.lo GNU/libdap_la-GNURegex.lo libdap_la-D4StreamMarshaller.lo libdap_la-D4StreamUnMarshaller.lo libdap_la-Int64.lo libdap_la-UInt64.lo libdap_la-Int8.lo libdap_la-D4ParserSax2.lo libdap_la-D4BaseTypeFactory.lo libdap_la-D4Dimensions.lo libdap_la-D4EnumDefs.lo libdap_la-D4Group.lo libdap_la-DMR.lo libdap_la-D4Attributes.lo libdap_la-D4Enum.lo libdap_la-chunked_ostream.lo libdap_la-chunked_istream.lo libdap_la-D4Sequence.lo libdap_la-D4Maps.lo libdap_la-D4Opaque.lo libdap_la-D4AsyncUtil.lo libdap_la-D4RValue.lo libdap_la-D4FilterClause.lo -lxml2 -lpthread gl/libgnu.la d4_ce/libd4_ce_parser.la d4_function/libd4_function_parser.la libparsers.la  -ltirpc 
libtool: link: x86_64-pc-linux-gnu-g++  -fPIC -DPIC -shared -nostdlib /usr/lib/gcc/x86_64-pc-linux-gnu/13/../../../../lib64/crti.o /usr/lib/gcc/x86_64-pc-linux-gnu/13/crtbeginS.o  .libs/libdap_la-AttrTable.o .libs/libdap_la-DAS.o .libs/libdap_la-DDS.o .libs/libdap_la-DataDDS.o .libs/libdap_la-DDXParserSAX2.o .libs/libdap_la-BaseType.o .libs/libdap_la-Byte.o .libs/libdap_la-Int32.o .libs/libdap_la-Float64.o .libs/libdap_la-Str.o .libs/libdap_la-Url.o .libs/libdap_la-Vector.o .libs/libdap_la-Array.o .libs/libdap_la-Structure.o .libs/libdap_la-Sequence.o .libs/libdap_la-Grid.o .libs/libdap_la-UInt32.o .libs/libdap_la-Int16.o .libs/libdap_la-UInt16.o .libs/libdap_la-Float32.o .libs/libdap_la-Constructor.o .libs/libdap_la-BaseTypeFactory.o .libs/libdap_la-SignalHandler.o .libs/libdap_la-Error.o .libs/libdap_la-InternalErr.o .libs/libdap_la-util.o .libs/libdap_la-xdrutil_ppc.o .libs/libdap_la-parser-util.o .libs/libdap_la-escaping.o .libs/libdap_la-Clause.o .libs/libdap_la-RValue.o .libs/libdap_la-ConstraintEvaluator.o .libs/libdap_la-DapIndent.o .libs/libdap_la-XDRUtils.o .libs/libdap_la-XDRFileMarshaller.o .libs/libdap_la-XDRStreamMarshaller.o .libs/libdap_la-XDRFileUnMarshaller.o .libs/libdap_la-XDRStreamUnMarshaller.o .libs/libdap_la-mime_util.o .libs/libdap_la-Keywords2.o .libs/libdap_la-XMLWriter.o .libs/libdap_la-ServerFunctionsList.o .libs/libdap_la-ServerFunction.o .libs/libdap_la-DapXmlNamespaces.o .libs/libdap_la-MarshallerThread.o GNU/.libs/libdap_la-GetOpt.o GNU/.libs/libdap_la-GNURegex.o .libs/libdap_la-D4StreamMarshaller.o .libs/libdap_la-D4StreamUnMarshaller.o .libs/libdap_la-Int64.o .libs/libdap_la-UInt64.o .libs/libdap_la-Int8.o .libs/libdap_la-D4ParserSax2.o .libs/libdap_la-D4BaseTypeFactory.o .libs/libdap_la-D4Dimensions.o .libs/libdap_la-D4EnumDefs.o .libs/libdap_la-D4Group.o .libs/libdap_la-DMR.o .libs/libdap_la-D4Attributes.o .libs/libdap_la-D4Enum.o .libs/libdap_la-chunked_ostream.o .libs/libdap_la-chunked_istream.o .libs/libdap_la-D4Sequence.o .libs/libdap_la-D4Maps.o .libs/libdap_la-D4Opaque.o .libs/libdap_la-D4AsyncUtil.o .libs/libdap_la-D4RValue.o .libs/libdap_la-D4FilterClause.o  -Wl,--whole-archive gl/.libs/libgnu.a d4_ce/.libs/libd4_ce_parser.a d4_function/.libs/libd4_function_parser.a ./.libs/libparsers.a -Wl,--no-whole-archive  -Wl,--as-needed -lpthread -lxml2 -ltirpc -L/usr/lib/gcc/x86_64-pc-linux-gnu/13 -L/usr/lib/gcc/x86_64-pc-linux-gnu/13/../../../../lib64 -L/lib/../lib64 -L/usr/lib/../lib64 -L/usr/lib/gcc/x86_64-pc-linux-gnu/13/../../../../x86_64-pc-linux-gnu/lib -L/usr/lib/gcc/x86_64-pc-linux-gnu/13/../../.. -lstdc++ -lm -lc -lgcc_s /usr/lib/gcc/x86_64-pc-linux-gnu/13/crtendS.o /usr/lib/gcc/x86_64-pc-linux-gnu/13/../../../../lib64/crtn.o  -g -O2 -march=native -fstack-protector-all -O2 -fdiagnostics-color=always -frecord-gcc-switches -flto=4 -Werror=odr -Werror=lto-type-mismatch -Werror=strict-aliasing -Werror=format-security -Wl,-O1 -flto=4 -Werror=odr -Werror=lto-type-mismatch -Werror=strict-aliasing -Wl,--defsym=__gentoo_check_ldflags__=0   -Wl,-soname -Wl,libdap.so.27 -o .libs/libdap.so.27.2.0
d4_ce/lex.d4_ce.cc:271:8: error: type 'struct yy_buffer_state' violates the C++ One Definition Rule [-Werror=odr]
  271 | #define YY_STRUCT_YY_BUFFER_STATE
      |        ^
lex.das.cc:445:8: note: a different type is defined in another translation unit
  445 | #define YY_STRUCT_YY_BUFFER_STATE
      |        ^
d4_ce/lex.d4_ce.cc:277:18: note: the first difference of corresponding definitions is field 'yy_input_file'
  277 | /* %if-c++-only */
      |                  ^
lex.das.cc:447:15: note: a field of same name but different type is defined in another translation unit
  447 |         {
      |               ^
d4_ce/lex.d4_ce.cc:271:8: note: type name 'std::basic_streambuf<char, std::char_traits<char> >' should match type name '_IO_FILE'
  271 | #define YY_STRUCT_YY_BUFFER_STATE
      |        ^
dds.tab.hh:123:7: error: type 'union YYSTYPE' violates the C++ One Definition Rule [-Werror=odr]
  123 | union YYSTYPE
      |       ^
Error.tab.hh:95:7: note: a different type is defined in another translation unit
   95 | union YYSTYPE
      |       ^
dds.yy:135:10: note: the first difference of corresponding definitions is field 'word'
  135 |     char word[ID_MAX];
      |          ^
Error.yy:83:9: note: a field with different name is defined in another translation unit
   83 |     int integer;
      |         ^
dds.tab.cc:412:7: error: type 'union yyalloc' violates the C++ One Definition Rule [-Werror=odr]
  412 | union yyalloc
      |       ^
ce_expr.tab.cc:490:7: note: a different type is defined in another translation unit
  490 | union yyalloc
      |       ^
dds.tab.cc:415:11: note: the first difference of corresponding definitions is field 'yyvs_alloc'
  415 |   YYSTYPE yyvs_alloc;
      |           ^
ce_expr.tab.cc:493:11: note: a field of same name but different type is defined in another translation unit
  493 |   YYSTYPE yyvs_alloc;
      |           ^
dds.tab.cc:412:7: note: type name 'YYSTYPE' should match type name 'CE_EXPRSTYPE'
  412 | union yyalloc
      |       ^
lto1: some warnings being treated as errors
lto-wrapper: fatal error: x86_64-pc-linux-gnu-g++ returned 1 exit status
compilation terminated.
/usr/lib/gcc/x86_64-pc-linux-gnu/13/../../../../x86_64-pc-linux-gnu/bin/ld: error: lto-wrapper failed
collect2: error: ld returned 1 exit status

Seems like there are multiple flex generated files with overlapping definitions that aren't being namespaced.

eli-schwartz commented 9 months ago

It also fails with strict-aliasing violations, specifically in the testsuite.

x86_64-pc-linux-gnu-g++ -DHAVE_CONFIG_H -I. -I..  -I../GNU -I.. -I../tests  -I/usr/include/libxml2 -I/usr/include/tirpc   --std=c++14   -g -O2  -march=native -fstack-protector-all -O2 -pipe -fdiagnostics-color=always -frecord-gcc-switches -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=3 -fstack-clash-protection -Werror=odr -Werror=lto-type-mismatch -Werror=strict-aliasing -Wformat -Werror=format-security -std=c++14 -c -o ddsT.o ddsT.cc
ddsT.cc: In member function ‘void ddsT::ddsT_test()’:
ddsT.cc:239:44: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
  239 |                 vs_iter &vsi = (vs_iter &) vsc;
      |                                            ^~~
ddsT.cc:274:44: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
  274 |                 vs_iter &vsi = (vs_iter &) vsc;
      |                                            ^~~
ddsT.cc:302:44: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
  302 |                 vs_iter &vsi = (vs_iter &) vsc;
      |                                            ^~~
ddsT.cc:303:45: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
  303 |                 vs_iter &vsi2 = (vs_iter &) vsc2;
      |                                             ^~~~
cc1plus: some warnings being treated as errors

Originally reported downstream: https://bugs.gentoo.org/878895

jgallagher59701 commented 9 months ago

OK, I'll look into this. Thanks.