Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing thread start_routine signatures in tests #2

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

abujalski
Copy link

pthread_create function requires that start_routine has void*(void*) signature. However many tests defined this function as void*(void). When compiling such test to native code such pointer was implicitly casted. In case of Emscripten such casts are won't work and resulted in exception thrown at JavaScript side.

This PR adjust tests start_routine to have proper signature.

pthread_create function requires that start_routine has void*(void*)
signature. However many tests defined this function as void*(void). When
compiling such test to native code such pointer was implicitly casted.
In case of Emscripten such casts are won't work and resulted in exception
thrown at JavaScript side.

This patch adjust tests start_routine to have proper signature.
@sbc100
Copy link
Contributor

sbc100 commented Aug 17, 2021

I this still needed? are all those tests currently failing?

@kleisauke
Copy link
Collaborator

I remembered that this was necessary when compiling with ASan, see for example:
https://github.com/emscripten-core/emscripten/blob/82ba35622ce7377c8b2f5f3859a8b41ee1c3f495/tests/test_posixtest.py#L160-L168

But perhaps this can also manifest when compiling without optimizations (or with assertions enabled)?

@kleisauke
Copy link
Collaborator

fwiw, there are still some non-matching signatures on this branch. Issue #6 might also be relevant here.

sed -i 's/CFLAGS =/& -fpermissive/' Makefile
sed -i '/check_gcc/,+2d' Makefile
for test in `ls -d conformance/interfaces/pthread_*`; do POSIX_TARGET=$test CC=g++ make build-tests LDFLAGS='-pthread'; done
cat logfile | grep -A 4 -- "-Werror=permissive"
Details (filtered)
conformance/interfaces/pthread_attr_setstack/2-1.c:114:45: error: invalid conversion from ‘void* (*)()’ to ‘void* (*)(void*)’ [-Werror=permissive]
  114 |         rc = pthread_create(&new_th, &attr, thread_func, NULL);
      |                                             ^~~~~~~~~~~
      |                                             |
      |                                             void* (*)()
--
conformance/interfaces/pthread_attr_setstacksize/2-1.c:101:45: error: invalid conversion from ‘void* (*)()’ to ‘void* (*)(void*)’ [-Werror=permissive]
  101 |         rc = pthread_create(&new_th, &attr, thread_func, NULL);
      |                                             ^~~~~~~~~~~
      |                                             |
      |                                             void* (*)()
--
conformance/interfaces/pthread_barrierattr_getpshared/2-1.c:76:26: error: invalid conversion from ‘void (*)()’ to ‘__sighandler_t’ {aka ‘void (*)(int)’} [-Werror=permissive]
   76 |         act.sa_handler = sig_handler;
      |                          ^~~~~~~~~~~
      |                          |
      |                          void (*)()
--
conformance/interfaces/pthread_barrier_init/4-1.c:81:26: error: invalid conversion from ‘void (*)()’ to ‘__sighandler_t’ {aka ‘void (*)(int)’} [-Werror=permissive]
   81 |         act.sa_handler = sig_handler;
      |                          ^~~~~~~~~~~
      |                          |
      |                          void (*)()
--
conformance/interfaces/pthread_barrier_wait/1-1.c:75:26: error: invalid conversion from ‘void (*)()’ to ‘__sighandler_t’ {aka ‘void (*)(int)’} [-Werror=permissive]
   75 |         act.sa_handler = sig_handler;
      |                          ^~~~~~~~~~~
      |                          |
      |                          void (*)()
--
conformance/interfaces/pthread_barrier_wait/3-1.c:58:26: error: invalid conversion from ‘void (*)()’ to ‘__sighandler_t’ {aka ‘void (*)(int)’} [-Werror=permissive]
   58 |         act.sa_handler = sig_handler;
      |                          ^~~~~~~~~~~
      |                          |
      |                          void (*)()
--
conformance/interfaces/pthread_barrier_wait/3-2.c:65:26: error: invalid conversion from ‘void (*)()’ to ‘__sighandler_t’ {aka ‘void (*)(int)’} [-Werror=permissive]
   65 |         act.sa_handler = sig_handler;
      |                          ^~~~~~~~~~~
      |                          |
      |                          void (*)()
--
conformance/interfaces/pthread_barrier_wait/6-1.c:41:26: error: invalid conversion from ‘void (*)()’ to ‘__sighandler_t’ {aka ‘void (*)(int)’} [-Werror=permissive]
   41 |         act.sa_handler = sig_handler;
      |                          ^~~~~~~~~~~
      |                          |
      |                          void (*)()
