Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

Tests fail with LTO due to ODR / type mismatch violations

オープン
#121 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
35/100
issue の種類
バグ
明瞭さ
説明が足りない
活発さ
停滞
技術スタック
cpp
領域
backend

調査の方向性

boost/smart_ptr/detail/sp_counted_base_gcc_atomic.hpp と boost/smart_ptr/detail/sp_counted_base_nt.hpp から始め、sp_counted_base のフィールドと、GCC が報告した release、weak_release、destroy の宣言を比較します。示されている LTO と -Werror のフラグで失敗を再現し、その後、影響を受ける abi_test_mt_nt テストと abi_test_nt_mt テストを実行します。これらのテストが ODR エラーと型不一致エラーなしで正常にビルドできれば完了です。

索引モデルが issue の本文から書いたものです。

説明

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:

gcc.link ../../../bin.v2/libs/smart_ptr/test/abi_test_mt_nt.test/gcc-14.3/gentoorelease/x86_64/pch-off/threading-multi/visibility-hidden/abi_test_mt_nt

    "x86_64-pc-linux-gnu-g++"  -Wl,-rpath -Wl,"/var/tmp/portage/dev-libs/boost-1.89.0/work/boost_1_89_0-abi_x86_64.amd64/bin.v2/libs/atomic/build/gcc-14.3/gentoorelease/x86_64/pch-off/threading-multi/visibility-hidden" -Wl,-rpath-link -Wl,"/var/tmp/portage/dev-libs/boost-1.89.0/work/boost_1_89_0-abi_x86_64.amd64/bin.v2/libs/atomic/build/gcc-14.3/gentoorelease/x86_64/pch-off/threading-multi/visibility-hidden" -o "../../../bin.v2/libs/smart_ptr/test/abi_test_mt_nt.test/gcc-14.3/gentoorelease/x86_64/pch-off/threading-multi/visibility-hidden/abi_test_mt_nt" -Wl,--start-group "../../../bin.v2/libs/smart_ptr/test/abi_test_mt_nt.test/gcc-14.3/gentoorelease/x86_64/pch-off/threading-multi/visibility-hidden/abi_test_main.o" "../../../bin.v2/libs/smart_ptr/test/gcc-14.3/gentoorelease/x86_64/link-static/pch-off/threading-multi/visibility-hidden/libabi_test_nt.a" "../../../bin.v2/libs/atomic/build/gcc-14.3/gentoorelease/x86_64/pch-off/threading-multi/visibility-hidden/libboost_atomic.so.1.89.0" "../../../bin.v2/libs/atomic/build/gcc-14.3/gentoorelease/x86_64/link-static/pch-off/threading-multi/visibility-hidden/libboost_atomic.a"  -Wl,-Bstatic  -Wl,-Bdynamic -lrt -Wl,--end-group -fPIC -m64 -pthread -fvisibility=hidden -fvisibility-inlines-hidden -Wl,-O1 -Wl,--as-needed -Wl,-z,pack-relative-relocs -flto=4 -Werror=odr -Werror=lto-type-mismatch -Werror=strict-aliasing -Wl,--defsym=__gentoo_check_ldflags__=0 

../../../boost/smart_ptr/detail/sp_counted_base_gcc_atomic.hpp:70:28: error: type ‘struct sp_counted_base’ violates the C++ One Definition Rule [-Werror=odr]
   70 | class BOOST_SYMBOL_VISIBLE sp_counted_base
      |                            ^
../../../boost/smart_ptr/detail/sp_counted_base_nt.hpp:38:28: note: a different type is defined in another translation unit
   38 | class BOOST_SYMBOL_VISIBLE sp_counted_base
      |                            ^
../../../boost/smart_ptr/detail/sp_counted_base_gcc_atomic.hpp:77:27: note: the first difference of corresponding definitions is field ‘use_count_’
   77 |     boost::uint_least32_t use_count_;        // #shared
      |                           ^
../../../boost/smart_ptr/detail/sp_counted_base_nt.hpp:45:26: note: a field of same name but different type is defined in another translation unit
   45 |     boost::int_least32_t use_count_;        // #shared
      |                          ^
../../../boost/smart_ptr/detail/sp_counted_base_gcc_atomic.hpp:70:28: note: type ‘uint_least32_t’ should match type ‘int_least32_t’
   70 | class BOOST_SYMBOL_VISIBLE sp_counted_base
      |                            ^
../../../boost/smart_ptr/detail/sp_counted_base_nt.hpp:86:10: error: type of ‘release’ does not match original declaration [-Werror=lto-type-mismatch]
   86 |     void release() noexcept
      |          ^
