summaryrefslogtreecommitdiff
path: root/tests/pthread_test.cpp
diff options
context:
space:
mode:
authorRyan Prichard <rprichard@google.com>2019-01-03 02:51:30 -0800
committerRyan Prichard <rprichard@google.com>2019-01-11 15:34:22 -0800
commit45d1349c638426d99a5319e7be3dbb7c36ece7eb (patch)
treefe566eac57d2354c8b6bf27fc9db698fe57ea6be /tests/pthread_test.cpp
parent27d59338b98bba7f33eb223c4f2e1df4c3b96774 (diff)
Reorganize static TLS memory for ELF TLS
For ELF TLS "local-exec" accesses, the static linker assumes that an executable's TLS segment is located at a statically-known offset from the thread pointer (i.e. "variant 1" for ARM and "variant 2" for x86). Because these layouts are incompatible, Bionic generally needs to allocate its TLS slots differently between different architectures. To allow per-architecture TLS slots: - Replace the TLS_SLOT_xxx enumerators with macros. New ARM slots are generally negative, while new x86 slots are generally positive. - Define a bionic_tcb struct that provides two things: - a void* raw_slots_storage[BIONIC_TLS_SLOTS] field - an inline accessor function: void*& tls_slot(size_t tpindex); For ELF TLS, it's necessary to allocate a temporary TCB (i.e. TLS slots), because the runtime linker doesn't know how large the static TLS area is until after it has loaded all of the initial solibs. To accommodate Golang, it's necessary to allocate the pthread keys at a fixed, small, positive offset from the thread pointer. This CL moves the pthread keys into bionic_tls, then allocates a single mapping per thread that looks like so: - stack guard - stack [omitted for main thread and with pthread_attr_setstack] - static TLS: - bionic_tcb [exec TLS will either precede or succeed the TCB] - bionic_tls [prefixed by the pthread keys] - [solib TLS segments will be placed here] - guard page As before, if the new mapping includes a stack, the pthread_internal_t is allocated on it. At startup, Bionic allocates a temporary bionic_tcb object on the stack, then allocates a temporary bionic_tls object using mmap. This mmap is delayed because the linker can't currently call async_safe_fatal() before relocating itself. Later, Bionic allocates a stack-less thread mapping for the main thread, and copies slots from the temporary TCB to the new TCB. (See *::copy_from_bootstrap methods.) Bug: http://b/78026329 Test: bionic unit tests Test: verify that a Golang app still works Test: verify that a Golang app crashes if bionic_{tls,tcb} are swapped Merged-In: I6543063752f4ec8ef6dc9c7f2a06ce2a18fc5af3 Change-Id: I6543063752f4ec8ef6dc9c7f2a06ce2a18fc5af3 (cherry picked from commit 1e660b70da625fcbf1e43dfae09b7b4817fa1660)
Diffstat (limited to 'tests/pthread_test.cpp')
-rw-r--r--tests/pthread_test.cpp6
1 files changed, 3 insertions, 3 deletions
diff --git a/tests/pthread_test.cpp b/tests/pthread_test.cpp
index 84ce531f0..1c57264fd 100644
--- a/tests/pthread_test.cpp
+++ b/tests/pthread_test.cpp
@@ -2582,9 +2582,9 @@ TEST(pthread, pthread_create__mmap_failures) {
ASSERT_EQ(0, munmap(pages[i], kPageSize));
}
- // Creating a thread uses at least six VMAs: the stack, the TLS, and a guard each side of both.
- // So we should have seen at least six failures.
- ASSERT_GE(EAGAIN_count, 6U);
+ // Creating a thread uses at least three VMAs: the combined stack and TLS, and a guard on each
+ // side. So we should have seen at least three failures.
+ ASSERT_GE(EAGAIN_count, 3U);
for (; i < pages.size(); ++i) {
ASSERT_EQ(0, munmap(pages[i], kPageSize));