DynamicLoader: Fix TLS on 32 bit platform

There were two problems with my previous implementation
- TLS was not allocated if nothing used it. There is a fallback
  initialization in _init_libc, but this was not enough if one of the
  init functions tried to access errno.
- __tls_get_addr was not resolved. If __tls_get_addr was called through
  a plt entry, everything would just break :(
This commit is contained in:
2025-06-06 16:27:07 +03:00
parent 00c6820825
commit 5ad7d7edb1
3 changed files with 22 additions and 16 deletions

View File

@@ -64,10 +64,6 @@ target_compile_definitions(objlibc PRIVATE __arch=${BANAN_ARCH})
target_compile_options(objlibc PRIVATE -O2 -g -Wstack-usage=512 -fno-exceptions -fpic -nolibc)
target_compile_options(objlibc PUBLIC -Wall -Wextra -Werror -Wno-error=stack-usage=)
if("${BANAN_ARCH}" STREQUAL "i686")
target_compile_definitions(objlibc PRIVATE __disable_thread_local_storage)
endif()
function(add_crtx crtx)
add_custom_target(${crtx}
COMMAND ${CMAKE_CXX_COMPILER} -c -o ${CMAKE_INSTALL_LIBDIR}/${crtx}.o ${CMAKE_CURRENT_SOURCE_DIR}/arch/${BANAN_ARCH}/${crtx}.S

View File

@@ -105,7 +105,6 @@ void pthread_cleanup_push(void (*routine)(void*), void* arg)
uthread->cleanup_stack = cleanup;
}
#if not __disable_thread_local_storage
static thread_local struct {
void* value;
void (*destructor)(void*);
@@ -159,7 +158,6 @@ int pthread_setspecific(pthread_key_t key, const void* value)
s_pthread_keys[key].value = const_cast<void*>(value);
return 0;
}
#endif
int pthread_attr_destroy(pthread_attr_t* attr)
{
@@ -413,7 +411,6 @@ void pthread_exit(void* value_ptr)
while (uthread->cleanup_stack)
pthread_cleanup_pop(1);
#if not __disable_thread_local_storage
for (size_t iteration = 0; iteration < PTHREAD_DESTRUCTOR_ITERATIONS; iteration++)
{
bool called = false;
@@ -431,7 +428,6 @@ void pthread_exit(void* value_ptr)
if (!called)
break;
}
#endif
free_uthread(uthread);
syscall(SYS_PTHREAD_EXIT, value_ptr);
@@ -1199,7 +1195,6 @@ int pthread_barrier_wait(pthread_barrier_t* barrier)
return 0;
}
#if not __disable_thread_local_storage
struct tls_index
{
unsigned long int ti_module;
@@ -1214,7 +1209,6 @@ extern "C" void* __tls_get_addr(tls_index* ti)
#if ARCH(i686)
extern "C" void* __attribute__((__regparm__(1))) ___tls_get_addr(tls_index* ti)
{
return reinterpret_cast<void*>(get_uthread()->dtv[ti->ti_module] + ti->ti_offset);
return reinterpret_cast<void*>(_get_uthread()->dtv[ti->ti_module] + ti->ti_offset);
}
#endif
#endif