../../../boost/smart_ptr/detail/sp_counted_base_gcc_atomic.hpp:116:10: note: ‘release’ was previously declared here
  116 |     void release() // nothrow
      |          ^
../../../boost/smart_ptr/detail/sp_counted_base_gcc_atomic.hpp:116:10: note: code may be misoptimized unless ‘-fno-strict-aliasing’ is used
../../../boost/smart_ptr/detail/sp_counted_base_nt.hpp:100:10: error: type of ‘weak_release’ does not match original declaration [-Werror=lto-type-mismatch]
  100 |     void weak_release() noexcept
      |          ^
../../../boost/smart_ptr/detail/sp_counted_base_gcc_atomic.hpp:130:10: note: ‘weak_release’ was previously declared here
  130 |     void weak_release() // nothrow
      |          ^
../../../boost/smart_ptr/detail/sp_counted_base_gcc_atomic.hpp:130:10: note: code may be misoptimized unless ‘-fno-strict-aliasing’ is used
../../../boost/smart_ptr/detail/sp_counted_base_nt.hpp:65:18: error: type of ‘destroy’ does not match original declaration [-Werror=lto-type-mismatch]
   65 |     virtual void destroy() noexcept // nothrow
      |                  ^
../../../boost/smart_ptr/detail/sp_counted_base_gcc_atomic.hpp:97:18: note: ‘destroy’ was previously declared here
   97 |     virtual void destroy() // nothrow
      |                  ^
../../../boost/smart_ptr/detail/sp_counted_base_gcc_atomic.hpp:97:18: note: code may be misoptimized unless ‘-fno-strict-aliasing’ is used
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/lib/gcc/x86_64-pc-linux-gnu/14/../../../../x86_64-pc-linux-gnu/bin/ld: error: lto-wrapper failed
collect2: error: ld returned 1 exit status
...skipped <p../../../bin.v2/libs/smart_ptr/test/abi_test_mt_nt.test/gcc-14.3/gentoorelease/x86_64/pch-off/threading-multi/visibility-hidden>abi_test_mt_nt.run for lack of <p../../../bin.v2/libs/smart_ptr/test/abi_test_mt_nt.test/gcc-14.3/gentoorelease/x86_64/pch-off/threading-multi/visibility-hidden>abi_test_mt_nt...
common.mkdir ../../../bin.v2/libs/smart_ptr/test/get_deleter_test2_no_rtti.test

        mkdir -p "../../../bin.v2/libs/smart_ptr/test/get_deleter_test2_no_rtti.test"
    
gcc.link ../../../bin.v2/libs/smart_ptr/test/abi_test_nt_mt.test/gcc-14.3/gentoorelease/x86_64/pch-off/threading-multi/visibility-hidden/abi_test_nt_mt

    "x86_64-pc-linux-gnu-g++"  -Wl,-rpath -Wl,"/var/tmp/portage/dev-libs/boost-1.89.0/work/boost_1_89_0-abi_x86_64.amd64/bin.v2/libs/atomic/build/gcc-14.3/gentoorelease/x86_64/pch-off/threading-multi/visibility-hidden" -Wl,-rpath-link -Wl,"/var/tmp/portage/dev-libs/boost-1.89.0/work/boost_1_89_0-abi_x86_64.amd64/bin.v2/libs/atomic/build/gcc-14.3/gentoorelease/x86_64/pch-off/threading-multi/visibility-hidden" -o "../../../bin.v2/libs/smart_ptr/test/abi_test_nt_mt.test/gcc-14.3/gentoorelease/x86_64/pch-off/threading-multi/visibility-hidden/abi_test_nt_mt" -Wl,--start-group "../../../bin.v2/libs/smart_ptr/test/abi_test_nt_mt.test/gcc-14.3/gentoorelease/x86_64/pch-off/threading-multi/visibility-hidden/abi_test_main.o" "../../../bin.v2/libs/smart_ptr/test/gcc-14.3/gentoorelease/x86_64/link-static/pch-off/threading-multi/visibility-hidden/libabi_test_mt.a" "../../../bin.v2/libs/atomic/build/gcc-14.3/gentoorelease/x86_64/pch-off/threading-multi/visibility-hidden/libboost_atomic.so.1.89.0" "../../../bin.v2/libs/atomic/build/gcc-14.3/gentoorelease/x86_64/link-static/pch-off/threading-multi/visibility-hidden/libboost_atomic.a"  -Wl,-Bstatic  -Wl,-Bdynamic -lrt -Wl,--end-group -fPIC -m64 -pthread -fvisibility=hidden -fvisibility-inlines-hidden -Wl,-O1 -Wl,--as-needed -Wl,-z,pack-relative-relocs -flto=4 -Werror=odr -Werror=lto-type-mismatch -Werror=strict-aliasing -Wl,--defsym=__gentoo_check_ldflags__=0 

