Build fails with LTO due to ODR violations
General
Escalation
General
Escalation
Description
Environment
Gentoo Linux
amd64
gcc (Gentoo 13.3.1_p20240614 p17) 13.3.1 20240614
Activity
Show:
Aaditya Dubey August 9, 2024 at 3:05 PM
Hi @Eli Schwartz
Thank you for the report.
Verified as described.
Build instructions:
sudo apt-get install libprocps-dev
git clone --recursive --depth=1 https://github.com/percona/percona-xtrabackup.git -b 8.0 PXB-8.0
cd PXB-8.0
mkdir target
git submodule init
git submodule update
cmake -DWITH_DEBUG=1 -DWITH_SSL=system -DFORCE_INSOURCE_BUILD=1 -DWITH_MAN_PAGES=OFF -DDOWNLOAD_BOOST=1 -DCMAKE_INSTALL_PREFIX=./target -DWITH_BOOST=/tmp/boost_$$/ -DCMAKE_CXX_FLAGS="-flto=4 -Werror=odr -Werror=lto-type-mismatch -Werror=strict-aliasing" && make -j4
...
/home/xxxx/PXB-8.0/sql/parser_yystype.h:340: note: the first difference of corresponding definitions is field ‘lexer’
340 | Lexer_yystype lexer; // terminal values from the lexical scanner
|
fts0pars.y:62: note: a field with different name is defined in another translation unit
/home/xxxx/PXB-8.0/storage/innobase/xtrabackup/src/file_utils.cc:69:20: error: type of ‘fil_page_get_type’ does not match original declaration [-Werror=lto-type-mismatch]
69 | inline page_type_t fil_page_get_type(const byte *page) {
| ^
/home/xxxx/PXB-8.0/storage/innobase/include/fil0fil.h:1828:20: note: return value type mismatch
1828 | inline page_type_t fil_page_get_type(const byte *page) {
| ^
/home/xxxx/PXB-8.0/storage/innobase/include/fil0fil.h:1828:20: note: ‘fil_page_get_type’ was previously declared here
/home/xxxx/PXB-8.0/storage/innobase/include/fil0fil.h:1828:20: note: code may be misoptimized unless ‘-fno-strict-aliasing’ is used
lto1: all warnings being treated as errors
lto-wrapper: fatal error: /usr/bin/c++ returned 1 exit status
compilation terminated.
/usr/bin/ld: error: lto-wrapper failed
collect2: error: ld returned 1 exit status
make[2]: *** [storage/innobase/xtrabackup/src/CMakeFiles/xtrabackup.dir/build.make:626: runtime_output_directory/xtrabackup] Error 1
make[1]: *** [CMakeFiles/Makefile2:4151: storage/innobase/xtrabackup/src/CMakeFiles/xtrabackup.dir/all] Error 2
make: *** [Makefile:152: all] Error 2
Details
Details
Assignee
Unassigned
UnassignedReporter
Eli Schwartz
Eli SchwartzNeeds QA
Yes
Affects versions
Priority
Smart Checklist
Open Smart Checklist
Smart Checklist

Open Smart Checklist
Created August 8, 2024 at 4:05 AM
Updated August 9, 2024 at 3:05 PM
I tried to build with the following *FLAGS to optimize the build:
-flto=4 -Werror=odr -Werror=lto-type-mismatch -Werror=strict-aliasing
Link-Time Optimization is a massively global compiler optimization pass which is pretty handy for producing faster executables. It also has the interesting property that because the compiler does whole-program analysis using bytecode, it can save type information and perform error checks that it normally doesn’t have enough insight for. In particular, checking for ODR issues and checking function type signature mismatches.
Note that all the -Werror=* flags are used to help detect cases where the compiler tries to optimize by assuming UB cannot exist in the source code -- if it does exist, ordinarily the code would be miscompiled, and this says to make the miscompilation a fatal error.
I got this error:
[100%] Linking CXX executable ../../../../runtime_output_directory/xtrabackup cd /var/tmp/portage/dev-db/percona-xtrabackup-8.3.0.1/work/percona-xtrabackup-8.3.0-1_build/storage/innobase/xtrabackup/src && /usr/bin/cmake -E cmake_link_script CMakeFiles/xtrabackup.dir/link.txt --verbose=1 /usr/lib/ccache/bin/x86_64-pc-linux-gnu-g++ -std=c++20 -fno-omit-frame-pointer -ftls-model=initial-exec -pipe -march=native -fstack-protector-all -O2 -fdiagnostics-color=always -frecord-gcc-switches -flto=3 -Werror=odr -Werror=lto-type-mismatch -Werror=strict-aliasing -Wformat -Werror=format-security -Wextra -Wformat-security -Wvla -Wundef -Wmissing-format-attribute -Woverloaded-virtual -Wcast-qual -Wimplicit-fallthrough=5 -Wno-stringop-truncation -Wsuggest-override -Wmissing-include-dirs -Wextra-semi -Wlogical-op -Wno-unused-parameter -Wno-cast-qual -ffunction-sections -fdata-sections -DNDEBUG -g1 -Wl,-O1 -Wl,--as-needed -Wl,-z,pack-relative-relocs -flto=3 -Werror=odr -Werror=lto-type-mismatch -Werror=strict-aliasing -Wl,--defsym=__gentoo_check_ldflags__=0 -Wl,--export-dynamic -rdynamic -Wl,--build-id=sha1 CMakeFiles/xtrabackup.dir/xtrabackup.cc.o CMakeFiles/xtrabackup.dir/changed_page_tracking.cc.o CMakeFiles/xtrabackup.dir/datasink.cc.o CMakeFiles/xtrabackup.dir/ds_buffer.cc.o CMakeFiles/xtrabackup.dir/ds_compress.cc.o CMakeFiles/xtrabackup.dir/ds_compress_lz4.cc.o CMakeFiles/xtrabackup.dir/ds_compress_zstd.cc.o CMakeFiles/xtrabackup.dir/ds_encrypt.cc.o CMakeFiles/xtrabackup.dir/ds_fifo.cc.o CMakeFiles/xtrabackup.dir/ds_local.cc.o CMakeFiles/xtrabackup.dir/ds_stdout.cc.o CMakeFiles/xtrabackup.dir/ds_tmpfile.cc.o CMakeFiles/xtrabackup.dir/ds_xbstream.cc.o CMakeFiles/xtrabackup.dir/fil_cur.cc.o CMakeFiles/xtrabackup.dir/file_utils.cc.o CMakeFiles/xtrabackup.dir/quicklz/quicklz.c.o CMakeFiles/xtrabackup.dir/read_filt.cc.o CMakeFiles/xtrabackup.dir/write_filt.cc.o CMakeFiles/xtrabackup.dir/wsrep.cc.o CMakeFiles/xtrabackup.dir/xbcrypt_common.cc.o CMakeFiles/xtrabackup.dir/xbcrypt_write.cc.o CMakeFiles/xtrabackup.dir/xbstream_write.cc.o CMakeFiles/xtrabackup.dir/backup_mysql.cc.o CMakeFiles/xtrabackup.dir/xb_dict.cc.o CMakeFiles/xtrabackup.dir/backup_copy.cc.o CMakeFiles/xtrabackup.dir/keyring_plugins.cc.o CMakeFiles/xtrabackup.dir/keyring_components.cc.o CMakeFiles/xtrabackup.dir/utils.cc.o CMakeFiles/xtrabackup.dir/kdf.cc.o CMakeFiles/xtrabackup.dir/space_map.cc.o CMakeFiles/xtrabackup.dir/redo_log_consumer.cc.o CMakeFiles/xtrabackup.dir/redo_log.cc.o "CMakeFiles/xtrabackup.dir/__/__/__/__/sql-common/client_authentication.cc.o" -o ../../../../runtime_output_directory/xtrabackup -laio ../../../../archive_output_directory/libsql_main.a ../../libinnobase.a ../../../../sql/libsql_dd.a ../../../../sql/libsql_gis.a ../../../../sql/librpl.a ../../../../sql/librpl_source.a ../../../../sql/librpl_replica.a ../../../../libservices/libmysqlservices.a ../../../../sql/libbinlog.a ../../../../archive_output_directory/libmysqlclient.a ../../../../components/libminchassis/libminchassis.a ../../../../archive_output_directory/libkeyring_common.a /usr/lib64/libgcrypt.so /usr/lib64/libgpg-error.so crc/libcrc.a -lproc2 ../../../../archive_output_directory/libsql_main.a ../../libinnobase.a ../../../../sql/libsql_dd.a ../../../../sql/libsql_gis.a ../../../../sql/librpl.a ../../../../sql/librpl_source.a ../../../../sql/librpl_replica.a ../../../../sql/libbinlog.a ../../../../archive_output_directory/libsql_main.a ../../libinnobase.a ../../../../sql/libsql_dd.a ../../../../sql/libsql_gis.a ../../../../sql/librpl.a ../../../../sql/librpl_source.a ../../../../sql/librpl_replica.a ../../../../sql/libbinlog.a /usr/lib64/libicuuc.so /usr/lib64/libicuio.so /usr/lib64/libicudata.so /usr/lib64/libicui18n.so ../../../archive/libarchive.a ../../../blackhole/libblackhole.a ../../../csv/libcsv.a ../../../federated/libfederated.a ../../../heap/libheap.a ../../../heap/libheap_library.a ../../../myisam/libmyisam.a ../../../myisam/libmyisam_library.a ../../../myisammrg/libmyisammrg.a ../../../perfschema/libperfschema.a ../../../temptable/libtemptable.a ../../../../sql/libmysql_native_password.a ../../../../sql/server_component/libmysql_server_component_services.a ../../../../archive_output_directory/libvio.a /usr/lib64/liblz4.so /usr/lib64/libprotobuf-lite.so ../../../../sql/protobuf/librpl_protobuf_lite.a ../../../../archive_output_directory/libmysql_binlog_event.a ../../../../archive_output_directory/libmysql_gtid.a ../../../../archive_output_directory/libmysys.a ../../../../archive_output_directory/libstrings.a ../../../../archive_output_directory/libmytime.a ../../../../archive_output_directory/libbacktrace.a ../../../../archive_output_directory/libmysql_serialization.a /usr/lib64/libz.so /usr/lib64/libssl.so /usr/lib64/libcrypto.so /usr/lib64/libzstd.so /usr/lib64/libresolv.so -lm -ldl ../../../../components/library_mysys/liblibrary_mysys.a -laio /var/tmp/portage/dev-db/percona-xtrabackup-8.3.0.1/work/percona-xtrabackup-8.3.0-1/storage/innobase/xtrabackup/src/ds_compress.cc:44:3: error: type ‘struct comp_thread_ctxt_t’ violates the C++ One Definition Rule [-Werror=odr] 44 | } comp_thread_ctxt_t; | ^ /var/tmp/portage/dev-db/percona-xtrabackup-8.3.0.1/work/percona-xtrabackup-8.3.0-1/storage/innobase/xtrabackup/src/ds_compress_lz4.cc:44:3: note: a different type is defined in another translation unit 44 | } comp_thread_ctxt_t; | ^ /var/tmp/portage/dev-db/percona-xtrabackup-8.3.0.1/work/percona-xtrabackup-8.3.0-1/storage/innobase/xtrabackup/src/ds_compress.cc:42:12: note: the first difference of corresponding definitions is field ‘adler’ 42 | uint32_t adler; | ^ /var/tmp/portage/dev-db/percona-xtrabackup-8.3.0.1/work/percona-xtrabackup-8.3.0-1/storage/innobase/xtrabackup/src/ds_compress_lz4.cc:44:3: note: a type with different number of fields is defined in another translation unit 44 | } comp_thread_ctxt_t; | ^ /var/tmp/portage/dev-db/percona-xtrabackup-8.3.0.1/work/percona-xtrabackup-8.3.0-1/storage/innobase/xtrabackup/src/ds_compress.cc:48:3: error: type ‘struct ds_compress_ctxt_t’ violates the C++ One Definition Rule [-Werror=odr] 48 | } ds_compress_ctxt_t; | ^ /var/tmp/portage/dev-db/percona-xtrabackup-8.3.0.1/work/percona-xtrabackup-8.3.0-1/storage/innobase/xtrabackup/src/ds_compress_zstd.cc:32:3: note: a different type is defined in another translation unit 32 | } ds_compress_ctxt_t; | ^ /var/tmp/portage/dev-db/percona-xtrabackup-8.3.0.1/work/percona-xtrabackup-8.3.0-1/storage/innobase/xtrabackup/src/ds_compress.cc:47:16: note: the first difference of corresponding definitions is field ‘thread_pool’ 47 | Thread_pool *thread_pool; | ^ /var/tmp/portage/dev-db/percona-xtrabackup-8.3.0.1/work/percona-xtrabackup-8.3.0-1/storage/innobase/xtrabackup/src/ds_compress_zstd.cc:31:20: note: a field of same name but different type is defined in another translation unit 31 | ZSTD_threadPool *thread_pool; | ^ /var/tmp/portage/dev-db/percona-xtrabackup-8.3.0.1/work/percona-xtrabackup-8.3.0-1/storage/innobase/xtrabackup/src/thread_pool.h:33:7: note: type name ‘Thread_pool’ should match type name ‘POOL_ctx_s’ 33 | class Thread_pool { | ^ /var/tmp/portage/dev-db/percona-xtrabackup-8.3.0.1/work/percona-xtrabackup-8.3.0-1/storage/innobase/xtrabackup/src/ds_compress.cc:58:3: error: type ‘struct ds_compress_file_t’ violates the C++ One Definition Rule [-Werror=odr] 58 | } ds_compress_file_t; | ^ /var/tmp/portage/dev-db/percona-xtrabackup-8.3.0.1/work/percona-xtrabackup-8.3.0-1/storage/innobase/xtrabackup/src/ds_compress_zstd.cc:41:3: note: a different type is defined in another translation unit 41 | } ds_compress_file_t; | ^ /var/tmp/portage/dev-db/percona-xtrabackup-8.3.0.1/work/percona-xtrabackup-8.3.0-1/storage/innobase/xtrabackup/src/ds_compress.cc:52:23: note: the first difference of corresponding definitions is field ‘comp_ctxt’ 52 | ds_compress_ctxt_t *comp_ctxt; | ^ /var/tmp/portage/dev-db/percona-xtrabackup-8.3.0.1/work/percona-xtrabackup-8.3.0-1/storage/innobase/xtrabackup/src/ds_compress_zstd.cc:36:9: note: a field with different name is defined in another translation unit 36 | char *comp_buf; | ^ /var/tmp/portage/dev-db/percona-xtrabackup-8.3.0.1/work/percona-xtrabackup-8.3.0-1/include/sql_common.h:100:8: error: type ‘struct MYSQL_EXTENSION’ violates the C++ One Definition Rule [-Werror=odr] 100 | struct MYSQL_EXTENSION { | ^ /var/tmp/portage/dev-db/percona-xtrabackup-8.3.0.1/work/percona-xtrabackup-8.3.0-1/include/sql_common.h:100: note: a different type is defined in another translation unit 100 | struct MYSQL_EXTENSION { | /var/tmp/portage/dev-db/percona-xtrabackup-8.3.0.1/work/percona-xtrabackup-8.3.0-1/include/sql_common.h:115:5: note: the first difference of corresponding definitions is field ‘bind_info’ 115 | } bind_info; | ^ /var/tmp/portage/dev-db/percona-xtrabackup-8.3.0.1/work/percona-xtrabackup-8.3.0-1/include/sql_common.h:107: note: a field with different name is defined in another translation unit 107 | NET_SERVER *server_extn; | lto1: some warnings being treated as errors lto-wrapper: fatal error: /usr/bin/x86_64-pc-linux-gnu-g++ returned 1 exit status compilation terminated. /usr/libexec/gcc/x86_64-pc-linux-gnu/ld: error: lto-wrapper failed collect2: error: ld returned 1 exit status make[2]: *** [storage/innobase/xtrabackup/src/CMakeFiles/xtrabackup.dir/build.make:674: runtime_output_directory/xtrabackup] Error 1 make[2]: Leaving directory '/var/tmp/portage/dev-db/percona-xtrabackup-8.3.0.1/work/percona-xtrabackup-8.3.0-1_build' make[1]: *** [CMakeFiles/Makefile2:3213: storage/innobase/xtrabackup/src/CMakeFiles/xtrabackup.dir/all] Error 2 make: *** [Makefile:156: all] Error 2
This was originally reported downstream at https://bugs.gentoo.org/855245
I reproduced it with versions 8.0.30-23 and 8.3.0-1.