Strict aliasing issue in threads
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 48/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Quiet
- Tech stack
- cpp
- Domain
- operating-systems
Research direction
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.
Written by the indexing model from the issue text.
Description
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
- Dominant language
- C++
- Stars
- 1.2k
- Forks
- 305
- Avg merge
- 3d 2h
- Merged PRs (30d)
- 11
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from KLayout/klayout
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
KLayout/klayout#2554 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
KLayout/klayout#2412 · 3 comments ·
Maintainers usually reply within 1 day
-
DRC functions not working properly with clip in placePossibly taken @klayoutmatthias claimed this today. Openbug
KLayout/klayout#2553 · 1 assignee ·
Maintainers usually reply within 1 day
-
Difficulty 3/5 1-2 days Newbie friendliness 50/100
Maintainers usually reply within 1 day
-
Deep DRC can miss violations when a cell has many shapesMay be free again A pull request for this issue was closed without being merged. Open
Difficulty 4/5 3-5 days Newbie friendliness 52/100
KLayout/klayout#2546 · 5 comments ·
Maintainers usually reply within 1 day
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 3 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
LaneDibello/Kotor-Patch-Manager#375 ·
Maintainers usually reply within 2 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
Maintainers usually reply within 1 day