../../../boost/smart_ptr/detail/sp_counted_base_nt.hpp:38:28: error: type ‘struct sp_counted_base’ violates the C++ One Definition Rule [-Werror=odr]
   38 | class BOOST_SYMBOL_VISIBLE sp_counted_base
      |                            ^
../../../boost/smart_ptr/detail/sp_counted_base_gcc_atomic.hpp:70:28: note: a different type is defined in another translation unit
   70 | class BOOST_SYMBOL_VISIBLE sp_counted_base
      |                            ^
../../../boost/smart_ptr/detail/sp_counted_base_nt.hpp:45:26: note: the first difference of corresponding definitions is field ‘use_count_’
   45 |     boost::int_least32_t use_count_;        // #shared
      |                          ^
../../../boost/smart_ptr/detail/sp_counted_base_gcc_atomic.hpp:77:27: note: a field of same name but different type is defined in another translation unit
   77 |     boost::uint_least32_t use_count_;        // #shared
      |                           ^
../../../boost/smart_ptr/detail/sp_counted_base_nt.hpp:38:28: note: type ‘int_least32_t’ should match type ‘uint_least32_t’
   38 | class BOOST_SYMBOL_VISIBLE sp_counted_base
      |                            ^
../../../boost/smart_ptr/detail/sp_counted_base_gcc_atomic.hpp:116:10: error: type of ‘release’ does not match original declaration [-Werror=lto-type-mismatch]
  116 |     void release() // nothrow
      |          ^
../../../boost/smart_ptr/detail/sp_counted_base_nt.hpp:86:10: note: ‘release’ was previously declared here
   86 |     void release() noexcept
      |          ^
../../../boost/smart_ptr/detail/sp_counted_base_nt.hpp:86:10: note: code may be misoptimized unless ‘-fno-strict-aliasing’ is used
../../../boost/smart_ptr/detail/sp_counted_base_gcc_atomic.hpp:130:10: error: type of ‘weak_release’ does not match original declaration [-Werror=lto-type-mismatch]
  130 |     void weak_release() // nothrow
      |          ^
../../../boost/smart_ptr/detail/sp_counted_base_nt.hpp:100:10: note: ‘weak_release’ was previously declared here
  100 |     void weak_release() noexcept
      |          ^
../../../boost/smart_ptr/detail/sp_counted_base_nt.hpp:100:10: note: code may be misoptimized unless ‘-fno-strict-aliasing’ is used
../../../boost/smart_ptr/detail/sp_counted_base_gcc_atomic.hpp:97:18: error: type of ‘destroy’ does not match original declaration [-Werror=lto-type-mismatch]
   97 |     virtual void destroy() // nothrow
      |                  ^
../../../boost/smart_ptr/detail/sp_counted_base_nt.hpp:65:18: note: ‘destroy’ was previously declared here
   65 |     virtual void destroy() noexcept // nothrow
      |                  ^
../../../boost/smart_ptr/detail/sp_counted_base_nt.hpp:65:18: note: code may be misoptimized unless ‘-fno-strict-aliasing’ is used
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/lib/gcc/x86_64-pc-linux-gnu/14/../../../../x86_64-pc-linux-gnu/bin/ld: error: lto-wrapper failed
collect2: error: ld returned 1 exit status
...skipped <p../../../bin.v2/libs/smart_ptr/test/abi_test_nt_mt.test/gcc-14.3/gentoorelease/x86_64/pch-off/threading-multi/visibility-hidden>abi_test_nt_mt.run for lack of <p../../../bin.v2/libs/smart_ptr/test/abi_test_nt_mt.test/gcc-14.3/gentoorelease/x86_64/pch-off/threading-multi/visibility-hidden>abi_test_nt_mt...
common.mkdir ../../../bin.v2/libs/smart_ptr/test/get_deleter_test2_no_rtti.test/gcc-14.3

        mkdir -p "../../../bin.v2/libs/smart_ptr/test/get_deleter_test2_no_rtti.test/gcc-14.3"

Originally reported downstream: https://bugs.gentoo.org/956660
Full build log: build.log

主要言語
C++
スター
111
フォーク
116
PR マージ指標
30日以内にマージされた PR はありません

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

boostorg/smart_ptr のほかの issue

boostorg/smart_ptr の issue をすべて見る

似ている issue

C++ の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。