Fix x86_64 build, clean up intermediate libraries.
The x86_64 build was failing because clone.S had a call to __thread_entry which was being added to a different intermediate .a on the way to making libc.so, and the linker couldn't guarantee statically that such a relocation would be possible. ld: error: out/target/product/generic_x86_64/obj/STATIC_LIBRARIES/libc_common_intermediates/libc_common.a(clone.o): requires dynamic R_X86_64_PC32 reloc against '__thread_entry' which may overflow at runtime; recompile with -fPIC This patch addresses that by ensuring that the caller and callee end up in the same intermediate .a. While I'm here, I've tried to clean up some of the mess that led to this situation too. In particular, this removes libc/private/ from the default include path (except for the DNS code), and splits out the DNS code into its own library (since it's a weird special case of upstream NetBSD code that's diverged so heavily it's unlikely ever to get back in sync). There's more cleanup of the DNS situation possible, but this is definitely a step in the right direction, and it's more than enough to get x86_64 building cleanly. Change-Id: I00425a7245b7a2573df16cc38798187d0729e7c4
This commit is contained in:
@@ -52,8 +52,6 @@ extern "C" void ATTRIBUTES _thread_created_hook(pid_t thread_id);
|
||||
|
||||
extern "C" int __set_tls(void* ptr);
|
||||
|
||||
static const int kPthreadInitFailed = 1;
|
||||
|
||||
static pthread_mutex_t gPthreadStackCreationLock = PTHREAD_MUTEX_INITIALIZER;
|
||||
|
||||
static pthread_mutex_t gDebuggerNotificationLock = PTHREAD_MUTEX_INITIALIZER;
|
||||
@@ -84,30 +82,6 @@ void __init_tls(pthread_internal_t* thread) {
|
||||
}
|
||||
}
|
||||
|
||||
// This trampoline is called from the assembly _pthread_clone function.
|
||||
// Our 'tls' and __pthread_clone's 'child_stack' are one and the same, just growing in
|
||||
// opposite directions.
|
||||
extern "C" void __thread_entry(void* (*func)(void*), void* arg, void** tls) {
|
||||
// Wait for our creating thread to release us. This lets it have time to
|
||||
// notify gdb about this thread before we start doing anything.
|
||||
// This also provides the memory barrier needed to ensure that all memory
|
||||
// accesses previously made by the creating thread are visible to us.
|
||||
pthread_mutex_t* start_mutex = (pthread_mutex_t*) &tls[TLS_SLOT_SELF];
|
||||
pthread_mutex_lock(start_mutex);
|
||||
pthread_mutex_destroy(start_mutex);
|
||||
|
||||
pthread_internal_t* thread = (pthread_internal_t*) tls[TLS_SLOT_THREAD_ID];
|
||||
thread->tls = tls;
|
||||
__init_tls(thread);
|
||||
|
||||
if ((thread->internal_flags & kPthreadInitFailed) != 0) {
|
||||
pthread_exit(NULL);
|
||||
}
|
||||
|
||||
void* result = func(arg);
|
||||
pthread_exit(result);
|
||||
}
|
||||
|
||||
__LIBC_ABI_PRIVATE__
|
||||
int _init_thread(pthread_internal_t* thread, bool add_to_thread_list) {
|
||||
int error = 0;
|
||||
@@ -240,7 +214,7 @@ int pthread_create(pthread_t* thread_out, pthread_attr_t const* attr,
|
||||
if (init_errno != 0) {
|
||||
// Mark the thread detached and let its __thread_entry run to
|
||||
// completion. (It'll just exit immediately, cleaning up its resources.)
|
||||
thread->internal_flags |= kPthreadInitFailed;
|
||||
thread->internal_flags |= PTHREAD_INTERNAL_FLAG_THREAD_INIT_FAILED;
|
||||
thread->attr.flags |= PTHREAD_ATTR_FLAG_DETACHED;
|
||||
return init_errno;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user