blob: c0ebf252ca1b59e6f579fc6b7111f6a95168499e [file] [log] [blame]
Ryan Prichard45d13492019-01-03 02:51:30 -08001/*
2 * Copyright (C) 2019 The Android Open Source Project
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in
12 * the documentation and/or other materials provided with the
13 * distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
18 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
19 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
22 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
25 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE.
27 */
28
29#include "linker_tls.h"
30
31#include "private/bionic_defs.h"
32#include "private/bionic_elf_tls.h"
33#include "private/bionic_globals.h"
34#include "private/linker_native_bridge.h"
35
36__BIONIC_WEAK_FOR_NATIVE_BRIDGE
37extern "C" void __linker_reserve_bionic_tls_in_static_tls() {
38 __libc_shared_globals()->static_tls_layout.reserve_bionic_tls();
39}
40
41// Stub for linker static TLS layout.
42void layout_linker_static_tls() {
43 StaticTlsLayout& layout = __libc_shared_globals()->static_tls_layout;
Ryan Prichard977e47d2019-01-14 21:52:14 -080044 layout.reserve_exe_segment_and_tcb(nullptr);
Ryan Prichard45d13492019-01-03 02:51:30 -080045
46 // The pthread key data is located at the very front of bionic_tls. As a
47 // temporary workaround, allocate bionic_tls just after the thread pointer so
48 // Golang can find its pthread key, as long as the executable's TLS segment is
49 // small enough. Specifically, Golang scans forward 384 words from the TP on
50 // ARM.
51 // - http://b/118381796
52 // - https://groups.google.com/d/msg/golang-dev/yVrkFnYrYPE/2G3aFzYqBgAJ
53 __linker_reserve_bionic_tls_in_static_tls();
54
55 layout.finish_layout();
56}