--
conformance/interfaces/pthread_create/10-1.c:110:44: error: invalid conversion from ‘void* (*)()’ to ‘void* (*)(void*)’ [-Werror=permissive]
  110 |         pthread_create(&new_th, &inv_attr, a_thread_func, NULL);
      |                                            ^~~~~~~~~~~~~
      |                                            |
      |                                            void* (*)()
--
conformance/interfaces/pthread_create/11-1.c:55:42: error: invalid conversion from ‘void* (*)()’ to ‘void* (*)(void*)’ [-Werror=permissive]
   55 |         if(pthread_create(&new_th, NULL, a_thread_func, NULL) != 0)
      |                                          ^~~~~~~~~~~~~
      |                                          |
      |                                          void* (*)()
--
conformance/interfaces/pthread_create/8-1.c:91:42: error: invalid conversion from ‘void* (*)()’ to ‘void* (*)(void*)’ [-Werror=permissive]
   91 |         if(pthread_create(&new_th, NULL, a_thread_func, NULL) != 0)
      |                                          ^~~~~~~~~~~~~
      |                                          |
      |                                          void* (*)()
--
conformance/interfaces/pthread_getcpuclockid/speculative/3-1.c:43:44: error: invalid conversion from ‘void* (*)()’ to ‘void* (*)(void*)’ [-Werror=permissive]
   43 |         rc = pthread_create(&new_th, NULL, thread_func, NULL);
      |                                            ^~~~~~~~~~~
      |                                            |
      |                                            void* (*)()
--
conformance/interfaces/pthread_join/speculative/6-1.c:55:43: error: invalid conversion from ‘void* (*)()’ to ‘void* (*)(void*)’ [-Werror=permissive]
   55 |         if(pthread_create(&new_th, &attr, a_thread_func, NULL) != 0)
      |                                           ^~~~~~~~~~~~~
      |                                           |
      |                                           void* (*)()
--
conformance/interfaces/pthread_kill/1-1.c:62:26: error: invalid conversion from ‘void (*)()’ to ‘__sighandler_t’ {aka ‘void (*)(int)’} [-Werror=permissive]
   62 |         act.sa_handler = handler;
      |                          ^~~~~~~
      |                          |
      |                          void (*)()
--
conformance/interfaces/pthread_kill/1-1.c:84:42: error: invalid conversion from ‘void* (*)()’ to ‘void* (*)(void*)’ [-Werror=permissive]
   84 |         if(pthread_create(&new_th, NULL, a_thread_func, NULL) != 0)
      |                                          ^~~~~~~~~~~~~
      |                                          |
      |                                          void* (*)()
conformance/interfaces/pthread_rwlock_rdlock/4-1.c:67:26: error: invalid conversion from ‘void (*)()’ to ‘__sighandler_t’ {aka ‘void (*)(int)’} [-Werror=permissive]
   67 |         act.sa_handler = sig_handler;
      |                          ^~~~~~~~~~~
      |                          |
      |                          void (*)()
--
conformance/interfaces/pthread_rwlock_timedrdlock/6-1.c:87:26: error: invalid conversion from ‘void (*)()’ to ‘__sighandler_t’ {aka ‘void (*)(int)’} [-Werror=permissive]
   87 |         act.sa_handler = sig_handler;
      |                          ^~~~~~~~~~~
      |                          |
      |                          void (*)()
--
conformance/interfaces/pthread_rwlock_timedrdlock/6-2.c:94:26: error: invalid conversion from ‘void (*)()’ to ‘__sighandler_t’ {aka ‘void (*)(int)’} [-Werror=permissive]
   94 |         act.sa_handler = sig_handler;
      |                          ^~~~~~~~~~~
      |                          |
      |                          void (*)()
--
conformance/interfaces/pthread_rwlock_timedwrlock/6-1.c:87:26: error: invalid conversion from ‘void (*)()’ to ‘__sighandler_t’ {aka ‘void (*)(int)’} [-Werror=permissive]
   87 |         act.sa_handler = sig_handler;
      |                          ^~~~~~~~~~~
      |                          |
      |                          void (*)()
