Merge "Hold the loader mutex in linker_main once constructors are running" into main am: 6e601911f1

Original change: https://android-review.googlesource.com/c/platform/bionic/+/2670169

Change-Id: I07b3304620d440273728a8474f4aa9cc22c4aa5b
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Ryan Prichard 2023-07-26 04:25:18 +00:00 committed by Automerger Merge Worker
commit bf1e5f83ad
3 changed files with 9 additions and 2 deletions

View file

@ -97,7 +97,7 @@ bool __loader_android_handle_signal(int signal_number, siginfo_t* info,
void* context) __LINKER_PUBLIC__;
}
static pthread_mutex_t g_dl_mutex = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;
pthread_mutex_t g_dl_mutex = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;
static char* __bionic_set_dlerror(char* new_value) {
char* old_value = __get_thread()->current_dlerror;

View file

@ -104,3 +104,4 @@ class DlErrorRestorer {
};
__LIBC_HIDDEN__ extern bool g_is_ldd;
__LIBC_HIDDEN__ extern pthread_mutex_t g_dl_mutex;

View file

@ -43,10 +43,11 @@
#include "linker_tls.h"
#include "linker_utils.h"
#include "private/KernelArgumentBlock.h"
#include "private/ScopedPthreadMutexLocker.h"
#include "private/bionic_call_ifunc_resolver.h"
#include "private/bionic_globals.h"
#include "private/bionic_tls.h"
#include "private/KernelArgumentBlock.h"
#include "android-base/unique_fd.h"
#include "android-base/strings.h"
@ -498,6 +499,11 @@ static ElfW(Addr) linker_main(KernelArgumentBlock& args, const char* exe_to_load
if (!get_cfi_shadow()->InitialLinkDone(solist)) __linker_cannot_link(g_argv[0]);
// A constructor could spawn a thread that calls into the loader, so as soon
// as we've called a constructor, we need to hold the lock while accessing
// global loader state.
ScopedPthreadMutexLocker locker(&g_dl_mutex);
si->call_pre_init_constructors();
si->call_constructors();