Strict aliasing issue in threads

オープン
#2,340 コメント 3 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

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

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
48/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
静か
技術スタック
cpp

調査の方向性

Start with src/plugins/streamers/lstream/runtime/kj/kj/thread.cc around the reported calls and thread.h around the threadId declaration. Check how the thread identifier is represented and used across platforms, then build with -Werror=strict-aliasing to reproduce the reported diagnostics. Done means the strict-aliasing errors are resolved without assuming a particular representation for pthread_t.

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

説明

Originally reported downstream in Gentoo at https://bugs.gentoo.org/973164. We build with -Werror=strict-aliasing to help catch future compiler incompatibilities.

x86_64-pc-linux-gnu-g++ -c -O2 -pipe -march=x86-64 -mtune=generic -g -Werror=odr -Werror=lto-type-mismatch -Werror=strict-aliasing -Wno-unused-parameter -fPIC -Wall -Wextra -mno-direct-extern-access -D_REENTRANT -DCAPNP_LITE -DQT_NO_DEBUG -I/var/tmp/portage/sci-electronics/klayout-0.30.7/work/ruby33/klayout-0.30.7/src/plugins/streamers/lstream/runtime/kj -I/var/tmp/portage/sci-electronics/klayout-0.30.7/work/ruby33/klayout-0.30.7/plugins/streamers/lstream/runtime/kj -I/var/tmp/portage/sci-electronics/klayout-0.30.7/work/ruby33/klayout-0.30.7/src/plugins/streamers/lstream/runtime/capnp -I/var/tmp/portage/sci-electronics/klayout-0.30.7/work/ruby33/klayout-0.30.7/src/plugins/streamers/lstream/runtime/kj -I/usr/lib64/qt6/mkspecs/linux-g++ -o thread.o /var/tmp/portage/sci-electronics/klayout-0.30.7/work/ruby33/klayout-0.30.7/src/plugins/streamers/lstream/runtime/kj/kj/thread.cc
/var/tmp/portage/sci-electronics/klayout-0.30.7/work/ruby33/klayout-0.30.7/src/plugins/streamers/lstream/runtime/kj/kj/thread.cc: In destructor ‘kj::Thread::~Thread()’:
/var/tmp/portage/sci-electronics/klayout-0.30.7/work/ruby33/klayout-0.30.7/src/plugins/streamers/lstream/runtime/kj/kj/thread.cc:82:39: error: dereferencing type-punned pointer will break strict-aliasing rules
[-Werror=strict-aliasing]
   82 |     int pthreadResult = pthread_join(*reinterpret_cast<pthread_t*>(&threadId), nullptr);
      |                                       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/var/tmp/portage/sci-electronics/klayout-0.30.7/work/ruby33/klayout-0.30.7/src/plugins/streamers/lstream/runtime/kj/kj/thread.cc: In member function ‘void kj::Thread::sendSignal(int)’:
/var/tmp/portage/sci-electronics/klayout-0.30.7/work/ruby33/klayout-0.30.7/src/plugins/streamers/lstream/runtime/kj/kj/thread.cc:96:37: error: dereferencing type-punned pointer will break strict-aliasing rules
[-Werror=strict-aliasing]
   96 |   int pthreadResult = pthread_kill(*reinterpret_cast<pthread_t*>(&threadId), signo);
      |                                     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/var/tmp/portage/sci-electronics/klayout-0.30.7/work/ruby33/klayout-0.30.7/src/plugins/streamers/lstream/runtime/kj/kj/thread.cc: In member function ‘void kj::Thread::detach()’:
/var/tmp/portage/sci-electronics/klayout-0.30.7/work/ruby33/klayout-0.30.7/src/plugins/streamers/lstream/runtime/kj/kj/thread.cc:103:39: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
  103 |   int pthreadResult = pthread_detach(*reinterpret_cast<pthread_t*>(&threadId));
      |                                       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cc1plus: some warnings being treated as errors
make[5]: *** [Makefile:1227: thread.o] Error 1
make[5]: *** Waiting for unfinished jobs....

The violation is at https://github.com/KLayout/klayout/blob/5ccf6260f1769e7431901101bf27d01b68df177e/src/plugins/streamers/lstream/runtime/kj/kj/thread.cc#L70

pthread_t is an opaque type, it shouldn't be assumed to be unsigned long long:
https://github.com/KLayout/klayout/blob/5ccf6260f1769e7431901101bf27d01b68df177e/src/plugins/streamers/lstream/runtime/kj/kj/thread.h#L69

I assume this is done for compatibility with Windows, otherwise pthread_t would've been used. But pthread_t is an opaque type: https://stackoverflow.com/questions/33285562/why-and-in-what-sense-is-pthread-t-an-opaque-type

主要言語
C++
スター
1.2k
フォーク
305
平均マージ
3日 2時間
マージ済み PR(30日)
11

環境構築

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

はじめの一歩

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

KLayout/klayout のほかの issue

KLayout/klayout の issue をすべて見る

似ている issue

C++ の issue をもっと見る

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

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