diff --git a/Toolchain/Stubs/i686clang/libc.so b/Toolchain/Stubs/i686clang/libc.so index 99d7659f48..bf87ceff55 100644 Binary files a/Toolchain/Stubs/i686clang/libc.so and b/Toolchain/Stubs/i686clang/libc.so differ diff --git a/Toolchain/Stubs/i686clang/libpthread.so b/Toolchain/Stubs/i686clang/libpthread.so deleted file mode 100644 index 557e7200dc..0000000000 Binary files a/Toolchain/Stubs/i686clang/libpthread.so and /dev/null differ diff --git a/Toolchain/Stubs/x86_64clang/libc.so b/Toolchain/Stubs/x86_64clang/libc.so index 373cbddcec..f4ae65b5ee 100644 Binary files a/Toolchain/Stubs/x86_64clang/libc.so and b/Toolchain/Stubs/x86_64clang/libc.so differ diff --git a/Toolchain/Stubs/x86_64clang/libpthread.so b/Toolchain/Stubs/x86_64clang/libpthread.so deleted file mode 100644 index cf839e8d80..0000000000 Binary files a/Toolchain/Stubs/x86_64clang/libpthread.so and /dev/null differ diff --git a/Userland/DynamicLoader/CMakeLists.txt b/Userland/DynamicLoader/CMakeLists.txt index 55c86fc19e..4b2c9aadc2 100644 --- a/Userland/DynamicLoader/CMakeLists.txt +++ b/Userland/DynamicLoader/CMakeLists.txt @@ -25,6 +25,9 @@ if (ENABLE_UNDEFINED_SANITIZER) set(LOADER_SOURCES ${LOADER_SOURCES} ../Libraries/LibSanitizer/UBSanitizer.cpp) endif() +# pthread requires thread local storage, which DynamicLoader does not have. +list(FILTER LIBC_SOURCES1 EXCLUDE REGEX ".*/LibC/pthread\\.cpp") + add_definitions(-D_DYNAMIC_LOADER) set(SOURCES ${LOADER_SOURCES} ${AK_SOURCES} ${ELF_SOURCES} ${LIBC_SOURCES1} ${LIBC_SOURCES2} ${LIBC_SOURCES3} ${LIBSYSTEM_SOURCES}) diff --git a/Userland/Libraries/LibC/CMakeLists.txt b/Userland/Libraries/LibC/CMakeLists.txt index aa5c40d116..2319a241e1 100644 --- a/Userland/Libraries/LibC/CMakeLists.txt +++ b/Userland/Libraries/LibC/CMakeLists.txt @@ -27,8 +27,10 @@ set(LIBC_SOURCES netdb.cpp poll.cpp priority.cpp - pthread_forward.cpp + pthread.cpp + pthread_cond.cpp pthread_integration.cpp + pthread_once.cpp pthread_tls.cpp pty.cpp pwd.cpp @@ -38,6 +40,7 @@ set(LIBC_SOURCES scanf.cpp sched.cpp search.cpp + semaphore.cpp serenity.cpp shadow.cpp signal.cpp diff --git a/Userland/Libraries/LibC/bits/pthread_forward.h b/Userland/Libraries/LibC/bits/pthread_forward.h deleted file mode 100644 index 849220a967..0000000000 --- a/Userland/Libraries/LibC/bits/pthread_forward.h +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright (c) 2021, Gunnar Beutner - * - * SPDX-License-Identifier: BSD-2-Clause - */ - -#pragma once - -#include - -struct PthreadFunctions { - int (*pthread_mutex_trylock)(pthread_mutex_t* mutex); - int (*pthread_mutex_destroy)(pthread_mutex_t*); - - int (*pthread_mutexattr_init)(pthread_mutexattr_t*); - int (*pthread_mutexattr_settype)(pthread_mutexattr_t*, int); - int (*pthread_mutexattr_destroy)(pthread_mutexattr_t*); - - int (*pthread_once)(pthread_once_t*, void (*)(void)); - - int (*pthread_cond_broadcast)(pthread_cond_t*); - int (*pthread_cond_init)(pthread_cond_t*, pthread_condattr_t const*); - int (*pthread_cond_signal)(pthread_cond_t*); - int (*pthread_cond_wait)(pthread_cond_t*, pthread_mutex_t*); - int (*pthread_cond_destroy)(pthread_cond_t*); - int (*pthread_cond_timedwait)(pthread_cond_t*, pthread_mutex_t*, const struct timespec*); -}; - -void __init_pthread_forward(PthreadFunctions); diff --git a/Userland/Libraries/LibPthread/pthread.cpp b/Userland/Libraries/LibC/pthread.cpp similarity index 100% rename from Userland/Libraries/LibPthread/pthread.cpp rename to Userland/Libraries/LibC/pthread.cpp diff --git a/Userland/Libraries/LibPthread/pthread.h b/Userland/Libraries/LibC/pthread.h similarity index 100% rename from Userland/Libraries/LibPthread/pthread.h rename to Userland/Libraries/LibC/pthread.h diff --git a/Userland/Libraries/LibPthread/pthread_cond.cpp b/Userland/Libraries/LibC/pthread_cond.cpp similarity index 100% rename from Userland/Libraries/LibPthread/pthread_cond.cpp rename to Userland/Libraries/LibC/pthread_cond.cpp diff --git a/Userland/Libraries/LibC/pthread_forward.cpp b/Userland/Libraries/LibC/pthread_forward.cpp deleted file mode 100644 index 32fcd015e7..0000000000 --- a/Userland/Libraries/LibC/pthread_forward.cpp +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Copyright (c) 2021, Gunnar Beutner - * - * SPDX-License-Identifier: BSD-2-Clause - */ - -#include -#include - -static PthreadFunctions s_pthread_functions; - -void __init_pthread_forward(PthreadFunctions funcs) -{ - s_pthread_functions = funcs; -} - -int pthread_mutex_trylock(pthread_mutex_t* mutex) -{ - VERIFY(s_pthread_functions.pthread_mutex_trylock); - return s_pthread_functions.pthread_mutex_trylock(mutex); -} - -int pthread_mutex_destroy(pthread_mutex_t* mutex) -{ - VERIFY(s_pthread_functions.pthread_mutex_destroy); - return s_pthread_functions.pthread_mutex_destroy(mutex); -} - -int pthread_mutexattr_init(pthread_mutexattr_t* attr) -{ - VERIFY(s_pthread_functions.pthread_mutexattr_init); - return s_pthread_functions.pthread_mutexattr_init(attr); -} - -int pthread_mutexattr_settype(pthread_mutexattr_t* attr, int type) -{ - VERIFY(s_pthread_functions.pthread_mutexattr_settype); - return s_pthread_functions.pthread_mutexattr_settype(attr, type); -} - -int pthread_mutexattr_destroy(pthread_mutexattr_t* attr) -{ - VERIFY(s_pthread_functions.pthread_mutexattr_destroy); - return s_pthread_functions.pthread_mutexattr_destroy(attr); -} - -int pthread_once(pthread_once_t* self, void (*callback)(void)) -{ - VERIFY(s_pthread_functions.pthread_once); - return s_pthread_functions.pthread_once(self, callback); -} - -int pthread_cond_broadcast(pthread_cond_t* cond) -{ - VERIFY(s_pthread_functions.pthread_cond_broadcast); - return s_pthread_functions.pthread_cond_broadcast(cond); -} - -int pthread_cond_init(pthread_cond_t* cond, pthread_condattr_t const* attr) -{ - VERIFY(s_pthread_functions.pthread_cond_init); - return s_pthread_functions.pthread_cond_init(cond, attr); -} - -int pthread_cond_signal(pthread_cond_t* cond) -{ - VERIFY(s_pthread_functions.pthread_cond_signal); - return s_pthread_functions.pthread_cond_signal(cond); -} - -int pthread_cond_wait(pthread_cond_t* cond, pthread_mutex_t* mutex) -{ - VERIFY(s_pthread_functions.pthread_cond_wait); - return s_pthread_functions.pthread_cond_wait(cond, mutex); -} - -int pthread_cond_destroy(pthread_cond_t* cond) -{ - VERIFY(s_pthread_functions.pthread_cond_destroy); - return s_pthread_functions.pthread_cond_destroy(cond); -} - -int pthread_cond_timedwait(pthread_cond_t* cond, pthread_mutex_t* mutex, const struct timespec* abstime) -{ - VERIFY(s_pthread_functions.pthread_cond_timedwait); - return s_pthread_functions.pthread_cond_timedwait(cond, mutex, abstime); -} diff --git a/Userland/Libraries/LibPthread/pthread_once.cpp b/Userland/Libraries/LibC/pthread_once.cpp similarity index 100% rename from Userland/Libraries/LibPthread/pthread_once.cpp rename to Userland/Libraries/LibC/pthread_once.cpp diff --git a/Userland/Libraries/LibPthread/semaphore.cpp b/Userland/Libraries/LibC/semaphore.cpp similarity index 100% rename from Userland/Libraries/LibPthread/semaphore.cpp rename to Userland/Libraries/LibC/semaphore.cpp diff --git a/Userland/Libraries/LibPthread/semaphore.h b/Userland/Libraries/LibC/semaphore.h similarity index 100% rename from Userland/Libraries/LibPthread/semaphore.h rename to Userland/Libraries/LibC/semaphore.h diff --git a/Userland/Libraries/LibPthread/CMakeLists.txt b/Userland/Libraries/LibPthread/CMakeLists.txt index bb6c95319b..ba5fc79edb 100644 --- a/Userland/Libraries/LibPthread/CMakeLists.txt +++ b/Userland/Libraries/LibPthread/CMakeLists.txt @@ -1,11 +1,4 @@ -set(SOURCES - forward.cpp - pthread.cpp - pthread_cond.cpp - pthread_once.cpp - semaphore.cpp -) - -serenity_libc(LibPthread pthread) -target_link_libraries(LibPthread LibC LibSystem) -target_include_directories(LibPthread PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) +# Provide a dummy target and a linker script that tells everything to link against LibC instead. +add_library(LibPthread INTERFACE) +target_link_libraries(LibPthread INTERFACE LibC) +file(WRITE "${CMAKE_STAGING_PREFIX}/${CMAKE_INSTALL_LIBDIR}/libpthread.so" "INPUT(libc.so)") diff --git a/Userland/Libraries/LibPthread/forward.cpp b/Userland/Libraries/LibPthread/forward.cpp deleted file mode 100644 index f8a964c580..0000000000 --- a/Userland/Libraries/LibPthread/forward.cpp +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (c) 2021, Gunnar Beutner - * Copyright (c) 2022, the SerenityOS developers. - * - * SPDX-License-Identifier: BSD-2-Clause - */ - -#include - -static constexpr PthreadFunctions s_functions = { - .pthread_mutex_trylock = pthread_mutex_trylock, - .pthread_mutex_destroy = pthread_mutex_destroy, - - .pthread_mutexattr_init = pthread_mutexattr_init, - .pthread_mutexattr_settype = pthread_mutexattr_settype, - .pthread_mutexattr_destroy = pthread_mutexattr_destroy, - - .pthread_once = pthread_once, - - .pthread_cond_broadcast = pthread_cond_broadcast, - .pthread_cond_init = pthread_cond_init, - .pthread_cond_signal = pthread_cond_signal, - .pthread_cond_wait = pthread_cond_wait, - .pthread_cond_destroy = pthread_cond_destroy, - .pthread_cond_timedwait = pthread_cond_timedwait, -}; - -[[gnu::constructor]] static void forward_pthread_functions() -{ - __init_pthread_forward(s_functions); -}