a63c047d90
Each TLSDESC relocation relocates a 2-word descriptor in the GOT that contains: - the address of a TLS resolver function - an argument to pass (indirectly) to the resolver function (Specifically, the address of the 2-word descriptor is passed to the resolver.) The loader resolves R_GENERIC_TLSDESC relocations using one of three resolver functions that it defines: - tlsdesc_resolver_static - tlsdesc_resolver_dynamic - tlsdesc_resolver_unresolved_weak The resolver functions are written in assembly because they have a restrictive calling convention. They're only allowed to modify x0 and (apparently) the condition codes. For a relocation to memory in static TLS (i.e. the executable or an solib loaded initially), the loader uses a simple resolver function, tlsdesc_resolver_static, that returns the static offset it receives from the loader. For relocations to dynamic TLS memory (i.e. memory in a dlopen'ed solib), the loader uses tlsdesc_resolver_dynamic, which allocates TLS memory on demand. It inlines the fast path of __tls_get_addr, then falls back to __tls_get_addr when it needs to allocate memory. The loader handles these dynamic TLS relocations in two passes: - In the first pass, it allocates a table of TlsDynamicResolverArg objects, one per dynamic TLSDESC relocation. - In the second pass, once the table is finalized, it writes the addresses of the TlsDynamicResolverArg objects into the TLSDESC relocations. tlsdesc_resolver_unresolved_weak returns a negated thread pointer so that taking the address of an unresolved weak TLS symbols produces NULL. The loader handles R_GENERIC_TLSDESC in a target-independent way, but only for arm64, because Bionic has only implemented the resolver functions for arm64. Bug: http://b/78026329 Test: bionic unit tests Test: check that backtrace works inside a resolver function and inside __tls_get_addr called from a resolver (gdbclient.py, b __tls_get_addr, bt) Change-Id: I752e59ff986292449892c449dad2546e6f0ff7b6
65 lines
2.2 KiB
C
65 lines
2.2 KiB
C
/*
|
|
* Copyright (C) 2019 The Android Open Source Project
|
|
* All rights reserved.
|
|
*
|
|
* Redistribution and use in source and binary forms, with or without
|
|
* modification, are permitted provided that the following conditions
|
|
* are met:
|
|
* * Redistributions of source code must retain the above copyright
|
|
* notice, this list of conditions and the following disclaimer.
|
|
* * Redistributions in binary form must reproduce the above copyright
|
|
* notice, this list of conditions and the following disclaimer in
|
|
* the documentation and/or other materials provided with the
|
|
* distribution.
|
|
*
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
|
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
|
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
|
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
|
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
|
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
* SUCH DAMAGE.
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include "private/bionic_elf_tls.h"
|
|
|
|
struct TlsModule;
|
|
struct soinfo;
|
|
|
|
void linker_setup_exe_static_tls(const char* progname);
|
|
void linker_finalize_static_tls();
|
|
|
|
void register_soinfo_tls(soinfo* si);
|
|
void unregister_soinfo_tls(soinfo* si);
|
|
|
|
const TlsModule& get_tls_module(size_t module_id);
|
|
|
|
typedef size_t TlsDescResolverFunc(size_t);
|
|
|
|
struct TlsDescriptor {
|
|
#if defined(__arm__)
|
|
size_t arg;
|
|
TlsDescResolverFunc* func;
|
|
#else
|
|
TlsDescResolverFunc* func;
|
|
size_t arg;
|
|
#endif
|
|
};
|
|
|
|
struct TlsDynamicResolverArg {
|
|
size_t generation;
|
|
TlsIndex index;
|
|
};
|
|
|
|
__LIBC_HIDDEN__ extern "C" size_t tlsdesc_resolver_static(size_t);
|
|
__LIBC_HIDDEN__ extern "C" size_t tlsdesc_resolver_dynamic(size_t);
|
|
__LIBC_HIDDEN__ extern "C" size_t tlsdesc_resolver_unresolved_weak(size_t);
|