Strict aliasing issue in threads

Đang mở
#2,340 3 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
48/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Ít trao đổi
Công nghệ
cpp
Lĩnh vực
operating-systems

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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

Ngôn ngữ chính
C++
Star
1.2k
Fork
305
Merge trung bình
3 ngày 2 giờ
Pull request đã merge (30 ngày)
11

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của KLayout/klayout

Tất cả issue của KLayout/klayout

Issue tương tự

Thêm issue về C++

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.