--
conformance/interfaces/pthread_rwlock_timedwrlock/6-2.c:94:26: error: invalid conversion from ‘void (*)()’ to ‘__sighandler_t’ {aka ‘void (*)(int)’} [-Werror=permissive]
   94 |         act.sa_handler = sig_handler;
      |                          ^~~~~~~~~~~
      |                          |
      |                          void (*)()
--
conformance/interfaces/pthread_rwlock_wrlock/2-1.c:67:26: error: invalid conversion from ‘void (*)()’ to ‘__sighandler_t’ {aka ‘void (*)(int)’} [-Werror=permissive]
   67 |         act.sa_handler = sig_handler;
      |                          ^~~~~~~~~~~
      |                          |
      |                          void (*)()
--
conformance/interfaces/pthread_sigmask/10-1.c:57:47: error: invalid conversion from ‘void* (*)()’ to ‘void* (*)(void*)’ [-Werror=permissive]
   57 |         if (pthread_create(&new_thread, NULL, a_thread_func, NULL) != 0) {
      |                                               ^~~~~~~~~~~~~
      |                                               |
      |                                               void* (*)()
--
conformance/interfaces/pthread_sigmask/12-1.c:110:47: error: invalid conversion from ‘void* (*)()’ to ‘void* (*)(void*)’ [-Werror=permissive]
  110 |         if (pthread_create(&new_thread, NULL, a_thread_func, NULL) != 0) {
      |                                               ^~~~~~~~~~~~~
      |                                               |
      |                                               void* (*)()
--
conformance/interfaces/pthread_sigmask/14-1.c:49:47: error: invalid conversion from ‘void* (*)()’ to ‘void* (*)(void*)’ [-Werror=permissive]
   49 |         if (pthread_create(&new_thread, NULL, a_thread_func, NULL) != 0) {
      |                                               ^~~~~~~~~~~~~
      |                                               |
      |                                               void* (*)()
--
conformance/interfaces/pthread_sigmask/16-1.c:64:47: error: invalid conversion from ‘void* (*)()’ to ‘void* (*)(void*)’ [-Werror=permissive]
   64 |         if (pthread_create(&new_thread, NULL, a_thread_func, NULL) != 0) {
      |                                               ^~~~~~~~~~~~~
      |                                               |
      |                                               void* (*)()
--
conformance/interfaces/pthread_sigmask/4-1.c:109:47: error: invalid conversion from ‘void* (*)()’ to ‘void* (*)(void*)’ [-Werror=permissive]
  109 |         if (pthread_create(&new_thread, NULL, a_thread_func, NULL) != 0) {
      |                                               ^~~~~~~~~~~~~
      |                                               |
      |                                               void* (*)()
--
conformance/interfaces/pthread_sigmask/5-1.c:129:49: error: invalid conversion from ‘void* (*)()’ to ‘void* (*)(void*)’ [-Werror=permissive]
  129 |         if ( pthread_create( &new_thread, NULL, a_thread_func, NULL ) != 0 )
      |                                                 ^~~~~~~~~~~~~
      |                                                 |
      |                                                 void* (*)()
--
conformance/interfaces/pthread_sigmask/6-1.c:128:47: error: invalid conversion from ‘void* (*)()’ to ‘void* (*)(void*)’ [-Werror=permissive]
  128 |         if (pthread_create(&new_thread, NULL, a_thread_func, NULL) != 0) {
      |                                               ^~~~~~~~~~~~~
      |                                               |
      |                                               void* (*)()
--
conformance/interfaces/pthread_sigmask/7-1.c:84:49: error: invalid conversion from ‘void* (*)()’ to ‘void* (*)(void*)’ [-Werror=permissive]
   84 |         if ( pthread_create( &new_thread, NULL, a_thread_func, NULL ) != 0 )
      |                                                 ^~~~~~~~~~~~~
      |                                                 |
      |                                                 void* (*)()
--
conformance/interfaces/pthread_sigmask/8-1.c:75:47: error: invalid conversion from ‘void* (*)()’ to ‘void* (*)(void*)’ [-Werror=permissive]
   75 |         if (pthread_create(&new_thread, NULL, a_thread_func, NULL) != 0) {
      |                                               ^~~~~~~~~~~~~
      |                                               |
      |                                               void* (*)()
--
conformance/interfaces/pthread_sigmask/8-2.c:77:47: error: invalid conversion from ‘void* (*)()’ to ‘void* (*)(void*)’ [-Werror=permissive]
   77 |         if (pthread_create(&new_thread, NULL, a_thread_func, NULL) != 0) {
      |                                               ^~~~~~~~~~~~~
      |                                               |
      |                                               void* (*)()
--
conformance/interfaces/pthread_sigmask/8-3.c:75:47: error: invalid conversion from ‘void* (*)()’ to ‘void* (*)(void*)’ [-Werror=permissive]
   75 |         if (pthread_create(&new_thread, NULL, a_thread_func, NULL) != 0) {
      |                                               ^~~~~~~~~~~~~
      |                                               |
      |                                               void* (*)()
--
conformance/interfaces/pthread_sigmask/9-1.c:92:47: error: invalid conversion from ‘void* (*)()’ to ‘void* (*)(void*)’ [-Werror=permissive]
   92 |         if (pthread_create(&new_thread, NULL, a_thread_func, NULL) != 0) {
      |                                               ^~~~~~~~~~~~~
      |                                               |
      |                                               void* (*)()
--
conformance/interfaces/pthread_spin_lock/1-1.c:66:26: error: invalid conversion from ‘void (*)()’ to ‘__sighandler_t’ {aka ‘void (*)(int)’} [-Werror=permissive]
   66 |         act.sa_handler = sig_handler;
      |                          ^~~~~~~~~~~
      |                          |
      |                          void (*)()
--
conformance/interfaces/pthread_spin_lock/3-1.c:43:26: error: invalid conversion from ‘void (*)()’ to ‘__sighandler_t’ {aka ‘void (*)(int)’} [-Werror=permissive]
   43 |         act.sa_handler = sig_handler;
      |                          ^~~~~~~~~~~
      |                          |
      |                          void (*)()
--
conformance/interfaces/pthread_spin_lock/3-2.c:52:26: error: invalid conversion from ‘void (*)()’ to ‘__sighandler_t’ {aka ‘void (*)(int)’} [-Werror=permissive]
   52 |         act.sa_handler = sig_handler;
      |                          ^~~~~~~~~~~
      |                          |
      |                          void (*)()
--
conformance/interfaces/pthread_spin_trylock/1-1.c:63:26: error: invalid conversion from ‘void (*)()’ to ‘__sighandler_t’ {aka ‘void (*)(int)’} [-Werror=permissive]
   63 |         act.sa_handler = sig_handler;
      |                          ^~~~~~~~~~~
      |                          |
      |                          void (*)()

@abujalski
Copy link
Author

I this still needed? are all those tests currently failing?

It looks that those tests passes. So for that purpose this patch is not needed.

However as @kleisauke mentioned it is necessary for ASAN, so I can rebase it and fix other test signatures if this still will be useful. WDYT?

@sbc100
Copy link
Contributor

sbc100 commented Aug 20, 2021

Ah! The reason it works is because we run the thread entry points from JS code (which can handle signature mismatches): https://github.com/emscripten-core/emscripten/blob/d8ec08a37915c5a7a358b324627abe5a00c0f632/src/library_pthread.js#L1281-L1283

@sbc100
Copy link
Contributor

sbc100 commented Aug 20, 2021

Perhaps we could instread patch asan to launch threads via JS like this? (To avoid the signature mismatch issue).

@kleisauke
Copy link
Collaborator

Patching ASan to invoke the pthread entry points via JS sounds good to me. I think it could be done by using invokeEntryPoint here (untested):
https://github.com/emscripten-core/emscripten/blob/fc50832faa8d4de5e170c7da1a71a31ab5a0b341/system/lib/compiler-rt/lib/asan/asan_thread.cpp#L274

However, this wouldn't resolve the signature mismatches of the signal handlers, but perhaps that can be resolved in a similar way.

@sbc100
Copy link
Contributor

sbc100 commented Aug 24, 2021

Patching ASan to invoke the pthread entry points via JS sounds good to me. I think it could be done by using invokeEntryPoint here (untested):
https://github.com/emscripten-core/emscripten/blob/fc50832faa8d4de5e170c7da1a71a31ab5a0b341/system/lib/compiler-rt/lib/asan/asan_thread.cpp#L274

However, this wouldn't resolve the signature mismatches of the signal handlers, but perhaps that can be resolved in a similar way.

Yes, I already worked around that here:
https://github.com/emscripten-core/emscripten/blob/9a644e1a878863b9dc168401174c9f5c775e8c1b/src/library.js#L2626

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants