platform_bionic/libc
Ryan Prichard 45d1349c63 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 1e660b70da)
2019-01-11 15:34:22 -08:00
..
arch-arm Add ARM EABI function __aeabi_read_tp 2019-01-07 20:30:35 -08:00
arch-arm64 Remove denver64 from libc 2018-11-30 22:28:39 +00:00
arch-common/bionic Change crtbrand for host bionic 2018-10-22 17:15:22 -07:00
arch-mips Remove __overloadable/__RENAME_CLANG 2018-02-06 13:35:56 -08:00
arch-mips64 bionic: add vdso clock_getres 2017-12-07 09:41:48 -08:00
arch-x86 Replace TLS_SLOT_BIONIC_PREINIT w/ shared globals 2018-12-04 13:51:56 -08:00
arch-x86_64 Make memcpy memmove 2018-06-11 18:12:45 +00:00
async_safe Add async_safe_format_fd_va_list 2018-10-08 13:27:16 -07:00
bionic Reorganize static TLS memory for ELF TLS 2019-01-11 15:34:22 -08:00
dns Merge "Replace android_open_proxy with dns_open_proxy" 2018-11-28 12:21:33 +00:00
include Add Android Runtime APEX bin directory to Bionic default shell search path. 2018-12-06 17:03:47 +00:00
kernel Update kernel headers with new parser. 2019-01-10 17:33:56 -08:00
malloc_debug Fix/suppress bionic google-explicit-constructor warnings 2019-01-02 11:04:05 -08:00
malloc_hooks Fix malloc_hooks for hooks_write_malloc_leak_info. 2018-07-18 15:25:45 +01:00
private Reorganize static TLS memory for ELF TLS 2019-01-11 15:34:22 -08:00
seccomp seccomp: Generate the policy files at compile time 2018-08-06 11:10:25 -07:00
stdio Make fclose/pclose distinct. 2018-10-01 16:17:37 -07:00
stdlib Add PR_SET_VMA and PR_SET_VMA_ANON_NAME to <sys/prctl.h>. 2018-08-22 10:36:23 -07:00
system_properties Clean up bionic_macros.h a bit. 2018-10-25 11:00:00 -07:00
tools Generate the per-arch .map files at build time. 2018-12-17 12:26:42 -08:00
tzcode Update the "host" bionic code tzdata lookup logic 2019-01-07 21:08:37 +00:00
upstream-freebsd Add reallocarray(3). 2018-09-26 14:24:18 -07:00
upstream-netbsd Remove unused NetBSD compatibility cruft. 2018-09-20 13:27:41 -07:00
upstream-openbsd Add reallocarray(3). 2018-09-26 14:24:18 -07:00
versioner-dependencies
Android.bp Reorganize static TLS memory for ELF TLS 2019-01-11 15:34:22 -08:00
fs_config_generator.py
libc.map.txt Merge changes from topic "move_bionic_to_apex" 2019-01-11 16:59:15 +00:00
libstdc++.map.txt
MODULE_LICENSE_BSD
NOTICE Reorganize static TLS memory for ELF TLS 2019-01-11 15:34:22 -08:00
SECCOMP_BLACKLIST_APP.TXT Allow several syscalls to app process 2018-03-28 16:30:20 -07:00
SECCOMP_BLACKLIST_COMMON.TXT Split zygote's seccomp filter into two 2018-01-04 12:28:40 -08:00
SECCOMP_WHITELIST_APP.TXT Move pipe, open, and getdents from the APP to COMMON seccomp whitelist. 2018-09-11 19:20:34 -04:00
SECCOMP_WHITELIST_COMMON.TXT Move pipe, open, and getdents from the APP to COMMON seccomp whitelist. 2018-09-11 19:20:34 -04:00
SECCOMP_WHITELIST_GLOBAL.TXT
SECCOMP_WHITELIST_SYSTEM.TXT Add bpf syscall to seccomp whitelist 2018-01-18 12:08:34 -08:00
SYSCALLS.TXT Add lp32 and lp64 shorthands to SYSCALLS.TXT. 2018-11-09 13:57:34 -08:00
version_script.txt